guff 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +37 -21
- data/README.txt +1 -3
- data/Rakefile +3 -53
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/guff.rb +8 -2
- data/lib/guff/java_source.rb +167 -35
- data/lib/guff/version.rb +9 -9
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -1585
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/java_source/files/ClassWithConstructors.java +22 -0
- data/test/java_source/files/ClassWithFields.java +4 -0
- data/test/java_source/files/ClassWithImports.java +8 -0
- data/test/java_source/files/ClassWithMethods.java +5 -1
- data/test/java_source/files/GenericClass.java +3 -0
- data/test/java_source/{annotation_declaration_test.rb → test_annotation_declaration.rb} +0 -0
- data/test/java_source/{class_declaration_test.rb → test_class_declaration.rb} +20 -0
- data/test/java_source/{field_declaration_test.rb → test_field_declaration.rb} +1 -1
- data/test/java_source/test_helper.rb +0 -2
- data/test/java_source/test_import_declaration.rb +14 -0
- data/test/java_source/{method_declaration_test.rb → test_method_declaration.rb} +4 -2
- data/test/test_helper.rb +2 -1
- data/website/index.html +326 -0
- data/website/index.txt +240 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +82 -50
- data/CHANGELOG.txt +0 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Mike Hogan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
CHANGED
@@ -1,21 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
lib/guff.rb
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
test/java_source/
|
19
|
-
test/java_source/
|
20
|
-
test/java_source/
|
21
|
-
test/
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/guff.rb
|
9
|
+
lib/guff/java_source.rb
|
10
|
+
lib/guff/version.rb
|
11
|
+
script/destroy
|
12
|
+
script/generate
|
13
|
+
script/txt2html
|
14
|
+
setup.rb
|
15
|
+
tasks/deployment.rake
|
16
|
+
tasks/environment.rake
|
17
|
+
tasks/website.rake
|
18
|
+
test/java_source/test_annotation_declaration.rb
|
19
|
+
test/java_source/test_class_declaration.rb
|
20
|
+
test/java_source/test_field_declaration.rb
|
21
|
+
test/java_source/test_import_declaration.rb
|
22
|
+
test/java_source/test_method_declaration.rb
|
23
|
+
test/java_source/files/ClassWithAnnotatedFields.java
|
24
|
+
test/java_source/files/ClassWithAnnotatedMethods.java
|
25
|
+
test/java_source/files/ClassWithConstructors.java
|
26
|
+
test/java_source/files/ClassWithFields.java
|
27
|
+
test/java_source/files/ClassWithImports.java
|
28
|
+
test/java_source/files/ClassWithMethods.java
|
29
|
+
test/java_source/files/EmptyClass.java
|
30
|
+
test/java_source/files/GenericClass.java
|
31
|
+
test/java_source/test_helper.rb
|
32
|
+
test/test_helper.rb
|
33
|
+
website/index.html
|
34
|
+
website/index.txt
|
35
|
+
website/javascripts/rounded_corners_lite.inc.js
|
36
|
+
website/stylesheets/screen.css
|
37
|
+
website/template.rhtml
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,54 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rake/gempackagetask'
|
7
|
-
require 'rake/rdoctask'
|
8
|
-
require 'rake/contrib/rubyforgepublisher'
|
9
|
-
require 'fileutils'
|
10
|
-
require 'hoe'
|
11
|
-
include FileUtils
|
12
|
-
require File.join(File.dirname(__FILE__), 'lib', 'guff', 'version')
|
1
|
+
require 'config/requirements'
|
2
|
+
require 'config/hoe' # setup Hoe + all gem configuration
|
13
3
|
|
14
|
-
|
15
|
-
EMAIL = "me@mikehogan.net"
|
16
|
-
DESCRIPTION = "An API to describe and generate Java source code. The idea is to avoid writing all the 'guff' that is typical in java projects by generating it from more succinct ruby models."
|
17
|
-
GEM_NAME = "guff" # what ppl will type to install your gem
|
18
|
-
RUBYFORGE_PROJECT = "guff" # The unix name for your project
|
19
|
-
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
20
|
-
|
21
|
-
|
22
|
-
NAME = "guff"
|
23
|
-
REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
|
-
VERS = ENV['VERSION'] || (Guff::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
25
|
-
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
26
|
-
RDOC_OPTS = ['--quiet', '--title', "guff documentation",
|
27
|
-
"--opname", "index.html",
|
28
|
-
"--line-numbers",
|
29
|
-
"--main", "README",
|
30
|
-
"--inline-source"]
|
31
|
-
|
32
|
-
class Hoe
|
33
|
-
def extra_deps
|
34
|
-
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Generate all the Rake tasks
|
39
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
40
|
-
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
41
|
-
p.author = AUTHOR
|
42
|
-
p.description = DESCRIPTION
|
43
|
-
p.email = EMAIL
|
44
|
-
p.summary = DESCRIPTION
|
45
|
-
p.url = HOMEPATH
|
46
|
-
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
47
|
-
p.test_globs = ["test/**/*_test.rb"]
|
48
|
-
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
49
|
-
|
50
|
-
# == Optional
|
51
|
-
#p.changes - A description of the release's latest changes.
|
52
|
-
#p.extra_deps - An array of rubygem dependencies.
|
53
|
-
#p.spec_extras - A hash of extra values to set in the gemspec.
|
54
|
-
end
|
4
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'guff/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Mike Hogan' # can also be an array of Authors
|
4
|
+
EMAIL = "me@mikehogan.net"
|
5
|
+
DESCRIPTION = "Provides a set of classes to describe and save java classes. The idea is to avoid writing all the 'guff' that is typical in java projects by generating it from more succinct ruby models"
|
6
|
+
GEM_NAME = 'guff' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'guff' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "unknown"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = Guff::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'guff documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.author = AUTHOR
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.email = EMAIL
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
62
|
+
# p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'guff'
|
data/lib/guff.rb
CHANGED
data/lib/guff/java_source.rb
CHANGED
@@ -36,27 +36,65 @@ module Guff
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
|
40
|
+
module ClassMember
|
41
|
+
def import(i)
|
42
|
+
@owning_class.import(i)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
39
46
|
module AnnotationSupport
|
40
|
-
def add_annotation(type,value=nil)
|
41
|
-
annotation = Annotation.new(type,value)
|
42
|
-
|
47
|
+
def add_annotation(type, value=nil)
|
48
|
+
annotation = Annotation.new(type, value)
|
49
|
+
annotations << annotation
|
43
50
|
yield annotation if block_given?
|
44
51
|
self
|
45
52
|
end
|
46
53
|
|
54
|
+
def annotations
|
55
|
+
@annotations ||= []
|
56
|
+
end
|
57
|
+
|
47
58
|
def write_annotations_to(writer)
|
48
|
-
|
59
|
+
annotations.each {|a|
|
49
60
|
a.write_to(writer)
|
50
61
|
writer.new_line
|
51
62
|
}
|
52
63
|
end
|
53
64
|
end
|
54
65
|
|
66
|
+
module Named
|
67
|
+
def named?(query)
|
68
|
+
@name == query
|
69
|
+
end
|
70
|
+
|
71
|
+
def name
|
72
|
+
@name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
55
76
|
module ParameterSupport
|
56
77
|
def takes(name, type)
|
57
|
-
|
78
|
+
parameters << Parameter.new(name, type)
|
58
79
|
self
|
59
80
|
end
|
81
|
+
|
82
|
+
def taking(name,type)
|
83
|
+
takes(name,type)
|
84
|
+
end
|
85
|
+
|
86
|
+
def parameters_list
|
87
|
+
result = []
|
88
|
+
parameters.each {|p|
|
89
|
+
result << p.as_source
|
90
|
+
}
|
91
|
+
result.join(',')
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def parameters
|
96
|
+
@parameters ||= []
|
97
|
+
end
|
60
98
|
end
|
61
99
|
|
62
100
|
module ScopeSupport
|
@@ -83,19 +121,62 @@ module Guff
|
|
83
121
|
|
84
122
|
module ModifierSupport
|
85
123
|
def static
|
86
|
-
|
124
|
+
modifiers << 'static'
|
87
125
|
self
|
88
126
|
end
|
89
127
|
|
90
128
|
def final
|
91
|
-
|
129
|
+
modifiers << 'final'
|
92
130
|
self
|
93
131
|
end
|
94
132
|
|
95
133
|
def abstract
|
96
|
-
|
134
|
+
modifiers << 'abstract'
|
97
135
|
self
|
98
136
|
end
|
137
|
+
|
138
|
+
def modifiers
|
139
|
+
@modifiers ||= []
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
module JavadocSupport
|
144
|
+
def add_javadoc(d)
|
145
|
+
javadoc_lines << d
|
146
|
+
self
|
147
|
+
end
|
148
|
+
|
149
|
+
def write_javadoc_to(writer)
|
150
|
+
if (!javadoc_lines.empty?)
|
151
|
+
writer.line("/**")
|
152
|
+
javadoc_lines.each do |line|
|
153
|
+
writer.line(" * #{line}")
|
154
|
+
end
|
155
|
+
writer.line(" */")
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
def javadoc_lines
|
161
|
+
@javadoc_lines ||= []
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
module ThrowsSupport
|
166
|
+
def throws(exception)
|
167
|
+
exceptions << exception
|
168
|
+
self
|
169
|
+
end
|
170
|
+
|
171
|
+
def append_throws_clause(writer)
|
172
|
+
if (!exceptions.empty?)
|
173
|
+
writer.append(' throws ').append(exceptions.join(', '))
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def exceptions
|
178
|
+
@exceptions ||= []
|
179
|
+
end
|
99
180
|
end
|
100
181
|
|
101
182
|
class UnnamedProperty
|
@@ -127,7 +208,7 @@ module Guff
|
|
127
208
|
end
|
128
209
|
|
129
210
|
class Annotation
|
130
|
-
def initialize(type,value=nil)
|
211
|
+
def initialize(type, value=nil)
|
131
212
|
@type = type
|
132
213
|
@properties = []
|
133
214
|
@properties << UnnamedProperty.new(value) unless value.nil?
|
@@ -173,13 +254,12 @@ module Guff
|
|
173
254
|
end
|
174
255
|
|
175
256
|
class Constructor
|
176
|
-
include ArgumentsHelper, ParameterSupport, AnnotationSupport
|
257
|
+
include ArgumentsHelper, ParameterSupport, AnnotationSupport, JavadocSupport, ThrowsSupport, ClassMember
|
177
258
|
|
178
|
-
def initialize(name)
|
259
|
+
def initialize(owning_class,name)
|
260
|
+
@owning_class=owning_class
|
179
261
|
@name = name
|
180
|
-
@parameters = []
|
181
262
|
@body = Body.default_body
|
182
|
-
@annotations = []
|
183
263
|
end
|
184
264
|
|
185
265
|
def body
|
@@ -188,23 +268,40 @@ module Guff
|
|
188
268
|
self
|
189
269
|
end
|
190
270
|
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
|
271
|
+
def for_field(field_name)
|
272
|
+
add_takes_clause_for_field(field_name)
|
273
|
+
body {|body|
|
274
|
+
add_assignment_for_field_name(body,field_name)
|
195
275
|
}
|
196
|
-
|
276
|
+
end
|
277
|
+
|
278
|
+
def for_fields(*field_names)
|
279
|
+
field_names.each {|field_name| add_takes_clause_for_field(field_name)}
|
280
|
+
body {|body|
|
281
|
+
field_names.each {|field_name| add_assignment_for_field_name(body,field_name)}
|
282
|
+
}
|
283
|
+
end
|
284
|
+
|
285
|
+
def add_assignment_for_field_name(body,field_name)
|
286
|
+
body.line("this.#{field_name}=#{field_name};")
|
287
|
+
end
|
288
|
+
|
289
|
+
def add_takes_clause_for_field(field_name)
|
290
|
+
field=@owning_class.get_field_named(field_name)
|
291
|
+
takes(field.name, field.declared_type)
|
197
292
|
end
|
198
293
|
|
199
294
|
def write_to(writer)
|
200
295
|
writer.ensure_member_separation_line
|
296
|
+
write_javadoc_to(writer)
|
201
297
|
write_annotations_to(writer)
|
202
298
|
write_declaration(writer)
|
299
|
+
append_throws_clause(writer)
|
203
300
|
@body.write_to(writer) unless @body.nil?
|
204
301
|
end
|
205
302
|
|
206
303
|
def write_declaration(writer)
|
207
|
-
writer.append("public #{@name}(" ).append(
|
304
|
+
writer.append("public #{@name}(" ).append(parameters_list).append(")")
|
208
305
|
end
|
209
306
|
end
|
210
307
|
|
@@ -284,10 +381,10 @@ module Guff
|
|
284
381
|
class Method < Constructor
|
285
382
|
include ScopeSupport, ModifierSupport, AnnotationSupport
|
286
383
|
|
287
|
-
def initialize(name)
|
288
|
-
super(name)
|
384
|
+
def initialize(owning_class,name)
|
385
|
+
super(owning_class,name)
|
289
386
|
@return_type = 'void'
|
290
|
-
@
|
387
|
+
@exceptions = []
|
291
388
|
@scope = 'public'
|
292
389
|
end
|
293
390
|
|
@@ -296,6 +393,11 @@ module Guff
|
|
296
393
|
self
|
297
394
|
end
|
298
395
|
|
396
|
+
def throws(e)
|
397
|
+
@exceptions << e
|
398
|
+
self
|
399
|
+
end
|
400
|
+
|
299
401
|
def returns_list_of(t)
|
300
402
|
@return_type= "List<#{t}>"
|
301
403
|
self
|
@@ -305,35 +407,41 @@ module Guff
|
|
305
407
|
@return_type
|
306
408
|
end
|
307
409
|
|
410
|
+
|
308
411
|
def write_declaration(writer)
|
309
|
-
writer.word(@scope).words(
|
412
|
+
writer.word(@scope).words(modifiers).word(@return_type).word("#{@name}(").append(parameters_list).append(")")
|
310
413
|
end
|
414
|
+
|
311
415
|
end
|
312
416
|
|
313
417
|
class Field
|
314
|
-
include ScopeSupport, ModifierSupport, AnnotationSupport
|
315
|
-
def initialize(name, type)
|
418
|
+
include ScopeSupport, ModifierSupport, AnnotationSupport, JavadocSupport, ClassMember, Named
|
419
|
+
def initialize(owning_class,name, type)
|
420
|
+
@owning_class=owning_class
|
316
421
|
@name = name
|
317
422
|
@type = type
|
318
423
|
@scope = 'private'
|
319
|
-
@modifiers = []
|
320
424
|
@initializer = ''
|
321
|
-
@annotations = []
|
322
425
|
end
|
323
426
|
|
324
427
|
def write_to(writer)
|
428
|
+
write_javadoc_to(writer)
|
325
429
|
write_annotations_to(writer)
|
326
|
-
writer.word(@scope).words(
|
430
|
+
writer.word(@scope).words(modifiers).word(@type).word(@name).word(@initializer).semi_colon.new_line
|
327
431
|
end
|
328
432
|
|
329
433
|
def initial(i)
|
330
434
|
@initializer = "= #{i}"
|
331
435
|
self
|
332
436
|
end
|
437
|
+
|
438
|
+
def declared_type
|
439
|
+
@type
|
440
|
+
end
|
333
441
|
end
|
334
442
|
|
335
443
|
class Class
|
336
|
-
include ScopeSupport, ModifierSupport, AnnotationSupport
|
444
|
+
include ScopeSupport, ModifierSupport, AnnotationSupport, JavadocSupport
|
337
445
|
|
338
446
|
def initialize(name, package, source_file)
|
339
447
|
@name = name;
|
@@ -346,16 +454,25 @@ module Guff
|
|
346
454
|
@source_file=source_file
|
347
455
|
@genericized_using = ''
|
348
456
|
@interfaces = nil
|
349
|
-
@annotations = []
|
350
457
|
@implements = nil
|
351
458
|
end
|
352
459
|
|
353
460
|
def add_field(name, type)
|
354
|
-
f = Field.new(name, type)
|
461
|
+
f = Field.new(self,name, type)
|
355
462
|
@fields << f
|
356
463
|
f
|
357
464
|
end
|
358
465
|
|
466
|
+
def get_field_named(name)
|
467
|
+
candidates = @fields.select {|field| field.named?(name)}
|
468
|
+
return candidates.size == 1 ? candidates.first : nil;
|
469
|
+
end
|
470
|
+
|
471
|
+
def import(i)
|
472
|
+
@source_file.import(i)
|
473
|
+
self
|
474
|
+
end
|
475
|
+
|
359
476
|
def genericized_using(g)
|
360
477
|
@genericized_using = g
|
361
478
|
self
|
@@ -380,20 +497,21 @@ module Guff
|
|
380
497
|
end
|
381
498
|
|
382
499
|
def add_method(name)
|
383
|
-
result = Method.new(name)
|
500
|
+
result = Method.new(self,name)
|
384
501
|
@instance_methods << result
|
385
502
|
result
|
386
503
|
end
|
387
504
|
|
388
505
|
def add_constructor
|
389
|
-
result = Constructor.new(
|
506
|
+
result = Constructor.new(self,@name)
|
390
507
|
@constructors << result
|
391
508
|
result
|
392
509
|
end
|
393
510
|
|
394
511
|
def write_to(writer)
|
512
|
+
write_javadoc_to(writer)
|
395
513
|
write_annotations_to(writer)
|
396
|
-
writer.words(
|
514
|
+
writer.words(modifiers).word("class").word(@name).append(@genericized_using).word_with_prefix('extends', @extends).list_with_prefix('implements', @implements).open_brace
|
397
515
|
|
398
516
|
@fields.each {|f|
|
399
517
|
f.write_to(writer)
|
@@ -412,12 +530,13 @@ module Guff
|
|
412
530
|
def initialize
|
413
531
|
@package = 'set the package'
|
414
532
|
@classes = []
|
533
|
+
@imports = []
|
415
534
|
end
|
416
535
|
|
417
536
|
def save_in(root)
|
418
537
|
writer = Printer.new
|
419
538
|
write_to(writer)
|
420
|
-
directory = root
|
539
|
+
directory = "#{root}/#{package_as_directory}"
|
421
540
|
if (!FileTest.exist?(directory))
|
422
541
|
FileUtils.mkdir_p(directory)
|
423
542
|
end
|
@@ -428,6 +547,13 @@ module Guff
|
|
428
547
|
filename
|
429
548
|
end
|
430
549
|
|
550
|
+
def import(i)
|
551
|
+
if (!@imports.include?(i))
|
552
|
+
@imports << i
|
553
|
+
end
|
554
|
+
self
|
555
|
+
end
|
556
|
+
|
431
557
|
def package_as_directory
|
432
558
|
@package.split('.').join('/')
|
433
559
|
end
|
@@ -447,6 +573,12 @@ module Guff
|
|
447
573
|
|
448
574
|
def write_to(writer)
|
449
575
|
writer.line(package_def).line
|
576
|
+
@imports.each do |import|
|
577
|
+
writer.line("import #{import};")
|
578
|
+
end
|
579
|
+
if (!@imports.empty?)
|
580
|
+
writer.line
|
581
|
+
end
|
450
582
|
@classes.each {|c|
|
451
583
|
c.write_to(writer)
|
452
584
|
}
|