ycn 0.0.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/License.txt +1 -1
- data/Manifest.txt +14 -5
- data/PostInstall.txt +5 -7
- data/README.txt +105 -10
- data/bin/ycn-gen +5 -5
- data/config/requirements.rb +1 -1
- data/lib/ycn.rb +21 -9
- data/lib/ycn/java/java_class.erb +17 -0
- data/lib/ycn/java/java_klass.rb +97 -0
- data/lib/ycn/java/java_method.rb +19 -0
- data/lib/ycn/java/java_property.rb +10 -0
- data/lib/ycn/klass.rb +74 -71
- data/lib/ycn/method.rb +12 -0
- data/lib/ycn/property.rb +12 -0
- data/lib/ycn/ruby/ruby_class.erb +11 -0
- data/lib/ycn/ruby/ruby_klass.rb +71 -0
- data/lib/ycn/ruby/ruby_method.rb +20 -0
- data/lib/ycn/ruby/ruby_property.rb +9 -0
- data/lib/ycn/string_manip.rb +5 -7
- data/lib/ycn/version.rb +1 -1
- data/lib/ycn/ycn.rb +29 -23
- data/lib/ycn/ycn_functions.rb +2 -2
- data/website/index.html +86 -11
- metadata +19 -12
- data/lib/ycn/java_klass.rb +0 -169
data/License.txt
CHANGED
data/Manifest.txt
CHANGED
|
@@ -7,13 +7,22 @@ Rakefile
|
|
|
7
7
|
bin/ycn-gen
|
|
8
8
|
config/hoe.rb
|
|
9
9
|
config/requirements.rb
|
|
10
|
-
lib/ycn.rb
|
|
11
|
-
lib/ycn/version.rb
|
|
12
|
-
lib/ycn/ycn.rb
|
|
10
|
+
lib/ycn.rb
|
|
13
11
|
lib/ycn/header.rb
|
|
14
|
-
lib/ycn/java_klass.rb
|
|
12
|
+
lib/ycn/java/java_klass.rb
|
|
13
|
+
lib/ycn/java/java_method.rb
|
|
14
|
+
lib/ycn/java/java_property.rb
|
|
15
|
+
lib/ycn/java/java_class.erb
|
|
16
|
+
lib/ycn/ruby/ruby_klass.rb
|
|
17
|
+
lib/ycn/ruby/ruby_method.rb
|
|
18
|
+
lib/ycn/ruby/ruby_property.rb
|
|
19
|
+
lib/ycn/ruby/ruby_class.erb
|
|
15
20
|
lib/ycn/klass.rb
|
|
16
|
-
lib/ycn/
|
|
21
|
+
lib/ycn/method.rb
|
|
22
|
+
lib/ycn/property.rb
|
|
23
|
+
lib/ycn/string_manip.rb
|
|
24
|
+
lib/ycn/version.rb
|
|
25
|
+
lib/ycn/ycn.rb
|
|
17
26
|
lib/ycn/ycn_functions.rb
|
|
18
27
|
script/console
|
|
19
28
|
script/console.cmd
|
data/PostInstall.txt
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
For more information on ycn, see :
|
|
2
|
+
|
|
3
|
+
- http://ycn.rubyforge.org
|
|
4
|
+
- http://naturalcode.wordpress.com
|
|
5
|
+
- http://github.com/naturalcode/ycn/tree
|
data/README.txt
CHANGED
|
@@ -1,32 +1,127 @@
|
|
|
1
1
|
= ycn
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
http://rubyforge.org/projects/ycn/
|
|
4
|
+
https://github.com/naturalcode/ycn/tree
|
|
4
5
|
|
|
5
6
|
== DESCRIPTION:
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Yaml Class Notation is a compact, concise way of defining object
|
|
9
|
+
classes in a beautiful and language-neutral way.
|
|
10
|
+
|
|
11
|
+
Generate valid, executable code for any language you're forced use
|
|
12
|
+
from YCN files.
|
|
13
|
+
|
|
14
|
+
No semicolons, curly braces, or verbose keywords.
|
|
8
15
|
|
|
9
16
|
== FEATURES/PROBLEMS:
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
Features
|
|
19
|
+
- Reads a class definition from a YAML file
|
|
20
|
+
- Transforms a YAML class definition into well-formatted code
|
|
21
|
+
- Currently supports Java as the output language
|
|
22
|
+
|
|
23
|
+
Problems
|
|
24
|
+
- Currently supports only Java as the output language
|
|
25
|
+
- Not all unusual cases (ex: a class without properties) have necessarily been tested
|
|
26
|
+
- Needs more hooks for custom behavior and plugins
|
|
27
|
+
- Needs easy support for different languages
|
|
16
28
|
|
|
17
29
|
== REQUIREMENTS:
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
- configatron 1.2.1
|
|
20
32
|
|
|
21
33
|
== INSTALL:
|
|
22
34
|
|
|
23
|
-
|
|
35
|
+
gem install ycn
|
|
36
|
+
|
|
37
|
+
== SYNOPSIS:
|
|
38
|
+
|
|
39
|
+
# ycn_example.rb
|
|
40
|
+
# Generates Java classes from a YCN Yaml file.
|
|
41
|
+
|
|
42
|
+
require 'ycn'
|
|
43
|
+
|
|
44
|
+
project = {
|
|
45
|
+
:name => "JavaExprat4AK - Le polymorphisme, les classes " +
|
|
46
|
+
"abstraites et les interfaces.",
|
|
47
|
+
:desc => "G�re une collection de cowboys, indiens, brigands " +
|
|
48
|
+
"et dames en d�tresse, ainsi que leurs boissons.",
|
|
49
|
+
:author => "Andrew Koster",
|
|
50
|
+
|
|
51
|
+
:package => 'cowboys et indiens'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Ycn.generate project, :java
|
|
55
|
+
|
|
56
|
+
# pcg/cowboys_et_indiens.yml
|
|
57
|
+
|
|
58
|
+
humain:
|
|
59
|
+
new:
|
|
60
|
+
- nom, texte_parole
|
|
61
|
+
properties:
|
|
62
|
+
String:
|
|
63
|
+
- nom
|
|
64
|
+
- boisson_favorite = "de l'eau"
|
|
65
|
+
StringBuilder:
|
|
66
|
+
- texte_parole
|
|
67
|
+
methods:
|
|
68
|
+
void:
|
|
69
|
+
parler(string): |
|
|
70
|
+
getTexteParole().append(
|
|
71
|
+
"(" + getNom() + ") - " + psParoles + "\n")
|
|
72
|
+
commenter(string): |
|
|
73
|
+
getTexteParole().append(psCommentaire + "\n")
|
|
74
|
+
se_presenter: |
|
|
75
|
+
parler("Bonjour, je suis " + getNom() +
|
|
76
|
+
" et j'aime " + getBoissonFavorite() + ".")
|
|
77
|
+
boire: |
|
|
78
|
+
parler("Ah! Un bon verre avec " +
|
|
79
|
+
getBoissonFavorite() + "! GLOUPS!")
|
|
80
|
+
|
|
81
|
+
indien < humain:
|
|
82
|
+
new:
|
|
83
|
+
- nom, texte_parole
|
|
84
|
+
- nom, texte_parole, plumes
|
|
85
|
+
properties:
|
|
86
|
+
int:
|
|
87
|
+
- plumes = 0
|
|
88
|
+
String:
|
|
89
|
+
- totem = "Coyote"
|
|
90
|
+
- boisson_favorite = "du jus de racine"
|
|
91
|
+
methods:
|
|
92
|
+
void:
|
|
93
|
+
se_presenter: |
|
|
94
|
+
super.sePresenter()
|
|
95
|
+
parler("Mon totem est le " + getTotem() +
|
|
96
|
+
" et j'ai " + getPlumes() + " plume(s).")
|
|
97
|
+
scalper(cowboy): |
|
|
98
|
+
pvVisagePale.seFaireScalper(this)
|
|
99
|
+
setPlumes(getPlumes() + 1)
|
|
100
|
+
|
|
101
|
+
cowboy < humain:
|
|
102
|
+
new:
|
|
103
|
+
- nom, texte_parole
|
|
104
|
+
- nom, texte_parole, popularite
|
|
105
|
+
properties:
|
|
106
|
+
int:
|
|
107
|
+
- popularite = 0
|
|
108
|
+
String:
|
|
109
|
+
- adjectif = "vaillant"
|
|
110
|
+
methods:
|
|
111
|
+
void:
|
|
112
|
+
se_presenter: |
|
|
113
|
+
super.sePresenter()
|
|
114
|
+
parler("Je suis " + getAdjectif() + " et je suis" +
|
|
115
|
+
" populaire pour la lib�ration de " +
|
|
116
|
+
getPopularite() + " dame(s).")
|
|
117
|
+
se_faire_scalper(indien): |
|
|
118
|
+
parler("A�e! Ma t�te, " + piIndien.getNom() + " !")
|
|
24
119
|
|
|
25
120
|
== LICENSE:
|
|
26
121
|
|
|
27
122
|
(The MIT License)
|
|
28
123
|
|
|
29
|
-
Copyright (c) 2008
|
|
124
|
+
Copyright (c) 2008 Andrew Koster
|
|
30
125
|
|
|
31
126
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
32
127
|
a copy of this software and associated documentation files (the
|
data/bin/ycn-gen
CHANGED
|
@@ -10,17 +10,17 @@ Dir.mkdir(PCG_DIR)
|
|
|
10
10
|
example_file_content = <<TEXT
|
|
11
11
|
require 'ycn'
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Ycn::generate( :java, {
|
|
14
14
|
:name => "JavaExprat4AK - Le polymorphisme, les classes " +
|
|
15
15
|
"abstraites et les interfaces.",
|
|
16
16
|
:desc => "Gère une collection de cowboys, indiens, brigands " +
|
|
17
17
|
"et dames en détresse, ainsi que leurs boissons.",
|
|
18
18
|
:author => "Andrew Koster",
|
|
19
19
|
|
|
20
|
-
:package => 'cowboys et indiens'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
:package => 'cowboys et indiens',
|
|
21
|
+
|
|
22
|
+
:getters => true, :setters => false
|
|
23
|
+
})
|
|
24
24
|
TEXT
|
|
25
25
|
|
|
26
26
|
example_package_content = <<TEXT
|
data/config/requirements.rb
CHANGED
data/lib/ycn.rb
CHANGED
|
@@ -2,15 +2,27 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
3
|
|
|
4
4
|
require 'yaml'
|
|
5
|
+
require 'configatron'
|
|
6
|
+
require 'erb'
|
|
7
|
+
require 'pp'
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
require File.join(File.dirname(__FILE__),
|
|
9
|
-
require File.join(File.dirname(__FILE__),
|
|
10
|
-
require File.join(File.dirname(__FILE__),
|
|
11
|
-
require File.join(File.dirname(__FILE__),
|
|
9
|
+
y = 'ycn'
|
|
10
|
+
|
|
11
|
+
require File.join(File.dirname(__FILE__), y, 'java/java_method')
|
|
12
|
+
require File.join(File.dirname(__FILE__), y, 'java/java_property')
|
|
13
|
+
require File.join(File.dirname(__FILE__), y, 'java/java_klass')
|
|
14
|
+
require File.join(File.dirname(__FILE__), y, 'ruby/ruby_method')
|
|
15
|
+
require File.join(File.dirname(__FILE__), y, 'ruby/ruby_property')
|
|
16
|
+
require File.join(File.dirname(__FILE__), y, 'ruby/ruby_klass')
|
|
17
|
+
require File.join(File.dirname(__FILE__), y, 'method')
|
|
18
|
+
require File.join(File.dirname(__FILE__), y, 'property')
|
|
19
|
+
require File.join(File.dirname(__FILE__), y, 'klass')
|
|
20
|
+
require File.join(File.dirname(__FILE__), y, 'ycn')
|
|
21
|
+
require File.join(File.dirname(__FILE__), y, 'header')
|
|
22
|
+
require File.join(File.dirname(__FILE__), y, 'string_manip')
|
|
23
|
+
require File.join(File.dirname(__FILE__), y, 'ycn_functions')
|
|
24
|
+
|
|
25
|
+
include StringManip
|
|
12
26
|
|
|
13
27
|
module Ycn
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
puts "BEHOLD!"
|
|
28
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%= klass.java_header %><%=
|
|
2
|
+
klass.java_package
|
|
3
|
+
%>
|
|
4
|
+
<%= klass.java_imports
|
|
5
|
+
%>
|
|
6
|
+
<%= klass.java_class_declaration %>
|
|
7
|
+
{
|
|
8
|
+
<% for p in klass.properties do
|
|
9
|
+
%><%= p.java_property %>
|
|
10
|
+
<% end %><%=
|
|
11
|
+
klass.java_constructors %><%
|
|
12
|
+
klass.methods.each do |m| %>
|
|
13
|
+
<%= m.java_signature %>
|
|
14
|
+
{
|
|
15
|
+
<%= m.java_show_content %>
|
|
16
|
+
}
|
|
17
|
+
<% end %><%= klass.java_accessors %>}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#coding: utf-8
|
|
2
|
+
|
|
3
|
+
module JavaKlass
|
|
4
|
+
def java_header
|
|
5
|
+
text = <<HEAD
|
|
6
|
+
Programme : #{configatron.program_name}
|
|
7
|
+
Auteur(s) : #{configatron.author_name}
|
|
8
|
+
Date : #{Time.now.day}/#{Time.now.month}/#{Time.now.year}
|
|
9
|
+
Description : #{configatron.description}
|
|
10
|
+
HEAD
|
|
11
|
+
|
|
12
|
+
'/*' + text.split("\n").map{ |l|
|
|
13
|
+
"\n * #{l}"
|
|
14
|
+
}.join + "\n */\n"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def java_package
|
|
18
|
+
@package ? "\npackage pcg#{camelize @package};" : ''
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def java_imports
|
|
22
|
+
text = properties.map{ |property|
|
|
23
|
+
import = case property.type
|
|
24
|
+
when 'Date'
|
|
25
|
+
"import java.util.Date;"
|
|
26
|
+
when 'Time'
|
|
27
|
+
"import java.util.Time;"
|
|
28
|
+
else
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
import
|
|
32
|
+
}.compact
|
|
33
|
+
|
|
34
|
+
if text.size > 0
|
|
35
|
+
text = "\n" + text.join("\n") + "\n"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def java_class_declaration
|
|
40
|
+
"public class #{name}#{" extends #{parent.name}" if parent}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def java_constructors
|
|
44
|
+
@construct_params.map { |parameter_set|
|
|
45
|
+
"\n public #{@name}(" +
|
|
46
|
+
|
|
47
|
+
parameter_set.map { |parameter|
|
|
48
|
+
type = find_var( parameter ).type
|
|
49
|
+
"#{type} #{styled_var :riki, parameter, :p, type}"
|
|
50
|
+
|
|
51
|
+
}.join(', ') + ")\n {\n " +
|
|
52
|
+
|
|
53
|
+
parameter_set.map { |parameter|
|
|
54
|
+
type = find_var( parameter ).type
|
|
55
|
+
"set#{camelize parameter}(#{styled_var :riki, parameter, :p, type});"
|
|
56
|
+
}.join("\n ") +
|
|
57
|
+
|
|
58
|
+
java_prop_default_overrides
|
|
59
|
+
}.join("\n }\n") + "\n }\n"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def java_prop_default_overrides
|
|
63
|
+
prop_default_overrides.map { |property|
|
|
64
|
+
property = find_var( property )
|
|
65
|
+
"\n super.set#{camelize property.name}(#{property.default_value});"
|
|
66
|
+
}.join("\n")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def java_accessors; java_g_s_etters; end
|
|
70
|
+
|
|
71
|
+
def java_g_s_etters
|
|
72
|
+
text = properties.map { |property|
|
|
73
|
+
unless prop_default_overrides.include? property.name
|
|
74
|
+
type = property.type
|
|
75
|
+
name = property.name
|
|
76
|
+
result = ''
|
|
77
|
+
if configatron.getters; result += <<TEXT
|
|
78
|
+
public #{type} get#{camelize name}()
|
|
79
|
+
{
|
|
80
|
+
return #{styled_var :riki, name, :g, type };
|
|
81
|
+
}
|
|
82
|
+
TEXT
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if configatron.setters; result += <<TEXT
|
|
86
|
+
public void set#{camelize name}(#{type} #{styled_var :riki, name, :p, type})
|
|
87
|
+
{
|
|
88
|
+
#{styled_var :riki, name, :g, type } = #{styled_var :riki, name, :p, type};
|
|
89
|
+
}
|
|
90
|
+
TEXT
|
|
91
|
+
end
|
|
92
|
+
result
|
|
93
|
+
end
|
|
94
|
+
}.join
|
|
95
|
+
text
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module JavaMethod
|
|
2
|
+
def java_signature
|
|
3
|
+
params = @parameters.map{ |p|
|
|
4
|
+
"#{camelize p} p#{p[0].chr.downcase}#{camelize p}"
|
|
5
|
+
}.join(', ')
|
|
6
|
+
|
|
7
|
+
"public #{@type} #{low_camelize @name}(#{params})"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def java_show_content
|
|
11
|
+
@content.split("\n").map { |line|
|
|
12
|
+
unless line =~ /[\+\(]\s*$/
|
|
13
|
+
line += ';'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
line
|
|
17
|
+
}.join("\n")
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/ycn/klass.rb
CHANGED
|
@@ -1,95 +1,98 @@
|
|
|
1
|
-
require "ycn/java_klass"
|
|
2
|
-
require "ycn/string_manip"
|
|
3
|
-
|
|
4
1
|
class Klass
|
|
5
2
|
attr_accessor :name, :parent, :properties, :methods,
|
|
6
|
-
:
|
|
7
|
-
:prop_default_overrides
|
|
8
|
-
|
|
9
|
-
include JavaKlass
|
|
10
|
-
include StringManip
|
|
3
|
+
:construct_params, :prop_default_overrides
|
|
11
4
|
|
|
12
5
|
def initialize name, parent, properties, methods,
|
|
13
6
|
construct_params=nil, package=nil
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@
|
|
19
|
-
|
|
20
|
-
@
|
|
8
|
+
extend JavaKlass if configatron.lang == :java
|
|
9
|
+
extend RubyKlass if configatron.lang == :ruby
|
|
10
|
+
|
|
11
|
+
@name = camelize( name )
|
|
12
|
+
@parent = parent ? camelize( parent ) : nil
|
|
13
|
+
@properties = parse_properties( properties )
|
|
14
|
+
@methods = parse_methods( methods )
|
|
15
|
+
@construct_params = organize_constructor_params( construct_params )
|
|
21
16
|
@package = package
|
|
22
17
|
end
|
|
23
18
|
|
|
24
|
-
def
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@methods.each_pair do |type, meths|
|
|
29
|
-
meths.each_key do |m|
|
|
30
|
-
if m =~ /\(.+\)/
|
|
31
|
-
m_parameters =
|
|
32
|
-
/\(.*\)/.match(m).
|
|
33
|
-
to_s[1..-2].split(/ |, /)
|
|
34
|
-
|
|
35
|
-
m_name_only = m.dup.sub!(/\(.*\)/, '')
|
|
36
|
-
|
|
37
|
-
meths.store(m_name_only, meths[m])
|
|
38
|
-
meths.delete(m)
|
|
39
|
-
@method_params.store(m_name_only, m_parameters)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
19
|
+
def print_to template
|
|
20
|
+
klass = self
|
|
21
|
+
ERB.new( template ).result( binding )
|
|
43
22
|
end
|
|
44
23
|
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
def parse_properties properties_hash
|
|
25
|
+
properties_hash.keys.map { |type|
|
|
26
|
+
properties_hash[type].map do |property|
|
|
27
|
+
p = extract_default_values({
|
|
28
|
+
:name=>property, :type=>type
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
Property.new self, p[:name], p[:type], p[:default_value]
|
|
32
|
+
end
|
|
33
|
+
}.flatten
|
|
48
34
|
end
|
|
49
35
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
p
|
|
36
|
+
def parse_methods methods_hash
|
|
37
|
+
methods_hash.keys.map { |type|
|
|
38
|
+
methods_hash[type].keys.map do |method|
|
|
39
|
+
content = methods_hash[type][method].split("\n").join("\n ")
|
|
40
|
+
|
|
41
|
+
m = extract_method_params({
|
|
42
|
+
:name=>method, :type=>type,
|
|
43
|
+
:content=>content
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
Methodd.new( m[:name], m[:type], m[:params], m[:content] )
|
|
62
47
|
end
|
|
63
|
-
|
|
64
|
-
end
|
|
48
|
+
}.flatten
|
|
49
|
+
end
|
|
65
50
|
|
|
66
|
-
def
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
type = find_type(property)
|
|
51
|
+
def extract_method_params method
|
|
52
|
+
if method[:name] =~ /\(.+\)/
|
|
53
|
+
m_parameters =
|
|
54
|
+
/\(.*\)/.match(method[:name]).
|
|
55
|
+
to_s[1..-2].split(/ |, /)
|
|
72
56
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@prop_defaults.delete property
|
|
77
|
-
end
|
|
78
|
-
end
|
|
57
|
+
m_name_only = method[:name].dup.sub!(/\(.*\)/, '')
|
|
58
|
+
method[:name] = m_name_only
|
|
59
|
+
method[:params] = m_parameters
|
|
79
60
|
end
|
|
61
|
+
|
|
62
|
+
method
|
|
80
63
|
end
|
|
81
64
|
|
|
82
|
-
def
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@properties.each_pair do |type, props|
|
|
87
|
-
props.each { |p| prop_hash.store(p, type) }
|
|
65
|
+
def extract_default_values property
|
|
66
|
+
if property[:name] =~ /([^(\s*=\s*)]+)\s*=\s*(.+)/
|
|
67
|
+
property[:name] = $1
|
|
68
|
+
property[:default_value] = $2
|
|
88
69
|
end
|
|
89
70
|
|
|
90
|
-
|
|
71
|
+
property
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def organize_constructor_params params_array
|
|
75
|
+
return [] unless params_array
|
|
76
|
+
params_array.map{ |params| params.split(/ |, /) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def fix_default_overrides
|
|
80
|
+
@prop_default_overrides = []
|
|
81
|
+
return nil unless @parent
|
|
91
82
|
|
|
92
|
-
|
|
93
|
-
parent.
|
|
83
|
+
@prop_default_overrides = @properties.select { |p|
|
|
84
|
+
p.default_value && @parent.find_var( p.name )
|
|
85
|
+
}.map { |p| p.name }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def find_var var_name
|
|
89
|
+
result = nil
|
|
90
|
+
if @parent
|
|
91
|
+
result = @parent.find_var var_name
|
|
92
|
+
end
|
|
93
|
+
@properties.each do |property|
|
|
94
|
+
result = property if property.name == var_name
|
|
95
|
+
end
|
|
96
|
+
result
|
|
94
97
|
end
|
|
95
98
|
end
|
data/lib/ycn/method.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class Methodd
|
|
2
|
+
attr_accessor :name, :type, :parameters, :content
|
|
3
|
+
|
|
4
|
+
def initialize name, type, parameters, content
|
|
5
|
+
eval("extend #{camelize configatron.lang}Method")
|
|
6
|
+
|
|
7
|
+
@name = name
|
|
8
|
+
@type = type
|
|
9
|
+
@parameters = parameters || []
|
|
10
|
+
@content = content
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/ycn/property.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class Property
|
|
2
|
+
attr_accessor :klass, :name, :type, :default_value
|
|
3
|
+
|
|
4
|
+
def initialize klass, name, type, default_value
|
|
5
|
+
eval("extend #{camelize configatron.lang}Property")
|
|
6
|
+
|
|
7
|
+
@klass = klass
|
|
8
|
+
@name = name
|
|
9
|
+
@type = type
|
|
10
|
+
@default_value = default_value
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<%= klass.ruby_header %><%= klass.ruby_imports %>
|
|
2
|
+
<%= klass.ruby_class_declaration %>
|
|
3
|
+
<%= klass.ruby_accessors %>
|
|
4
|
+
<%= klass.ruby_constructors %><% for p in klass.properties do %>
|
|
5
|
+
<%= p.ruby_property %><% end %>
|
|
6
|
+
end
|
|
7
|
+
<% klass.methods.each do |m| %>
|
|
8
|
+
<%= m.ruby_signature %>
|
|
9
|
+
<%= m.ruby_show_content %>
|
|
10
|
+
end
|
|
11
|
+
<% end %>end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#coding: utf-8
|
|
2
|
+
|
|
3
|
+
module RubyKlass
|
|
4
|
+
def ruby_header
|
|
5
|
+
text = <<HEAD
|
|
6
|
+
Programme : #{configatron.program_name}
|
|
7
|
+
Auteur(s) : #{configatron.author_name}
|
|
8
|
+
Date : #{Time.now.day}/#{Time.now.month}/#{Time.now.year}
|
|
9
|
+
Description : #{configatron.description}
|
|
10
|
+
HEAD
|
|
11
|
+
|
|
12
|
+
text.split("\n").map{ |l|
|
|
13
|
+
"# #{l}\n"
|
|
14
|
+
}.join
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def ruby_imports
|
|
18
|
+
#~ text = properties.map{ |property|
|
|
19
|
+
#~ import = case property.type
|
|
20
|
+
#~ when 'Date'
|
|
21
|
+
#~ "import java.util.Date;"
|
|
22
|
+
#~ when 'Time'
|
|
23
|
+
#~ "import java.util.Time;"
|
|
24
|
+
#~ else
|
|
25
|
+
#~ nil
|
|
26
|
+
#~ end
|
|
27
|
+
#~ import
|
|
28
|
+
#~ }.compact
|
|
29
|
+
|
|
30
|
+
#~ if text.size > 0
|
|
31
|
+
#~ text = "\n" + text.join("\n") + "\n"
|
|
32
|
+
#~ end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def ruby_class_declaration
|
|
36
|
+
"class #{name}#{" < #{parent.name}" if parent}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def ruby_constructors
|
|
40
|
+
#~ @construct_params.map { |parameter_set|
|
|
41
|
+
#~ "\n public #{@name}(" +
|
|
42
|
+
|
|
43
|
+
#~ parameter_set.map { |parameter|
|
|
44
|
+
#~ type = find_var( parameter ).type
|
|
45
|
+
#~ "#{type} #{styled_var :riki, parameter, :p, type}"
|
|
46
|
+
|
|
47
|
+
#~ }.join(', ') + ")\n {\n " +
|
|
48
|
+
|
|
49
|
+
#~ parameter_set.map { |parameter|
|
|
50
|
+
#~ type = find_var( parameter ).type
|
|
51
|
+
#~ "set#{camelize parameter}(#{styled_var :riki, parameter, :p, type});"
|
|
52
|
+
#~ }.join("\n ") +
|
|
53
|
+
|
|
54
|
+
#~ java_prop_default_overrides
|
|
55
|
+
#~ }.join("\n }\n") + "\n }\n"
|
|
56
|
+
"def initialize " + @construct_params.last.join(', ')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#~ def java_prop_default_overrides
|
|
60
|
+
#~ prop_default_overrides.map { |property|
|
|
61
|
+
#~ property = find_var( property )
|
|
62
|
+
#~ "\n super.set#{camelize property.name}(#{property.default_value});"
|
|
63
|
+
#~ }.join("\n")
|
|
64
|
+
#~ end
|
|
65
|
+
|
|
66
|
+
def ruby_accessors; ruby_g_s_etters; end
|
|
67
|
+
|
|
68
|
+
def ruby_g_s_etters
|
|
69
|
+
"attr_accessor #{@properties.map{|p| ":#{p.name}"}.join(', ')}\n"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module RubyMethod
|
|
2
|
+
def ruby_signature
|
|
3
|
+
params = @parameters.map{ |p|
|
|
4
|
+
"#{p} p#{p[0].chr.downcase}_#{p}"
|
|
5
|
+
}.join(', ')
|
|
6
|
+
|
|
7
|
+
"def #{@name} #{params}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def ruby_show_content
|
|
11
|
+
#~ @content.split("\n").map { |line|
|
|
12
|
+
#~ unless line =~ /[\+\(]\s*$/
|
|
13
|
+
#~ line += ';'
|
|
14
|
+
#~ end
|
|
15
|
+
|
|
16
|
+
#~ line
|
|
17
|
+
#~ }.join("\n")
|
|
18
|
+
@content
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/ycn/string_manip.rb
CHANGED
|
@@ -10,11 +10,15 @@ module StringManip
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def camelize string
|
|
13
|
-
string.gsub('_', ' ').split(' ').map { |word|
|
|
13
|
+
string.to_s.gsub('_', ' ').split(' ').map { |word|
|
|
14
14
|
word.capitalize
|
|
15
15
|
}.join
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def camel_case string
|
|
19
|
+
camelize string
|
|
20
|
+
end
|
|
21
|
+
|
|
18
22
|
def low_camelize string
|
|
19
23
|
w = 0
|
|
20
24
|
string.gsub('_', ' ').split(' ').map { |word|
|
|
@@ -22,10 +26,4 @@ module StringManip
|
|
|
22
26
|
w == 1 ? word.downcase : word.capitalize
|
|
23
27
|
}.join
|
|
24
28
|
end
|
|
25
|
-
|
|
26
|
-
def self.camelize string
|
|
27
|
-
string.gsub('_', ' ').split(' ').map { |word|
|
|
28
|
-
word.capitalize
|
|
29
|
-
}.join
|
|
30
|
-
end
|
|
31
29
|
end
|
data/lib/ycn/version.rb
CHANGED
data/lib/ycn/ycn.rb
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
+
#coding: utf-8
|
|
2
|
+
|
|
1
3
|
module Ycn
|
|
2
|
-
def self.generate
|
|
3
|
-
puts 'moo'
|
|
4
|
+
def self.generate language, config
|
|
4
5
|
$base_dir = Dir.pwd
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
Header.configure_from config
|
|
8
|
+
config[:package] =
|
|
9
|
+
config[:package].to_s.gsub(' ', '_')
|
|
10
|
+
|
|
11
|
+
config[:getters] = true unless config.has_key? :getters
|
|
12
|
+
config[:setters] = true unless config.has_key? :setters
|
|
13
|
+
config[:constructors] = true unless config.has_key? :constructors
|
|
14
|
+
|
|
15
|
+
configatron { |c|
|
|
16
|
+
c.package = config[:package]
|
|
17
|
+
c.getters = config[:getters]
|
|
18
|
+
c.setters = config[:setters]
|
|
19
|
+
c.lang = language
|
|
20
|
+
}
|
|
12
21
|
|
|
13
|
-
Header.configure_from project_hash
|
|
14
|
-
project_hash[:package] =
|
|
15
|
-
project_hash[:package].to_s.gsub(' ', '_')
|
|
16
|
-
configatron { |c| c.package = project_hash[:package] }
|
|
17
|
-
|
|
18
22
|
classes_yaml = YAML::load(
|
|
19
23
|
correct_for_blank_last_method( open(
|
|
20
|
-
|
|
24
|
+
"#{$base_dir}/pcg/#{config[:package]}.yml")))
|
|
21
25
|
|
|
22
26
|
classes = []
|
|
23
27
|
|
|
@@ -26,21 +30,23 @@ module Ycn
|
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
fix_inheritance_and_overrides classes
|
|
29
|
-
|
|
30
|
-
generation_dir = "#{$base_dir}/generated_code"
|
|
31
|
-
package_name = "pcg#{StringManip::camelize configatron.package}"
|
|
32
|
-
output_dir = "#{generation_dir}/#{package_name}"
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
package_name = "pcg#{camelize configatron.package}"
|
|
35
|
+
output_dir = "#{$base_dir}/#{package_name}"
|
|
36
36
|
|
|
37
|
+
Dir.mkdir output_dir unless File.exists? output_dir
|
|
38
|
+
|
|
37
39
|
classes.each do |klass|
|
|
40
|
+
|
|
41
|
+
template = open( "#{File.dirname(__FILE__)}/#{language}/#{language}_class.erb" ).read
|
|
42
|
+
|
|
38
43
|
file_name = "#{klass.name}.#{extension[language]}"
|
|
39
44
|
|
|
40
45
|
File.open( "#{output_dir}/#{file_name}", 'w' ) { |f|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
content = klass.print_to( template )
|
|
47
|
+
f.print content
|
|
48
|
+
puts content
|
|
49
|
+
#~ pp klass
|
|
44
50
|
}
|
|
45
51
|
end
|
|
46
52
|
end
|
data/lib/ycn/ycn_functions.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#~ require 'property'
|
|
2
|
+
|
|
1
3
|
def correct_for_blank_last_method file
|
|
2
4
|
# Without this, a blank mapping on the last line of the file
|
|
3
5
|
# is incorrectly interpreted as a String.
|
|
@@ -17,8 +19,6 @@ end
|
|
|
17
19
|
def fix_inheritance_and_overrides classes
|
|
18
20
|
classes.each { |klass|
|
|
19
21
|
klass.parent = (classes.find_all{ |c| c.name == klass.parent })[0]
|
|
20
|
-
}.each { |klass|
|
|
21
|
-
klass.extract_default_values
|
|
22
22
|
}.each { |klass|
|
|
23
23
|
klass.fix_default_overrides }
|
|
24
24
|
end
|
data/website/index.html
CHANGED
|
@@ -1,11 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
7
|
+
<title>
|
|
8
|
+
ycn
|
|
9
|
+
</title>
|
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
|
11
|
+
<style>
|
|
12
|
+
|
|
13
|
+
</style>
|
|
14
|
+
<script type="text/javascript">
|
|
15
|
+
window.onload = function() {
|
|
16
|
+
settings = {
|
|
17
|
+
tl: { radius: 10 },
|
|
18
|
+
tr: { radius: 10 },
|
|
19
|
+
bl: { radius: 10 },
|
|
20
|
+
br: { radius: 10 },
|
|
21
|
+
antiAlias: true,
|
|
22
|
+
autoPad: true,
|
|
23
|
+
validTags: ["div"]
|
|
24
|
+
}
|
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
|
26
|
+
versionBox.applyCornersToAll();
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="main">
|
|
32
|
+
|
|
33
|
+
<h1>ycn</h1>
|
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ycn"; return false'>
|
|
35
|
+
<p>Get Version</p>
|
|
36
|
+
<a href="http://rubyforge.org/projects/ycn" class="numbers">0.0.1</a>
|
|
37
|
+
</div>
|
|
38
|
+
<h1>&#x2192; ‘ycn’</h1>
|
|
39
|
+
<h2>What</h2>
|
|
40
|
+
<h2>Installing</h2>
|
|
41
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">ycn</span></pre></p>
|
|
42
|
+
<h2>The basics</h2>
|
|
43
|
+
<h2>Demonstration of usage</h2>
|
|
44
|
+
<h2>Forum</h2>
|
|
45
|
+
<p><a href="http://groups.google.com/group/ycn">http://groups.google.com/group/ycn</a></p>
|
|
46
|
+
<p><span class="caps">TODO</span> – create Google Group – ycn</p>
|
|
47
|
+
<h2>How to submit patches</h2>
|
|
48
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
|
49
|
+
<p><span class="caps">TODO</span> – pick <span class="caps">SVN</span> or Git instructions</p>
|
|
50
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/ycn/trunk</code> for anonymous access.</p>
|
|
51
|
+
<p><span class="caps">OOOORRRR</span></p>
|
|
52
|
+
<p>You can fetch the source from either:</p>
|
|
53
|
+
<ul>
|
|
54
|
+
<li>rubyforge: <span class="caps">MISSING</span> IN <span class="caps">ACTION</span></li>
|
|
55
|
+
</ul>
|
|
56
|
+
<p><span class="caps">TODO</span> – You can not created a RubyForge project, OR have not run <code>rubyforge config</code><br />
|
|
57
|
+
yet to refresh your local rubyforge data with this projects’ id information.</p>
|
|
58
|
+
<p>When you do this, this message will magically disappear!</p>
|
|
59
|
+
<p>Or you can hack website/index.txt and make it all go away!!</p>
|
|
60
|
+
<ul>
|
|
61
|
+
<li>github: <a href="http://github.com/GITHUB_USERNAME/ycn/tree/master">http://github.com/GITHUB_USERNAME/ycn/tree/master</a></li>
|
|
62
|
+
</ul>
|
|
63
|
+
<pre>git clone git://github.com/GITHUB_USERNAME/ycn.git</pre>
|
|
64
|
+
<p><span class="caps">TODO</span> – add “github_username: username” to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.</p>
|
|
65
|
+
<ul>
|
|
66
|
+
<li>gitorious: <a href="git://gitorious.org/ycn/mainline.git">git://gitorious.org/ycn/mainline.git</a></li>
|
|
67
|
+
</ul>
|
|
68
|
+
<pre>git clone git://gitorious.org/ycn/mainline.git</pre>
|
|
69
|
+
<h3>Build and test instructions</h3>
|
|
70
|
+
<pre>cd ycn
|
|
71
|
+
rake test
|
|
72
|
+
rake install_gem</pre>
|
|
73
|
+
<h2>License</h2>
|
|
74
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
|
75
|
+
<h2>Contact</h2>
|
|
76
|
+
<p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/ycn">forum</a></p>
|
|
77
|
+
<p class="coda">
|
|
78
|
+
<a href="FIXME email">FIXME full name</a>, 22nd September 2008<br>
|
|
79
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
|
80
|
+
</p>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
|
84
|
+
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ycn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Koster
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-
|
|
12
|
+
date: 2008-10-07 00:00:00 -04:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -47,12 +47,21 @@ files:
|
|
|
47
47
|
- config/hoe.rb
|
|
48
48
|
- config/requirements.rb
|
|
49
49
|
- lib/ycn.rb
|
|
50
|
-
- lib/ycn/version.rb
|
|
51
|
-
- lib/ycn/ycn.rb
|
|
52
50
|
- lib/ycn/header.rb
|
|
53
|
-
- lib/ycn/java_klass.rb
|
|
51
|
+
- lib/ycn/java/java_klass.rb
|
|
52
|
+
- lib/ycn/java/java_method.rb
|
|
53
|
+
- lib/ycn/java/java_property.rb
|
|
54
|
+
- lib/ycn/java/java_class.erb
|
|
55
|
+
- lib/ycn/ruby/ruby_klass.rb
|
|
56
|
+
- lib/ycn/ruby/ruby_method.rb
|
|
57
|
+
- lib/ycn/ruby/ruby_property.rb
|
|
58
|
+
- lib/ycn/ruby/ruby_class.erb
|
|
54
59
|
- lib/ycn/klass.rb
|
|
60
|
+
- lib/ycn/method.rb
|
|
61
|
+
- lib/ycn/property.rb
|
|
55
62
|
- lib/ycn/string_manip.rb
|
|
63
|
+
- lib/ycn/version.rb
|
|
64
|
+
- lib/ycn/ycn.rb
|
|
56
65
|
- lib/ycn/ycn_functions.rb
|
|
57
66
|
- script/console
|
|
58
67
|
- script/console.cmd
|
|
@@ -75,14 +84,12 @@ files:
|
|
|
75
84
|
- website/template.html.erb
|
|
76
85
|
has_rdoc: true
|
|
77
86
|
homepage: http://ycn.rubyforge.org
|
|
78
|
-
post_install_message:
|
|
79
|
-
|
|
80
|
-
For more information on ycn, see http://ycn.rubyforge.org
|
|
81
|
-
|
|
82
|
-
NOTE: Change this information in PostInstall.txt
|
|
83
|
-
You can also delete it if you don't want it.
|
|
84
|
-
|
|
87
|
+
post_install_message: |-
|
|
88
|
+
For more information on ycn, see :
|
|
85
89
|
|
|
90
|
+
- http://ycn.rubyforge.org
|
|
91
|
+
- http://naturalcode.wordpress.com
|
|
92
|
+
- http://github.com/naturalcode/ycn/tree
|
|
86
93
|
rdoc_options:
|
|
87
94
|
- --main
|
|
88
95
|
- README.txt
|
data/lib/ycn/java_klass.rb
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
module JavaKlass
|
|
2
|
-
def java_header
|
|
3
|
-
text = <<HEAD
|
|
4
|
-
Programme : #{configatron.program_name}
|
|
5
|
-
Auteur(s) : #{configatron.author_name}
|
|
6
|
-
Date : #{Time.now.day}/#{Time.now.month}/#{Time.now.year}
|
|
7
|
-
Description : #{configatron.description}
|
|
8
|
-
HEAD
|
|
9
|
-
|
|
10
|
-
'/*' + text.split("\n").map{ |l|
|
|
11
|
-
"\n * #{l}"
|
|
12
|
-
}.join + "\n */\n"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def to_java
|
|
16
|
-
java_header+
|
|
17
|
-
java_package+
|
|
18
|
-
java_imports+
|
|
19
|
-
java_class_declaration+
|
|
20
|
-
java_properties+
|
|
21
|
-
java_constructors+
|
|
22
|
-
java_methods+
|
|
23
|
-
java_g_s_etters+
|
|
24
|
-
java_bottom
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def java_package
|
|
28
|
-
@package ? "\npackage pcg#{camelize @package};\n" : ''
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def java_imports
|
|
32
|
-
text = ''
|
|
33
|
-
if properties
|
|
34
|
-
text += properties.keys.map{ |type|
|
|
35
|
-
type == 'Date' ? "\nimport java.util.Date;\n" : nil
|
|
36
|
-
}.join
|
|
37
|
-
end
|
|
38
|
-
text
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def java_class_declaration
|
|
42
|
-
<<TEXT
|
|
43
|
-
|
|
44
|
-
public class #{name}#{" extends #{parent.name}" if parent}
|
|
45
|
-
{
|
|
46
|
-
TEXT
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def java_properties
|
|
50
|
-
text = ''
|
|
51
|
-
|
|
52
|
-
if properties
|
|
53
|
-
properties.each_pair do |type, prop_names|
|
|
54
|
-
if prop_names.class == Array
|
|
55
|
-
empty_set = true
|
|
56
|
-
|
|
57
|
-
text += prop_names.map { |name|
|
|
58
|
-
if prop_default_overrides[name]
|
|
59
|
-
''
|
|
60
|
-
else
|
|
61
|
-
empty_set = false
|
|
62
|
-
name_displayed = styled_var :riki, name, :g, type
|
|
63
|
-
value_assignment = prop_defaults[name] ? " = #{prop_defaults[name]}" : nil
|
|
64
|
-
|
|
65
|
-
" private #{type} #{name_displayed}#{value_assignment};\n"
|
|
66
|
-
end
|
|
67
|
-
}.join# + (empty_set ? '' : "\n")
|
|
68
|
-
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
text = (text == '') ? '' : "\n#{text}"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def java_constructors
|
|
77
|
-
text = <<TEXT
|
|
78
|
-
|
|
79
|
-
// Constructeur par défaut
|
|
80
|
-
public #{name}()
|
|
81
|
-
{#{_java_prop_default_overrides}
|
|
82
|
-
TEXT
|
|
83
|
-
#~ text +=
|
|
84
|
-
text += "#{"\n" unless prop_default_overrides.keys.size > 0} }\n"
|
|
85
|
-
if construct_params
|
|
86
|
-
#~ pp construct_params
|
|
87
|
-
text += construct_params.map{ |constructor|
|
|
88
|
-
"\n public #{name}(" +
|
|
89
|
-
constructor.map { |param|
|
|
90
|
-
type = find_type(param)
|
|
91
|
-
"#{type} #{styled_var :riki, param, :p, type}"
|
|
92
|
-
}.join(', ') + ")\n {\n" +
|
|
93
|
-
constructor.map { |param|
|
|
94
|
-
type = find_type(param)
|
|
95
|
-
" set#{camelize param}(#{styled_var :riki, param, :p, type});"
|
|
96
|
-
}.join("\n") +
|
|
97
|
-
_java_prop_default_overrides + "\n }\n"
|
|
98
|
-
}.join
|
|
99
|
-
end
|
|
100
|
-
text
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def _java_prop_default_overrides
|
|
104
|
-
p = prop_default_overrides.keys.map { |property|
|
|
105
|
-
"\n super.set#{camelize property}(#{prop_default_overrides[property]});"
|
|
106
|
-
}.join("\n")
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def java_methods
|
|
110
|
-
text = ""
|
|
111
|
-
#~ puts "#{pp(methods)}"
|
|
112
|
-
if methods.class == Hash
|
|
113
|
-
methods.each_pair do |type, meth|
|
|
114
|
-
#~ puts 't' + type
|
|
115
|
-
if meth.class == Hash
|
|
116
|
-
meth.each_pair { |m, contents|
|
|
117
|
-
|
|
118
|
-
if method_params[m]
|
|
119
|
-
parameters = method_params[m].map{ |item|
|
|
120
|
-
"#{camelize item} #{styled_var :riki, item, :p, item}"
|
|
121
|
-
}.join(', ')
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
text += "\n public #{type} #{low_camelize m}(" +
|
|
125
|
-
"#{parameters if parameters})\n" +
|
|
126
|
-
" {\n#{contents.split("\n").map{ |l| " #{l}#{';' if !(l =~ /(\+|\{|\}|\()\z/)}"}.join("\n") if contents}\n }\n"
|
|
127
|
-
}
|
|
128
|
-
else
|
|
129
|
-
puts "Warning! No method type for #{type}"
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
else
|
|
134
|
-
|
|
135
|
-
end
|
|
136
|
-
text
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def java_g_s_etters
|
|
140
|
-
text = ''
|
|
141
|
-
if properties
|
|
142
|
-
properties.each_pair do |type, prop_names|
|
|
143
|
-
text += prop_names.map { |name|
|
|
144
|
-
unless prop_default_overrides[name]
|
|
145
|
-
<<TEXT
|
|
146
|
-
|
|
147
|
-
public #{type} get#{camelize name}()
|
|
148
|
-
{
|
|
149
|
-
return #{styled_var :riki, name, :g, type };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public void set#{camelize name}(#{type} #{styled_var :riki, name, :p, type})
|
|
153
|
-
{
|
|
154
|
-
#{styled_var :riki, name, :g, type } = #{styled_var :riki, name, :p, type};
|
|
155
|
-
}
|
|
156
|
-
TEXT
|
|
157
|
-
else
|
|
158
|
-
''
|
|
159
|
-
end
|
|
160
|
-
}.join
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
text
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def java_bottom
|
|
167
|
-
'}'
|
|
168
|
-
end
|
|
169
|
-
end
|