codemodels-javaparserwrapper 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60973d39ebfb42c7f7e2e426eb829f6ec0b323da
4
+ data.tar.gz: ccd9faf9072ab7b6fe4caadfbc0167c6686f1dcb
5
+ SHA512:
6
+ metadata.gz: e34f15e61ccb365ba660626c4d3cd9e1ed701160724bf1206d3d5203db3a54d02f166a21e4df754ef560130e095ff34697f90e2ea1efa8a4e4906a38120b6110
7
+ data.tar.gz: 8dfd6843e9654a0b3bdc8d27d29c9620bc792264a892ef58fb4acdcfe40da3aba93f507a3b68c1e96075b9d50072ecf0c4b3aa42c2a7a987d2540d52409f2522
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codemodels-javaparserwrapper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ codemodels-javaparserwrapper
2
+ ============================
3
+
4
+ Code to wrap parsers written in Java and produce models suitable to be used in CodeModels
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+ require 'rubygems/tasks'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ Gem::Tasks.new do |tasks|
9
+ tasks.console.command = 'jruby'
10
+ end
11
+
12
+ desc "Run tests"
13
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codemodels/javaparserwrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.platform = 'java'
8
+ spec.name = "codemodels-javaparserwrapper"
9
+ spec.version = CodeModels::JavaParserWrapper::VERSION
10
+ spec.authors = ["Federico Tomassetti"]
11
+ spec.email = ["f.tomassetti@gmail.com"]
12
+ spec.description = %q{Code to wrap parsers written in Java and produce models suitable to be used in CodeModels}
13
+ spec.summary = %q{Code to wrap parsers written in Java and produce models suitable to be used in CodeModels}
14
+ spec.homepage = ""
15
+ spec.license = "Apache v2"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "codemodels"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "rubygems-tasks"
28
+ end
@@ -0,0 +1,3 @@
1
+ require "codemodels/javaparserwrapper/version"
2
+ require "codemodels/javaparserwrapper/parserwrapper"
3
+ require "codemodels/javaparserwrapper/utils"
@@ -0,0 +1,221 @@
1
+ require 'codemodels'
2
+
3
+ module CodeModels
4
+ module JavaParserWrapper
5
+
6
+ # for compatibility, going to be removed in the future
7
+ Javaparserwrapper = JavaParserWrapper
8
+
9
+ module TransformationFactory
10
+
11
+ def instantiate_transformed(original)
12
+ target_class = get_corresponding_class(original)
13
+ instance = target_class.new
14
+ end
15
+
16
+ end
17
+
18
+ # They look in a specified Module for a class with
19
+ # the same name as the class of the original object
20
+ class BasicTransformationFactory
21
+ include TransformationFactory
22
+
23
+ attr_accessor :target_module
24
+
25
+ protected
26
+
27
+ def get_corresponding_class(original)
28
+ raise "target_module not set" if @target_module.nil?
29
+ original_class = original.class
30
+ class_name = Utils.simple_java_class_name(original_class)
31
+ raise "No corresponding class '#{class_name}' found in #{@target_module}" unless @target_module.const_defined?(class_name)
32
+ @target_module.const_get(class_name)
33
+ end
34
+
35
+ end
36
+
37
+ # A Parser built wrapping a base parser written in Java
38
+ class ParserJavaWrapper < CodeModels::Parser
39
+
40
+ def initialize(transformer=JavaObjectsToRgenTransformer.new)
41
+ @transformer = transformer
42
+ end
43
+
44
+ def node_to_model(node)
45
+ @transformer.node_to_model(node)
46
+ end
47
+
48
+ end
49
+
50
+ class JavaObjectsToRgenTransformer
51
+
52
+ attr_accessor :verbose
53
+
54
+ def initialize(factory=BasicTransformationFactory.new)
55
+ @verbose = false
56
+ @factory = factory
57
+ end
58
+
59
+ attr_accessor :factory
60
+
61
+ JavaCollection = ::Java::JavaClass.for_name("java.util.Collection")
62
+
63
+ def log(msg)
64
+ puts msg if verbose
65
+ end
66
+
67
+ def adapter_specific_class(model_class,ref)
68
+ nil
69
+ end
70
+
71
+ def adapter(model_class,ref)
72
+ if adapter_specific_class(model_class,ref)
73
+ adapter_specific_class(model_class,ref)
74
+ else
75
+ if model_class.superclass!=Object
76
+ adapter(model_class.superclass,ref)
77
+ else
78
+ nil
79
+ end
80
+ end
81
+ end
82
+
83
+ def reference_to_method(model_class,ref)
84
+ s = ref.name
85
+ adapted = adapter(model_class,ref)
86
+ s = adapted if adapted
87
+ s.to_sym
88
+ end
89
+
90
+ def attribute_to_method(model_class,att)
91
+ s = att.name
92
+ adapted = adapter(model_class,att)
93
+ s = adapted if adapted
94
+ s.to_sym
95
+ end
96
+
97
+ def assign_ref_to_model(model,ref,value)
98
+ return unless value==nil # we do not need to assign a nil...
99
+ if ref.many
100
+ adder_method = :"add#{ref.name.capitalize}"
101
+ value.each {|el| model.send(adder_method,node_to_model(el))}
102
+ else
103
+ setter_method = :"#{ref.name}="
104
+ raise "Trying to assign an array to a single property. Class #{model.class}, property #{ref.name}" if value.is_a?(::Array)
105
+ model.send(setter_method,node_to_model(value))
106
+ end
107
+ rescue Object => e
108
+ puts "Problem while assigning ref #{ref.name} (many? #{ref.many}) to #{model.class}. Value: #{value.class}"
109
+ puts "\t<<#{e}>>"
110
+ raise e
111
+ end
112
+
113
+ def assign_att_to_model(model,att,value)
114
+ if att.many
115
+ adder_method = :"add#{att.name.capitalize}"
116
+ value.each {|el| model.send(adder_method,el)}
117
+ else
118
+ setter_method = :"#{att.name}="
119
+ raise "Trying to assign an array to a single property. Class #{model.class}, property #{att.name}" if value.is_a?(::Array)
120
+ model.send(setter_method,value)
121
+ end
122
+ end
123
+
124
+ def populate_attr(node,att,model)
125
+ value = get_feature_value(node,att)
126
+ model.send(:"#{att.name}=",value) if value!=nil
127
+ rescue Object => e
128
+ puts "Problem while populating attribute #{att.name} of #{model} from #{node}. Value: #{value}"
129
+ raise e
130
+ end
131
+
132
+ def populate_ref(node,ref,model)
133
+ log("populate ref #{ref.name}, node: #{node.class}, model: #{model.class}")
134
+ value = get_feature_value(node,ref)
135
+ log("\tvalue=#{value.class}")
136
+ if value!=nil
137
+ if value==node
138
+ puts "avoiding loop... #{ref.name}, class #{node.class}"
139
+ return
140
+ end
141
+ if JavaCollection.assignable_from?(value.java_class)
142
+ log("\tvalue is a collection")
143
+ capitalized_name = ref.name.proper_capitalize
144
+ value.each do |el|
145
+ unless el.respond_to?(:parent)
146
+ el.class.__persistent__ = true
147
+ class << el
148
+ attr_accessor :parent
149
+ end
150
+ end
151
+ el.parent = node
152
+ model.send(:"add#{capitalized_name}",node_to_model(el))
153
+ end
154
+ else
155
+ log("\tvalue is not a collection")
156
+ unless value.respond_to?(:parent)
157
+ value.class.__persistent__ = true
158
+ class << value
159
+ attr_accessor :parent
160
+ end
161
+ end
162
+ value.parent = node
163
+ model.send(:"#{ref.name}=",node_to_model(value))
164
+ end
165
+ end
166
+ end
167
+
168
+ # def instantiate_transformed(node)
169
+ # raise "Should include a TransformationFactory"
170
+ # end
171
+
172
+ def node_to_model(node)
173
+ log("node_to_model #{node.class}")
174
+ instance = @factory.instantiate_transformed(node)
175
+ metaclass = instance.class
176
+ metaclass.ecore.eAllAttributes.each do |attr|
177
+ populate_attr(node,attr,instance)
178
+ end
179
+ metaclass.ecore.eAllReferences.each do |ref|
180
+ populate_ref(node,ref,instance)
181
+ end
182
+ instance
183
+ end
184
+
185
+ def transform_enum_values(value)
186
+ if value.respond_to?(:java_class) && value.java_class.enum?
187
+ value.name
188
+ else
189
+ value
190
+ end
191
+ end
192
+
193
+ def get_feature_value_through_getter(node,feat_name)
194
+ capitalized_name = feat_name.proper_capitalize
195
+ methods = [:"get#{capitalized_name}",:"is#{capitalized_name}"]
196
+
197
+ methods.each do |m|
198
+ if node.respond_to?(m)
199
+ begin
200
+ return transform_enum_values(node.send(m))
201
+ rescue Object => e
202
+ raise "Problem invoking #{m} on #{node.class}: #{e}"
203
+ end
204
+ end
205
+ end
206
+ raise "how should I get this... #{feat_name} on #{node.class}. It does not respond to #{methods}"
207
+ end
208
+
209
+ def get_feature_value(node,feat)
210
+ adapter = adapter(node.class,feat)
211
+ if adapter
212
+ adapter[:adapter].call(node)
213
+ else
214
+ get_feature_value_through_getter(node,feat.name)
215
+ end
216
+ end
217
+
218
+ end
219
+
220
+ end
221
+ end
@@ -0,0 +1,18 @@
1
+ module CodeModels
2
+ module JavaParserWrapper
3
+
4
+ module Utils
5
+
6
+ def self.simple_java_class_name(java_class)
7
+ if java_class.is_a?(::Java::JavaClass)
8
+ return Utils.simple_java_class_name(java_class.ruby_class)
9
+ end
10
+ name = java_class.name
11
+ if (i = (r = name).rindex(':')) then r[0..i] = '' end
12
+ r
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module CodeModels
2
+ module JavaParserWrapper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/test/.gitignore ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ rm *.jar
2
+ rm -Rf classes/*
3
+ javac -d classes src/*
4
+ jar cf dummyjavaparser.jar classes/
@@ -0,0 +1,24 @@
1
+ package it.codemodels.javaparserwrapper.ast;
2
+
3
+ import java.util.List;
4
+ import java.util.LinkedList;
5
+ import java.util.Date;
6
+
7
+ public class Comment {
8
+
9
+ private Date insertionDate;
10
+ private String content;
11
+
12
+ public Comment(Date insertionDate, String content){
13
+ this.insertionDate = insertionDate;
14
+ this.content = content;
15
+ }
16
+
17
+ public String getContent(){
18
+ return content;
19
+ }
20
+
21
+ public Date getInsertionDate(){
22
+ return insertionDate;
23
+ }
24
+ }
@@ -0,0 +1,17 @@
1
+ package it.codemodels.javaparserwrapper;
2
+
3
+ import it.codemodels.javaparserwrapper.ast.Project;
4
+
5
+ public class DummyJavaParser {
6
+
7
+ private Project root = null;
8
+
9
+ public void setRoot(Project root){
10
+ this.root = root;
11
+ }
12
+
13
+ public Project parse(){
14
+ return this.root;
15
+ }
16
+
17
+ }
@@ -0,0 +1,27 @@
1
+ package it.codemodels.javaparserwrapper.ast;
2
+
3
+ import java.util.List;
4
+ import java.util.LinkedList;
5
+
6
+ public class Project {
7
+
8
+ private String name;
9
+ private List<Todo> todos;
10
+
11
+ public Project(String name){
12
+ this.name = name;
13
+ this.todos = new LinkedList<Todo>();
14
+ }
15
+
16
+ public void addTodo(Todo todo){
17
+ this.todos.add(todo);
18
+ }
19
+
20
+ public List<Todo> getTodos(){
21
+ return todos;
22
+ }
23
+
24
+ public String getName(){
25
+ return this.name;
26
+ }
27
+ }
@@ -0,0 +1,43 @@
1
+ package it.codemodels.javaparserwrapper.ast;
2
+
3
+ import java.util.List;
4
+ import java.util.LinkedList;
5
+
6
+ public class Todo {
7
+
8
+ public enum Status {
9
+ COMPLETED,
10
+ WORKING_ON,
11
+ NOT_STARTED
12
+ };
13
+
14
+ private String description;
15
+ private Status status;
16
+ private List<Comment> comments;
17
+
18
+ public Todo(String description){
19
+ this.description = description;
20
+ this.status = Status.NOT_STARTED;
21
+ this.comments = new LinkedList<Comment>();
22
+ }
23
+
24
+ public String getDescription(){
25
+ return description;
26
+ }
27
+
28
+ public Status getStatus(){
29
+ return status;
30
+ }
31
+
32
+ public List<Comment> getComments(){
33
+ return comments;
34
+ }
35
+
36
+ public void addComment(Comment comment){
37
+ this.comments.add(comment);
38
+ }
39
+
40
+ public void setStatus(Status status){
41
+ this.status = status;
42
+ }
43
+ }
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/test/"
4
+ end
5
+
6
+ require 'codemodels/javaparserwrapper'
7
+ require 'test/unit'
8
+ require 'rgen/metamodel_builder'
9
+
10
+ include CodeModels
@@ -0,0 +1,109 @@
1
+ require 'helper'
2
+
3
+ $CLASSPATH << 'test/dummyjavaparser/classes'
4
+
5
+ java_import 'it.codemodels.javaparserwrapper.ast.Project'
6
+ java_import 'it.codemodels.javaparserwrapper.ast.Todo'
7
+ java_import 'java.util.Date'
8
+ java_import 'java.util.GregorianCalendar'
9
+
10
+ class TestParser < Test::Unit::TestCase
11
+
12
+ include CodeModels::JavaParserWrapper
13
+
14
+ module Src
15
+ class A
16
+ attr_accessor :x
17
+ attr_accessor :y
18
+ end
19
+ end
20
+
21
+ module Dest
22
+ class A < RGen::MetamodelBuilder::MMBase
23
+ has_attr 'x',Integer
24
+ has_attr 'y',String
25
+ end
26
+
27
+ class Todo < RGen::MetamodelBuilder::MMBase
28
+ has_attr 'description',String
29
+ has_attr 'status',String
30
+ end
31
+
32
+ class Project < RGen::MetamodelBuilder::MMBase
33
+ has_attr 'name',String
34
+ contains_many_uni 'todos', Todo
35
+ end
36
+
37
+ end
38
+
39
+ class MyJavaObjectsToRgenTransformer < JavaObjectsToRgenTransformer
40
+ # include CodeModels::Javaparserwrapper::BasicTransformationFactory
41
+
42
+ def initialize
43
+ super
44
+ @factory.target_module = TestParser::Dest
45
+ end
46
+
47
+ end
48
+
49
+ def setup
50
+ @poli = Project.new('Poli')
51
+ @original_a = Src::A.new
52
+ @original_a.x = 1
53
+ @original_a.y = '2'
54
+
55
+ d1 = GregorianCalendar.new
56
+
57
+ @fill_report = Todo.new('fill report')
58
+
59
+ @have_a_party = Todo.new('have a party!')
60
+ @have_a_party.status = Todo::Status::WORKING_ON
61
+
62
+ @poli.addTodo(@fill_report)
63
+ @poli.addTodo(@have_a_party)
64
+ end
65
+
66
+ class MyBasicTransformationFactory < CodeModels::JavaParserWrapper::BasicTransformationFactory
67
+ # include CodeModels::Javaparserwrapper::BasicTransformationFactory
68
+
69
+ def initialize
70
+ self.target_module = TestParser::Dest
71
+ end
72
+ end
73
+
74
+ def test_basic_transformation_factory
75
+ tf = MyBasicTransformationFactory.new
76
+ transformed = tf.instantiate_transformed(@original_a)
77
+ assert transformed.is_a?(TestParser::Dest::A)
78
+ end
79
+
80
+ def test_node_to_model_simple_attr
81
+ j2rt = MyJavaObjectsToRgenTransformer.new
82
+ t = j2rt.node_to_model(@poli)
83
+ assert t.is_a?(Dest::Project)
84
+ assert_equal 'Poli',t.name
85
+ end
86
+
87
+ def test_node_to_model_enum_attr
88
+ j2rt = MyJavaObjectsToRgenTransformer.new
89
+
90
+ t = j2rt.node_to_model(@fill_report)
91
+ assert t.is_a?(Dest::Todo)
92
+ assert_equal 'fill report',t.description
93
+ assert_equal 'NOT_STARTED',t.status
94
+
95
+ t = j2rt.node_to_model(@have_a_party)
96
+ assert t.is_a?(Dest::Todo)
97
+ assert_equal 'have a party!',t.description
98
+ assert_equal 'WORKING_ON',t.status
99
+ end
100
+
101
+ def test_node_to_model_containment
102
+ j2rt = MyJavaObjectsToRgenTransformer.new
103
+ t = j2rt.node_to_model(@poli)
104
+ assert_equal 2,@poli.todos.count
105
+ assert_equal 'fill report',@poli.todos[0].description
106
+ assert_equal 'have a party!',@poli.todos[1].description
107
+ end
108
+
109
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ $CLASSPATH << 'test/dummyjavaparser/classes'
4
+
5
+ java_import 'it.codemodels.javaparserwrapper.ast.Project'
6
+ java_import 'it.codemodels.javaparserwrapper.ast.Todo'
7
+ java_import 'it.codemodels.javaparserwrapper.ast.Comment'
8
+ java_import 'it.codemodels.javaparserwrapper.DummyJavaParser'
9
+
10
+ class TestUtils < Test::Unit::TestCase
11
+
12
+ include CodeModels::JavaParserWrapper
13
+
14
+ def setup
15
+ @poli = Project.new('Poli')
16
+ end
17
+
18
+ def test_simple_java_class_name
19
+ assert_equal 'Collection',Utils.simple_java_class_name(::Java::JavaClass.for_name("java.util.Collection"))
20
+ assert_equal 'Collection',Utils.simple_java_class_name(::Java::JavaClass.for_name("java.util.Collection").ruby_class)
21
+ assert_equal 'Project',Utils.simple_java_class_name(Project.java_class)
22
+ assert_equal 'Todo',Utils.simple_java_class_name(Todo)
23
+ assert_equal 'Comment',Utils.simple_java_class_name(Comment)
24
+ assert_equal 'DummyJavaParser',Utils.simple_java_class_name(DummyJavaParser)
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codemodels-javaparserwrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - Federico Tomassetti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codemodels
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ description: Code to wrap parsers written in Java and produce models suitable to be used in CodeModels
84
+ email:
85
+ - f.tomassetti@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - codemodels-javaparserwrapper.gemspec
96
+ - lib/codemodels/javaparserwrapper.rb
97
+ - lib/codemodels/javaparserwrapper/parserwrapper.rb
98
+ - lib/codemodels/javaparserwrapper/utils.rb
99
+ - lib/codemodels/javaparserwrapper/version.rb
100
+ - test/.gitignore
101
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/DummyJavaParser.class
102
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Comment.class
103
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Project.class
104
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Todo$Status.class
105
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Todo.class
106
+ - test/dummyjavaparser/compile_java.sh
107
+ - test/dummyjavaparser/dummyjavaparser.jar
108
+ - test/dummyjavaparser/src/Comment.java
109
+ - test/dummyjavaparser/src/DummyJavaParser.java
110
+ - test/dummyjavaparser/src/Project.java
111
+ - test/dummyjavaparser/src/Todo.java
112
+ - test/helper.rb
113
+ - test/test_parser.rb
114
+ - test/test_utils.rb
115
+ homepage: ''
116
+ licenses:
117
+ - Apache v2
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.0
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Code to wrap parsers written in Java and produce models suitable to be used in CodeModels
139
+ test_files:
140
+ - test/.gitignore
141
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/DummyJavaParser.class
142
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Comment.class
143
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Project.class
144
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Todo$Status.class
145
+ - test/dummyjavaparser/classes/it/codemodels/javaparserwrapper/ast/Todo.class
146
+ - test/dummyjavaparser/compile_java.sh
147
+ - test/dummyjavaparser/dummyjavaparser.jar
148
+ - test/dummyjavaparser/src/Comment.java
149
+ - test/dummyjavaparser/src/DummyJavaParser.java
150
+ - test/dummyjavaparser/src/Project.java
151
+ - test/dummyjavaparser/src/Todo.java
152
+ - test/helper.rb
153
+ - test/test_parser.rb
154
+ - test/test_utils.rb