codemodels-java 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +198 -0
- data/README.md +6 -0
- data/Rakefile +13 -0
- data/codemodels-java.gemspec +24 -0
- data/lib/codemodels/java/info_extraction.rb +110 -0
- data/lib/codemodels/java/java_models_builder.rb +17 -0
- data/lib/codemodels/java/language.rb +17 -0
- data/lib/codemodels/java/metamodel.rb +234 -0
- data/lib/codemodels/java/model_building.rb +42 -0
- data/lib/codemodels/java/parser.rb +83 -0
- data/lib/codemodels/java.rb +10 -0
- data/lib/jars/javaparser-1.0.8.jar +0 -0
- data/test/data/ActionButtonsColumnTag.java +100 -0
- data/test/data/AuthConstraint.java +17 -0
- data/test/data/CsvExporter.java +58 -0
- data/test/data/ReorderStoriesForm.java +100 -0
- data/test/data/TestIteration.java +192 -0
- data/test/data/example_accessors.java +24 -0
- data/test/data/example_basic.java +5 -0
- data/test/test_correspondences.rb +31 -0
- data/test/test_helper.rb +57 -0
- data/test/test_info_extraction.rb +258 -0
- data/test/test_metamodel.rb +133 -0
- data/test/test_parsing.rb +174 -0
- data/test/test_values.rb +361 -0
- metadata +188 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
Eclipse Public License - v 1.0
|
2
|
+
|
3
|
+
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
|
4
|
+
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
5
|
+
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
6
|
+
|
7
|
+
1. DEFINITIONS
|
8
|
+
|
9
|
+
"Contribution" means:
|
10
|
+
|
11
|
+
a) in the case of the initial Contributor, the initial code and documentation
|
12
|
+
distributed under this Agreement, and
|
13
|
+
b) in the case of each subsequent Contributor:
|
14
|
+
i) changes to the Program, and
|
15
|
+
ii) additions to the Program;
|
16
|
+
|
17
|
+
where such changes and/or additions to the Program originate from and are
|
18
|
+
distributed by that particular Contributor. A Contribution 'originates' from
|
19
|
+
a Contributor if it was added to the Program by such Contributor itself or
|
20
|
+
anyone acting on such Contributor's behalf. Contributions do not include
|
21
|
+
additions to the Program which: (i) are separate modules of software
|
22
|
+
distributed in conjunction with the Program under their own license
|
23
|
+
agreement, and (ii) are not derivative works of the Program.
|
24
|
+
|
25
|
+
"Contributor" means any person or entity that distributes the Program.
|
26
|
+
|
27
|
+
"Licensed Patents" mean patent claims licensable by a Contributor which are
|
28
|
+
necessarily infringed by the use or sale of its Contribution alone or when
|
29
|
+
combined with the Program.
|
30
|
+
|
31
|
+
"Program" means the Contributions distributed in accordance with this Agreement.
|
32
|
+
|
33
|
+
"Recipient" means anyone who receives the Program under this Agreement,
|
34
|
+
including all Contributors.
|
35
|
+
|
36
|
+
2. GRANT OF RIGHTS
|
37
|
+
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
38
|
+
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
39
|
+
reproduce, prepare derivative works of, publicly display, publicly perform,
|
40
|
+
distribute and sublicense the Contribution of such Contributor, if any, and
|
41
|
+
such derivative works, in source code and object code form.
|
42
|
+
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
43
|
+
Recipient a non-exclusive, worldwide, royalty-free patent license under
|
44
|
+
Licensed Patents to make, use, sell, offer to sell, import and otherwise
|
45
|
+
transfer the Contribution of such Contributor, if any, in source code and
|
46
|
+
object code form. This patent license shall apply to the combination of the
|
47
|
+
Contribution and the Program if, at the time the Contribution is added by
|
48
|
+
the Contributor, such addition of the Contribution causes such combination
|
49
|
+
to be covered by the Licensed Patents. The patent license shall not apply
|
50
|
+
to any other combinations which include the Contribution. No hardware per
|
51
|
+
se is licensed hereunder.
|
52
|
+
c) Recipient understands that although each Contributor grants the licenses to
|
53
|
+
its Contributions set forth herein, no assurances are provided by any
|
54
|
+
Contributor that the Program does not infringe the patent or other
|
55
|
+
intellectual property rights of any other entity. Each Contributor
|
56
|
+
disclaims any liability to Recipient for claims brought by any other entity
|
57
|
+
based on infringement of intellectual property rights or otherwise. As a
|
58
|
+
condition to exercising the rights and licenses granted hereunder, each
|
59
|
+
Recipient hereby assumes sole responsibility to secure any other
|
60
|
+
intellectual property rights needed, if any. For example, if a third party
|
61
|
+
patent license is required to allow Recipient to distribute the Program, it
|
62
|
+
is Recipient's responsibility to acquire that license before distributing
|
63
|
+
the Program.
|
64
|
+
d) Each Contributor represents that to its knowledge it has sufficient
|
65
|
+
copyright rights in its Contribution, if any, to grant the copyright
|
66
|
+
license set forth in this Agreement.
|
67
|
+
|
68
|
+
3. REQUIREMENTS
|
69
|
+
|
70
|
+
A Contributor may choose to distribute the Program in object code form under its
|
71
|
+
own license agreement, provided that:
|
72
|
+
|
73
|
+
a) it complies with the terms and conditions of this Agreement; and
|
74
|
+
b) its license agreement:
|
75
|
+
i) effectively disclaims on behalf of all Contributors all warranties and
|
76
|
+
conditions, express and implied, including warranties or conditions of
|
77
|
+
title and non-infringement, and implied warranties or conditions of
|
78
|
+
merchantability and fitness for a particular purpose;
|
79
|
+
ii) effectively excludes on behalf of all Contributors all liability for
|
80
|
+
damages, including direct, indirect, special, incidental and
|
81
|
+
consequential damages, such as lost profits;
|
82
|
+
iii) states that any provisions which differ from this Agreement are offered
|
83
|
+
by that Contributor alone and not by any other party; and
|
84
|
+
iv) states that source code for the Program is available from such
|
85
|
+
Contributor, and informs licensees how to obtain it in a reasonable
|
86
|
+
manner on or through a medium customarily used for software exchange.
|
87
|
+
|
88
|
+
When the Program is made available in source code form:
|
89
|
+
|
90
|
+
a) it must be made available under this Agreement; and
|
91
|
+
b) a copy of this Agreement must be included with each copy of the Program.
|
92
|
+
Contributors may not remove or alter any copyright notices contained within
|
93
|
+
the Program.
|
94
|
+
|
95
|
+
Each Contributor must identify itself as the originator of its Contribution, if
|
96
|
+
any, in a manner that reasonably allows subsequent Recipients to identify the
|
97
|
+
originator of the Contribution.
|
98
|
+
|
99
|
+
4. COMMERCIAL DISTRIBUTION
|
100
|
+
|
101
|
+
Commercial distributors of software may accept certain responsibilities with
|
102
|
+
respect to end users, business partners and the like. While this license is
|
103
|
+
intended to facilitate the commercial use of the Program, the Contributor who
|
104
|
+
includes the Program in a commercial product offering should do so in a manner
|
105
|
+
which does not create potential liability for other Contributors. Therefore, if
|
106
|
+
a Contributor includes the Program in a commercial product offering, such
|
107
|
+
Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
|
108
|
+
every other Contributor ("Indemnified Contributor") against any losses, damages
|
109
|
+
and costs (collectively "Losses") arising from claims, lawsuits and other legal
|
110
|
+
actions brought by a third party against the Indemnified Contributor to the
|
111
|
+
extent caused by the acts or omissions of such Commercial Contributor in
|
112
|
+
connection with its distribution of the Program in a commercial product
|
113
|
+
offering. The obligations in this section do not apply to any claims or Losses
|
114
|
+
relating to any actual or alleged intellectual property infringement. In order
|
115
|
+
to qualify, an Indemnified Contributor must: a) promptly notify the Commercial
|
116
|
+
Contributor in writing of such claim, and b) allow the Commercial Contributor to
|
117
|
+
control, and cooperate with the Commercial Contributor in, the defense and any
|
118
|
+
related settlement negotiations. The Indemnified Contributor may participate in
|
119
|
+
any such claim at its own expense.
|
120
|
+
|
121
|
+
For example, a Contributor might include the Program in a commercial product
|
122
|
+
offering, Product X. That Contributor is then a Commercial Contributor. If that
|
123
|
+
Commercial Contributor then makes performance claims, or offers warranties
|
124
|
+
related to Product X, those performance claims and warranties are such
|
125
|
+
Commercial Contributor's responsibility alone. Under this section, the
|
126
|
+
Commercial Contributor would have to defend claims against the other
|
127
|
+
Contributors related to those performance claims and warranties, and if a court
|
128
|
+
requires any other Contributor to pay any damages as a result, the Commercial
|
129
|
+
Contributor must pay those damages.
|
130
|
+
|
131
|
+
5. NO WARRANTY
|
132
|
+
|
133
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
|
134
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
135
|
+
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
|
136
|
+
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
|
137
|
+
Recipient is solely responsible for determining the appropriateness of using and
|
138
|
+
distributing the Program and assumes all risks associated with its exercise of
|
139
|
+
rights under this Agreement , including but not limited to the risks and costs
|
140
|
+
of program errors, compliance with applicable laws, damage to or loss of data,
|
141
|
+
programs or equipment, and unavailability or interruption of operations.
|
142
|
+
|
143
|
+
6. DISCLAIMER OF LIABILITY
|
144
|
+
|
145
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
146
|
+
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
147
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
148
|
+
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
149
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
150
|
+
OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS
|
151
|
+
GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
152
|
+
|
153
|
+
7. GENERAL
|
154
|
+
|
155
|
+
If any provision of this Agreement is invalid or unenforceable under applicable
|
156
|
+
law, it shall not affect the validity or enforceability of the remainder of the
|
157
|
+
terms of this Agreement, and without further action by the parties hereto, such
|
158
|
+
provision shall be reformed to the minimum extent necessary to make such
|
159
|
+
provision valid and enforceable.
|
160
|
+
|
161
|
+
If Recipient institutes patent litigation against any entity (including a
|
162
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
|
163
|
+
(excluding combinations of the Program with other software or hardware)
|
164
|
+
infringes such Recipient's patent(s), then such Recipient's rights granted under
|
165
|
+
Section 2(b) shall terminate as of the date such litigation is filed.
|
166
|
+
|
167
|
+
All Recipient's rights under this Agreement shall terminate if it fails to
|
168
|
+
comply with any of the material terms or conditions of this Agreement and does
|
169
|
+
not cure such failure in a reasonable period of time after becoming aware of
|
170
|
+
such noncompliance. If all Recipient's rights under this Agreement terminate,
|
171
|
+
Recipient agrees to cease use and distribution of the Program as soon as
|
172
|
+
reasonably practicable. However, Recipient's obligations under this Agreement
|
173
|
+
and any licenses granted by Recipient relating to the Program shall continue and
|
174
|
+
survive.
|
175
|
+
|
176
|
+
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
177
|
+
order to avoid inconsistency the Agreement is copyrighted and may only be
|
178
|
+
modified in the following manner. The Agreement Steward reserves the right to
|
179
|
+
publish new versions (including revisions) of this Agreement from time to time.
|
180
|
+
No one other than the Agreement Steward has the right to modify this Agreement.
|
181
|
+
The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation
|
182
|
+
may assign the responsibility to serve as the Agreement Steward to a suitable
|
183
|
+
separate entity. Each new version of the Agreement will be given a
|
184
|
+
distinguishing version number. The Program (including Contributions) may always
|
185
|
+
be distributed subject to the version of the Agreement under which it was
|
186
|
+
received. In addition, after a new version of the Agreement is published,
|
187
|
+
Contributor may elect to distribute the Program (including its Contributions)
|
188
|
+
under the new version. Except as expressly stated in Sections 2(a) and 2(b)
|
189
|
+
above, Recipient receives no rights or licenses to the intellectual property of
|
190
|
+
any Contributor under this Agreement, whether expressly, by implication,
|
191
|
+
estoppel or otherwise. All rights in the Program not expressly granted under
|
192
|
+
this Agreement are reserved.
|
193
|
+
|
194
|
+
This Agreement is governed by the laws of the State of New York and the
|
195
|
+
intellectual property laws of the United States of America. No party to this
|
196
|
+
Agreement will bring a legal action under this Agreement more than one year
|
197
|
+
after the cause of action arose. Each party waives its rights to a jury trial in
|
198
|
+
any resulting litigation.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = 'java'
|
3
|
+
s.name = 'codemodels-java'
|
4
|
+
s.version = '0.2.0'
|
5
|
+
s.date = '2013-09-11'
|
6
|
+
s.summary = "Plugin of codemodels to build models from Ruby code."
|
7
|
+
s.description = "Plugin of codemodels to build models from Ruby code. See http://github.com/ftomassetti/codemodels."
|
8
|
+
s.authors = ["Federico Tomassetti"]
|
9
|
+
s.email = 'f.tomassetti@gmail.com'
|
10
|
+
s.homepage = 'https://github.com/ftomassetti/java-lightmodels'
|
11
|
+
s.license = "APACHE2"
|
12
|
+
s.files = `git ls-files`.split($/)
|
13
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
s.require_paths = ["lib"] + Dir['./lib/jars/*.jar']
|
16
|
+
|
17
|
+
s.add_runtime_dependency 'codemodels'
|
18
|
+
s.add_runtime_dependency 'json'
|
19
|
+
|
20
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "simplecov"
|
23
|
+
s.add_development_dependency "rubygems-tasks"
|
24
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module CodeModels
|
2
|
+
|
3
|
+
module Java
|
4
|
+
|
5
|
+
module InfoExtraction
|
6
|
+
|
7
|
+
def self.is_camel_case_str(s)
|
8
|
+
not s.index /[^A-Za-z0-9]/
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.camel_to_words(camel)
|
12
|
+
return [''] if camel==''
|
13
|
+
|
14
|
+
# if camel contains an upcase word and it is followed by something then
|
15
|
+
# extract it and process the camel before and after
|
16
|
+
# to understand where the upcase word ends we have to look if there is
|
17
|
+
# a downcase char after
|
18
|
+
upcaseword_index = camel.index /[A-Z]{2}/
|
19
|
+
number_index = camel.index /[0-9]/
|
20
|
+
if upcaseword_index
|
21
|
+
if upcaseword_index==0
|
22
|
+
words_before = []
|
23
|
+
else
|
24
|
+
camel_before = camel[0..upcaseword_index-1]
|
25
|
+
words_before = camel_to_words(camel_before)
|
26
|
+
end
|
27
|
+
|
28
|
+
camel_from = camel[upcaseword_index..-1]
|
29
|
+
has_other_after = camel_from.index /[^A-Z]/
|
30
|
+
if has_other_after
|
31
|
+
is_lower_case_after = camel_from[has_other_after].index /[a-z]/
|
32
|
+
if is_lower_case_after
|
33
|
+
mod = 1
|
34
|
+
else
|
35
|
+
mod = 0
|
36
|
+
end
|
37
|
+
upcase_word = camel_from[0..has_other_after-1-mod]
|
38
|
+
camel_after = camel_from[has_other_after-mod..-1]
|
39
|
+
words_after = camel_to_words(camel_after)
|
40
|
+
else
|
41
|
+
upcase_word = camel_from
|
42
|
+
words_after = []
|
43
|
+
end
|
44
|
+
words = words_before
|
45
|
+
words << upcase_word
|
46
|
+
words = words + words_after
|
47
|
+
words
|
48
|
+
elsif number_index
|
49
|
+
if number_index==0
|
50
|
+
words_before = []
|
51
|
+
else
|
52
|
+
camel_before = camel[0..number_index-1]
|
53
|
+
words_before = camel_to_words(camel_before)
|
54
|
+
end
|
55
|
+
|
56
|
+
camel_from = camel[number_index..-1]
|
57
|
+
has_other_after = camel_from.index /[^0-9]/
|
58
|
+
if has_other_after
|
59
|
+
number_word = camel_from[0..has_other_after-1]
|
60
|
+
camel_after = camel_from[has_other_after..-1]
|
61
|
+
words_after = camel_to_words(camel_after)
|
62
|
+
else
|
63
|
+
number_word = camel_from
|
64
|
+
words_after = []
|
65
|
+
end
|
66
|
+
words = words_before
|
67
|
+
words << number_word
|
68
|
+
words = words + words_after
|
69
|
+
words
|
70
|
+
else
|
71
|
+
camel.split /(?=[A-Z])/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class JavaSpecificInfoExtractionLogic
|
76
|
+
|
77
|
+
def terms_containing_value?(value)
|
78
|
+
CodeModels::Java::InfoExtraction.is_camel_case_str(value)
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_words(value)
|
82
|
+
res = ::CodeModels::Java::InfoExtraction.camel_to_words(value)
|
83
|
+
res.each {|v| raise "Camel case to words produced a nil" if v==nil}
|
84
|
+
raise "No words found using the camel case to words" if res.count==0
|
85
|
+
res
|
86
|
+
end
|
87
|
+
|
88
|
+
def concat(a,b)
|
89
|
+
a+b
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end # end of InfoExtraction
|
95
|
+
|
96
|
+
module JavaInfoExtractionFunctionalities
|
97
|
+
|
98
|
+
def terms_map(context=nil)
|
99
|
+
super(InfoExtraction::JavaSpecificInfoExtractionLogic.new,context)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
class JavaNode
|
105
|
+
include JavaInfoExtractionFunctionalities
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'codemodels/java/model_building'
|
3
|
+
require 'codemodels'
|
4
|
+
|
5
|
+
$PWD = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
raise "Usage: java_models_builder <sources> <models>" unless ARGV.count==2
|
8
|
+
|
9
|
+
sources_path = ARGV[0]
|
10
|
+
models_path = ARGV[1]
|
11
|
+
raise "Path to sources does not exist or it is not a dir: #{sources_path}" unless File.exist?(sources_path) and File.directory?(sources_path)
|
12
|
+
raise "Path to models does not exist or it is not a dir: #{models_path}" unless File.exist?(models_path) and File.directory?(models_path)
|
13
|
+
|
14
|
+
$SRC = sources_path
|
15
|
+
$DEST = models_path
|
16
|
+
|
17
|
+
CodeModels::Java.generate_java_models_in_dir($SRC,$DEST)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'codemodels'
|
2
|
+
|
3
|
+
module CodeModels
|
4
|
+
module Java
|
5
|
+
|
6
|
+
class JavaLanguage < Language
|
7
|
+
def initialize
|
8
|
+
super('Java')
|
9
|
+
@extensions << 'java'
|
10
|
+
@parser = CodeModels::Java::Parser.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
CodeModels.register_language JavaLanguage.new
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'rgen/metamodel_builder'
|
2
|
+
require 'java'
|
3
|
+
require 'codemodels'
|
4
|
+
|
5
|
+
module CodeModels
|
6
|
+
module Java
|
7
|
+
|
8
|
+
class JavaNode < RGen::MetamodelBuilder::MMBase
|
9
|
+
end
|
10
|
+
|
11
|
+
JavaString = ::Java::JavaClass.for_name("java.lang.String")
|
12
|
+
JavaList = ::Java::JavaClass.for_name("java.util.List")
|
13
|
+
JavaBoolean = ::Java::boolean.java_class
|
14
|
+
JavaInt = ::Java::int.java_class
|
15
|
+
JapaMethodDeclaration = ::Java::JavaClass.for_name("japa.parser.ast.body.MethodDeclaration")
|
16
|
+
|
17
|
+
MappedAstClasses = {}
|
18
|
+
|
19
|
+
def self.wrap(ast_names)
|
20
|
+
|
21
|
+
# first create all the classes
|
22
|
+
ast_names.each do |ast_name|
|
23
|
+
java_class = ::Java::JavaClass.for_name("japa.parser.ast.#{ast_name}")
|
24
|
+
java_super_class = java_class.superclass
|
25
|
+
if java_super_class.name == 'japa.parser.ast.Node'
|
26
|
+
super_class = JavaNode
|
27
|
+
else
|
28
|
+
raise "Super class #{java_super_class.name} of #{java_class.name}. It should be wrapped before!" unless MappedAstClasses[java_super_class]
|
29
|
+
super_class = MappedAstClasses[java_super_class]
|
30
|
+
end
|
31
|
+
#puts "Java Super Class: #{java_super_class.name}"
|
32
|
+
ast_class = java_class.ruby_class
|
33
|
+
# TODO it should extend the right class...
|
34
|
+
c = Class.new(super_class)
|
35
|
+
raise "Already mapped! #{ast_name}" if MappedAstClasses[java_class]
|
36
|
+
MappedAstClasses[java_class] = c
|
37
|
+
Java.const_set simple_java_class_name(ast_class), c
|
38
|
+
end
|
39
|
+
|
40
|
+
# then add all the properties and attributes
|
41
|
+
ast_names.each do |ast_name|
|
42
|
+
java_class = ::Java::JavaClass.for_name("japa.parser.ast.#{ast_name}")
|
43
|
+
ast_class = java_class.ruby_class
|
44
|
+
c = MappedAstClasses[java_class]
|
45
|
+
|
46
|
+
props_to_ignore = ['modifiers','arrayCount','operator','comments','javaDoc','varArgs','interface']
|
47
|
+
|
48
|
+
c.class_eval do
|
49
|
+
ast_class.java_class.declared_instance_methods.select {|m| m.name.start_with?('get')||m.name.start_with?('is') }.each do |m|
|
50
|
+
prop_name = CodeModels::Java.property_name(m)
|
51
|
+
unless props_to_ignore.include?(prop_name)
|
52
|
+
if m.return_type==JavaString
|
53
|
+
has_attr prop_name, String
|
54
|
+
elsif m.return_type==JavaBoolean
|
55
|
+
has_attr prop_name, RGen::MetamodelBuilder::DataTypes::Boolean
|
56
|
+
elsif m.return_type==JavaInt
|
57
|
+
has_attr prop_name, Integer
|
58
|
+
elsif MappedAstClasses.has_key?(m.return_type)
|
59
|
+
contains_one_uni prop_name, MappedAstClasses[m.return_type]
|
60
|
+
elsif m.return_type==JavaList
|
61
|
+
# puts "Property #{prop_name} is a list"
|
62
|
+
type_name = CodeModels::Java.get_generic_param(m.to_generic_string)
|
63
|
+
last = type_name.index '>'
|
64
|
+
type_name = type_name[0..last-1]
|
65
|
+
type_ast_class = MappedAstClasses.keys.find{|k| k.name==type_name}
|
66
|
+
if type_ast_class
|
67
|
+
contains_many_uni prop_name, MappedAstClasses[type_ast_class]
|
68
|
+
else
|
69
|
+
raise "#{ast_name}) Property (many) #{prop_name} is else: #{type_name}"
|
70
|
+
end
|
71
|
+
elsif m.return_type.enum?
|
72
|
+
has_attr prop_name, String
|
73
|
+
else
|
74
|
+
raise "#{ast_name}) Property (single) #{prop_name} is else: #{m.return_type}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
#type = nil
|
78
|
+
#contains_one_uni prop_name, type
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.get_corresponding_metaclass(node)
|
85
|
+
node_class = node.class
|
86
|
+
name = simple_java_class_name(node_class)
|
87
|
+
name = "#{(node.operator.name).proper_capitalize}BinaryExpr" if name=='BinaryExpr'
|
88
|
+
#puts "node.class: #{node.class}"
|
89
|
+
if node.class.to_s=='Java::JapaParserAstBody::MethodDeclaration'
|
90
|
+
if node.parent.class.to_s=='Java::JapaParserAstExpr::ObjectCreationExpr'
|
91
|
+
# ObjectCreationExpr has not interface? but it is always a method definition
|
92
|
+
name = 'ClassMethodDeclaration'
|
93
|
+
elsif node.parent.class.to_s=='Java::JapaParserAstBody::EnumDeclaration'
|
94
|
+
name = 'ClassMethodDeclaration'
|
95
|
+
elsif node.parent.interface?
|
96
|
+
name = 'InterfaceMethodDeclaration'
|
97
|
+
else
|
98
|
+
name = 'ClassMethodDeclaration'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
return Java.const_get(name)
|
102
|
+
end
|
103
|
+
|
104
|
+
PROP_ADAPTERS = Hash.new {|h,k| h[k] = {} }
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def self.property_name(java_method)
|
109
|
+
return java_method.name.remove_prefix('get').proper_uncapitalize if java_method.name.start_with?('get')
|
110
|
+
return java_method.name.remove_prefix('is').proper_uncapitalize if java_method.name.start_with?('is')
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.simple_java_class_name(java_class)
|
114
|
+
name = java_class.name
|
115
|
+
if (i = (r = name).rindex(':')) then r[0..i] = '' end
|
116
|
+
r
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.get_generic_param(generic_str)
|
120
|
+
return generic_str.remove_prefix('public java.util.List<') if generic_str.start_with?('public java.util.List<')
|
121
|
+
return generic_str.remove_prefix('public final java.util.List<') if generic_str.start_with?('public final java.util.List<')
|
122
|
+
nil
|
123
|
+
end
|
124
|
+
|
125
|
+
wrap [
|
126
|
+
'Comment',
|
127
|
+
'BlockComment',
|
128
|
+
'LineComment',
|
129
|
+
'ImportDeclaration',
|
130
|
+
'CompilationUnit',
|
131
|
+
'TypeParameter',
|
132
|
+
'PackageDeclaration',
|
133
|
+
|
134
|
+
'body.BodyDeclaration',
|
135
|
+
'body.TypeDeclaration',
|
136
|
+
'body.AnnotationDeclaration',
|
137
|
+
'body.AnnotationMemberDeclaration',
|
138
|
+
'body.JavadocComment',
|
139
|
+
'body.VariableDeclaratorId',
|
140
|
+
'body.Parameter',
|
141
|
+
'body.MethodDeclaration',
|
142
|
+
'body.ClassOrInterfaceDeclaration',
|
143
|
+
'body.EmptyMemberDeclaration',
|
144
|
+
'body.EmptyTypeDeclaration',
|
145
|
+
'body.EnumConstantDeclaration',
|
146
|
+
'body.EnumDeclaration',
|
147
|
+
'body.FieldDeclaration',
|
148
|
+
'body.InitializerDeclaration',
|
149
|
+
'body.ConstructorDeclaration',
|
150
|
+
'body.VariableDeclarator',
|
151
|
+
|
152
|
+
'expr.Expression',
|
153
|
+
'expr.NameExpr',
|
154
|
+
'expr.AnnotationExpr',
|
155
|
+
'expr.ArrayAccessExpr',
|
156
|
+
'expr.ArrayCreationExpr',
|
157
|
+
'expr.ArrayInitializerExpr',
|
158
|
+
'expr.AssignExpr',
|
159
|
+
'expr.BinaryExpr',
|
160
|
+
'expr.LiteralExpr',
|
161
|
+
'expr.BooleanLiteralExpr',
|
162
|
+
'expr.CastExpr',
|
163
|
+
'expr.StringLiteralExpr',
|
164
|
+
'expr.CharLiteralExpr',
|
165
|
+
'expr.ClassExpr',
|
166
|
+
'expr.ConditionalExpr',
|
167
|
+
'expr.DoubleLiteralExpr',
|
168
|
+
'expr.EnclosedExpr',
|
169
|
+
'expr.FieldAccessExpr',
|
170
|
+
'expr.InstanceOfExpr',
|
171
|
+
'expr.IntegerLiteralExpr',
|
172
|
+
'expr.IntegerLiteralMinValueExpr',
|
173
|
+
'expr.LongLiteralExpr',
|
174
|
+
'expr.LongLiteralMinValueExpr',
|
175
|
+
'expr.MarkerAnnotationExpr',
|
176
|
+
'expr.MemberValuePair',
|
177
|
+
'expr.MethodCallExpr',
|
178
|
+
'expr.NormalAnnotationExpr',
|
179
|
+
'expr.NullLiteralExpr',
|
180
|
+
'expr.ObjectCreationExpr',
|
181
|
+
'expr.QualifiedNameExpr',
|
182
|
+
'expr.SingleMemberAnnotationExpr',
|
183
|
+
'expr.SuperExpr',
|
184
|
+
'expr.ThisExpr',
|
185
|
+
'expr.UnaryExpr',
|
186
|
+
'expr.VariableDeclarationExpr',
|
187
|
+
|
188
|
+
'stmt.Statement',
|
189
|
+
'stmt.BlockStmt',
|
190
|
+
'stmt.AssertStmt',
|
191
|
+
'stmt.BreakStmt',
|
192
|
+
'stmt.CatchClause',
|
193
|
+
'stmt.ContinueStmt',
|
194
|
+
'stmt.DoStmt',
|
195
|
+
'stmt.EmptyStmt',
|
196
|
+
'stmt.ExplicitConstructorInvocationStmt',
|
197
|
+
'stmt.ExpressionStmt',
|
198
|
+
'stmt.ForeachStmt',
|
199
|
+
'stmt.ForStmt',
|
200
|
+
'stmt.IfStmt',
|
201
|
+
'stmt.LabeledStmt',
|
202
|
+
'stmt.ReturnStmt',
|
203
|
+
'stmt.SwitchEntryStmt',
|
204
|
+
'stmt.SwitchStmt',
|
205
|
+
'stmt.SynchronizedStmt',
|
206
|
+
'stmt.ThrowStmt',
|
207
|
+
'stmt.TryStmt',
|
208
|
+
'stmt.TypeDeclarationStmt',
|
209
|
+
'stmt.WhileStmt',
|
210
|
+
|
211
|
+
'type.Type',
|
212
|
+
'type.ClassOrInterfaceType',
|
213
|
+
'type.PrimitiveType',
|
214
|
+
'type.ReferenceType',
|
215
|
+
'type.VoidType',
|
216
|
+
'type.WildcardType' ]
|
217
|
+
|
218
|
+
['Or','And','BinOr','BinAnd', 'Xor',
|
219
|
+
'Equals','NotEquals',
|
220
|
+
'Less','Greater','LessEquals','GreaterEquals',
|
221
|
+
'LShift','RSignedShift','RUnsignedShift',
|
222
|
+
'Plus', 'Minus', 'Times','Divide','Remainder'].each do |op|
|
223
|
+
c = Class.new(BinaryExpr)
|
224
|
+
Java.const_set "#{op}BinaryExpr", c
|
225
|
+
end
|
226
|
+
|
227
|
+
class InterfaceMethodDeclaration < MethodDeclaration
|
228
|
+
end
|
229
|
+
|
230
|
+
class ClassMethodDeclaration < MethodDeclaration
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|