codemodels 0.2.2-java

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.
@@ -0,0 +1,443 @@
1
+ {
2
+ "type": "http://www.emftext.org/java/members#ClassMethod",
3
+ "id": 774,
4
+ "attr_name": "setCompleted",
5
+ "relcont_layoutInformations": [
6
+
7
+ ],
8
+ "relcont_typeReference": {
9
+ "type": "http://www.emftext.org/java/types#Void",
10
+ "id": 775,
11
+ "relcont_layoutInformations": [
12
+
13
+ ]
14
+ },
15
+ "relcont_arrayDimensionsBefore": [
16
+
17
+ ],
18
+ "relcont_arrayDimensionsAfter": [
19
+
20
+ ],
21
+ "relcont_typeParameters": [
22
+
23
+ ],
24
+ "relcont_parameters": [
25
+ {
26
+ "type": "http://www.emftext.org/java/parameters#OrdinaryParameter",
27
+ "id": 776,
28
+ "attr_name": "completed",
29
+ "relcont_layoutInformations": [
30
+
31
+ ],
32
+ "relcont_typeReference": {
33
+ "type": "http://www.emftext.org/java/types#Boolean",
34
+ "id": 777,
35
+ "relcont_layoutInformations": [
36
+
37
+ ]
38
+ },
39
+ "relcont_arrayDimensionsBefore": [
40
+
41
+ ],
42
+ "relcont_arrayDimensionsAfter": [
43
+
44
+ ],
45
+ "relcont_typeArguments": [
46
+
47
+ ],
48
+ "relcont_annotationsAndModifiers": [
49
+
50
+ ]
51
+ }
52
+ ],
53
+ "relcont_exceptions": [
54
+
55
+ ],
56
+ "relcont_annotationsAndModifiers": [
57
+ {
58
+ "type": "http://www.emftext.org/java/modifiers#Public",
59
+ "id": 778,
60
+ "relcont_layoutInformations": [
61
+
62
+ ]
63
+ }
64
+ ],
65
+ "relcont_statements": [
66
+ {
67
+ "type": "http://www.emftext.org/java/statements#ExpressionStatement",
68
+ "id": 779,
69
+ "relcont_layoutInformations": [
70
+
71
+ ],
72
+ "relcont_expression": {
73
+ "type": "http://www.emftext.org/java/expressions#AssignmentExpression",
74
+ "id": 780,
75
+ "relcont_layoutInformations": [
76
+
77
+ ],
78
+ "relcont_child": {
79
+ "type": "http://www.emftext.org/java/expressions#ConditionalExpression",
80
+ "id": 781,
81
+ "relcont_layoutInformations": [
82
+
83
+ ],
84
+ "relcont_child": {
85
+ "type": "http://www.emftext.org/java/expressions#ConditionalOrExpression",
86
+ "id": 782,
87
+ "relcont_layoutInformations": [
88
+
89
+ ],
90
+ "relcont_children": [
91
+ {
92
+ "type": "http://www.emftext.org/java/expressions#ConditionalAndExpression",
93
+ "id": 783,
94
+ "relcont_layoutInformations": [
95
+
96
+ ],
97
+ "relcont_children": [
98
+ {
99
+ "type": "http://www.emftext.org/java/expressions#InclusiveOrExpression",
100
+ "id": 784,
101
+ "relcont_layoutInformations": [
102
+
103
+ ],
104
+ "relcont_children": [
105
+ {
106
+ "type": "http://www.emftext.org/java/expressions#ExclusiveOrExpression",
107
+ "id": 785,
108
+ "relcont_layoutInformations": [
109
+
110
+ ],
111
+ "relcont_children": [
112
+ {
113
+ "type": "http://www.emftext.org/java/expressions#AndExpression",
114
+ "id": 786,
115
+ "relcont_layoutInformations": [
116
+
117
+ ],
118
+ "relcont_children": [
119
+ {
120
+ "type": "http://www.emftext.org/java/expressions#EqualityExpression",
121
+ "id": 787,
122
+ "relcont_layoutInformations": [
123
+
124
+ ],
125
+ "relcont_equalityOperators": [
126
+
127
+ ],
128
+ "relcont_children": [
129
+ {
130
+ "type": "http://www.emftext.org/java/expressions#InstanceOfExpression",
131
+ "id": 788,
132
+ "relcont_layoutInformations": [
133
+
134
+ ],
135
+ "relcont_arrayDimensionsBefore": [
136
+
137
+ ],
138
+ "relcont_arrayDimensionsAfter": [
139
+
140
+ ],
141
+ "relcont_typeReference": null,
142
+ "relcont_child": {
143
+ "type": "http://www.emftext.org/java/expressions#RelationExpression",
144
+ "id": 789,
145
+ "relcont_layoutInformations": [
146
+
147
+ ],
148
+ "relcont_children": [
149
+ {
150
+ "type": "http://www.emftext.org/java/expressions#ShiftExpression",
151
+ "id": 790,
152
+ "relcont_layoutInformations": [
153
+
154
+ ],
155
+ "relcont_children": [
156
+ {
157
+ "type": "http://www.emftext.org/java/expressions#AdditiveExpression",
158
+ "id": 791,
159
+ "relcont_layoutInformations": [
160
+
161
+ ],
162
+ "relcont_children": [
163
+ {
164
+ "type": "http://www.emftext.org/java/expressions#MultiplicativeExpression",
165
+ "id": 792,
166
+ "relcont_layoutInformations": [
167
+
168
+ ],
169
+ "relcont_children": [
170
+ {
171
+ "type": "http://www.emftext.org/java/expressions#UnaryExpression",
172
+ "id": 793,
173
+ "relcont_layoutInformations": [
174
+
175
+ ],
176
+ "relcont_operators": [
177
+
178
+ ],
179
+ "relcont_child": {
180
+ "type": "http://www.emftext.org/java/expressions#SuffixUnaryModificationExpression",
181
+ "id": 794,
182
+ "relcont_layoutInformations": [
183
+
184
+ ],
185
+ "relcont_child": {
186
+ "type": "http://www.emftext.org/java/references#SelfReference",
187
+ "id": 795,
188
+ "relcont_layoutInformations": [
189
+
190
+ ],
191
+ "relcont_typeArguments": [
192
+
193
+ ],
194
+ "relcont_next": {
195
+ "type": "http://www.emftext.org/java/references#IdentifierReference",
196
+ "id": 796,
197
+ "relcont_layoutInformations": [
198
+
199
+ ],
200
+ "relcont_typeArguments": [
201
+
202
+ ],
203
+ "relcont_next": null,
204
+ "relcont_arraySelectors": [
205
+
206
+ ],
207
+ "relnoncont_target": 79
208
+ },
209
+ "relcont_arraySelectors": [
210
+
211
+ ],
212
+ "relcont_self": {
213
+ "type": "http://www.emftext.org/java/literals#This",
214
+ "id": 797,
215
+ "relcont_layoutInformations": [
216
+
217
+ ]
218
+ }
219
+ },
220
+ "relcont_operator": null
221
+ }
222
+ }
223
+ ],
224
+ "relcont_multiplicativeOperators": [
225
+
226
+ ]
227
+ }
228
+ ],
229
+ "relcont_additiveOperators": [
230
+
231
+ ]
232
+ }
233
+ ],
234
+ "relcont_shiftOperators": [
235
+
236
+ ]
237
+ }
238
+ ],
239
+ "relcont_relationOperators": [
240
+
241
+ ]
242
+ }
243
+ }
244
+ ]
245
+ }
246
+ ]
247
+ }
248
+ ]
249
+ }
250
+ ]
251
+ }
252
+ ]
253
+ }
254
+ ]
255
+ },
256
+ "relcont_expressionIf": null,
257
+ "relcont_expressionElse": null
258
+ },
259
+ "relcont_assignmentOperator": {
260
+ "type": "http://www.emftext.org/java/operators#Assignment",
261
+ "id": 798,
262
+ "relcont_layoutInformations": [
263
+
264
+ ]
265
+ },
266
+ "relcont_value": {
267
+ "type": "http://www.emftext.org/java/expressions#AssignmentExpression",
268
+ "id": 799,
269
+ "relcont_layoutInformations": [
270
+
271
+ ],
272
+ "relcont_child": {
273
+ "type": "http://www.emftext.org/java/expressions#ConditionalExpression",
274
+ "id": 800,
275
+ "relcont_layoutInformations": [
276
+
277
+ ],
278
+ "relcont_child": {
279
+ "type": "http://www.emftext.org/java/expressions#ConditionalOrExpression",
280
+ "id": 801,
281
+ "relcont_layoutInformations": [
282
+
283
+ ],
284
+ "relcont_children": [
285
+ {
286
+ "type": "http://www.emftext.org/java/expressions#ConditionalAndExpression",
287
+ "id": 802,
288
+ "relcont_layoutInformations": [
289
+
290
+ ],
291
+ "relcont_children": [
292
+ {
293
+ "type": "http://www.emftext.org/java/expressions#InclusiveOrExpression",
294
+ "id": 803,
295
+ "relcont_layoutInformations": [
296
+
297
+ ],
298
+ "relcont_children": [
299
+ {
300
+ "type": "http://www.emftext.org/java/expressions#ExclusiveOrExpression",
301
+ "id": 804,
302
+ "relcont_layoutInformations": [
303
+
304
+ ],
305
+ "relcont_children": [
306
+ {
307
+ "type": "http://www.emftext.org/java/expressions#AndExpression",
308
+ "id": 805,
309
+ "relcont_layoutInformations": [
310
+
311
+ ],
312
+ "relcont_children": [
313
+ {
314
+ "type": "http://www.emftext.org/java/expressions#EqualityExpression",
315
+ "id": 806,
316
+ "relcont_layoutInformations": [
317
+
318
+ ],
319
+ "relcont_equalityOperators": [
320
+
321
+ ],
322
+ "relcont_children": [
323
+ {
324
+ "type": "http://www.emftext.org/java/expressions#InstanceOfExpression",
325
+ "id": 807,
326
+ "relcont_layoutInformations": [
327
+
328
+ ],
329
+ "relcont_arrayDimensionsBefore": [
330
+
331
+ ],
332
+ "relcont_arrayDimensionsAfter": [
333
+
334
+ ],
335
+ "relcont_typeReference": null,
336
+ "relcont_child": {
337
+ "type": "http://www.emftext.org/java/expressions#RelationExpression",
338
+ "id": 808,
339
+ "relcont_layoutInformations": [
340
+
341
+ ],
342
+ "relcont_children": [
343
+ {
344
+ "type": "http://www.emftext.org/java/expressions#ShiftExpression",
345
+ "id": 809,
346
+ "relcont_layoutInformations": [
347
+
348
+ ],
349
+ "relcont_children": [
350
+ {
351
+ "type": "http://www.emftext.org/java/expressions#AdditiveExpression",
352
+ "id": 810,
353
+ "relcont_layoutInformations": [
354
+
355
+ ],
356
+ "relcont_children": [
357
+ {
358
+ "type": "http://www.emftext.org/java/expressions#MultiplicativeExpression",
359
+ "id": 811,
360
+ "relcont_layoutInformations": [
361
+
362
+ ],
363
+ "relcont_children": [
364
+ {
365
+ "type": "http://www.emftext.org/java/expressions#UnaryExpression",
366
+ "id": 812,
367
+ "relcont_layoutInformations": [
368
+
369
+ ],
370
+ "relcont_operators": [
371
+
372
+ ],
373
+ "relcont_child": {
374
+ "type": "http://www.emftext.org/java/expressions#SuffixUnaryModificationExpression",
375
+ "id": 813,
376
+ "relcont_layoutInformations": [
377
+
378
+ ],
379
+ "relcont_child": {
380
+ "type": "http://www.emftext.org/java/references#IdentifierReference",
381
+ "id": 814,
382
+ "relcont_layoutInformations": [
383
+
384
+ ],
385
+ "relcont_typeArguments": [
386
+
387
+ ],
388
+ "relcont_next": null,
389
+ "relcont_arraySelectors": [
390
+
391
+ ],
392
+ "relnoncont_target": 776
393
+ },
394
+ "relcont_operator": null
395
+ }
396
+ }
397
+ ],
398
+ "relcont_multiplicativeOperators": [
399
+
400
+ ]
401
+ }
402
+ ],
403
+ "relcont_additiveOperators": [
404
+
405
+ ]
406
+ }
407
+ ],
408
+ "relcont_shiftOperators": [
409
+
410
+ ]
411
+ }
412
+ ],
413
+ "relcont_relationOperators": [
414
+
415
+ ]
416
+ }
417
+ }
418
+ ]
419
+ }
420
+ ]
421
+ }
422
+ ]
423
+ }
424
+ ]
425
+ }
426
+ ]
427
+ }
428
+ ]
429
+ },
430
+ "relcont_expressionIf": null,
431
+ "relcont_expressionElse": null
432
+ },
433
+ "relcont_assignmentOperator": null,
434
+ "relcont_value": null
435
+ }
436
+ }
437
+ }
438
+ ],
439
+ "attr_getter": false,
440
+ "relnoncont_getterFor": null,
441
+ "attr_setter": true,
442
+ "relnoncont_setterFor": 79
443
+ }
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class TestForeignAst < Test::Unit::TestCase
4
+
5
+ include CodeModels
6
+
7
+ class MyLanguageAstNodeA < CodeModelsAstNode
8
+ has_attr 'id', Integer
9
+ end
10
+
11
+ class MyLanguageAstNodeB < CodeModelsAstNode
12
+ has_attr 'id', Integer
13
+ end
14
+
15
+ def setup
16
+ end
17
+
18
+ def test_without_foreign_ast
19
+ assert_equal 0, MyLanguageAstNodeA.ecore.eAllReferences.count, "No Refs expected but they are: #{MyLanguageAstNodeA.ecore.eAllReferences.name}"
20
+ end
21
+
22
+ def test_with_foreign_ast
23
+ CodeModels.enable_foreign_asts(MyLanguageAstNodeB)
24
+ assert_equal 1, MyLanguageAstNodeB.ecore.eAllReferences.count
25
+ assert_equal 'foreign_asts',MyLanguageAstNodeB.ecore.eAllReferences[0].name
26
+ end
27
+
28
+ end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/test/"
4
+ end
5
+
6
+ require 'codemodels'
7
+ require 'test/unit'
8
+ require 'rgen/metamodel_builder'
9
+
10
+ include CodeModels
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ class MyDummyLanguageSpecificLogic
4
+
5
+ def terms_containing_value?(value)
6
+ return true if ["ciao_come_stai","ciao_come"].include?(value)
7
+ return false if ["@@@","123.45"].include?(value)
8
+ raise "Error! invoked with #{value}"
9
+ end
10
+
11
+ def to_words(value)
12
+ case value
13
+ when 'ciao_come_stai'
14
+ ['ciao','come','stai']
15
+ when 'ciao_come'
16
+ ['ciao','come']
17
+ else
18
+ raise "Error! invoked with #{value}"
19
+ end
20
+ end
21
+
22
+ def concat(a,b)
23
+ "#{a}_#{b}"
24
+ end
25
+
26
+ end
27
+
28
+ class MyMetaClass < RGen::MetamodelBuilder::MMBase
29
+ has_many_attr 'a',String
30
+ has_many_attr 'b',Float
31
+ end
32
+
33
+ class TestInfoExtaction < Test::Unit::TestCase
34
+
35
+ include CodeModels::InfoExtraction
36
+
37
+ def test_breaker_void_context
38
+ tb = TermsBreaker.new(MyDummyLanguageSpecificLogic.new)
39
+ assert_equal ["ciao","come","stai"],tb.terms_in_value("ciao_come_stai")
40
+ end
41
+
42
+ def test_breaker_with_frequent_word
43
+ ctx = MyMetaClass.new
44
+ ctx.addA 'ciao_come'
45
+ tb = TermsBreaker.from_context(MyDummyLanguageSpecificLogic.new,ctx)
46
+ assert_equal ["ciao_come","stai"],tb.terms_in_value("ciao_come_stai")
47
+ end
48
+
49
+ def test_empty_values_map
50
+ ctx = MyMetaClass.new
51
+ assert_equal({},ctx.values_map)
52
+ end
53
+
54
+ def test_simple_values_map
55
+ ctx = MyMetaClass.new
56
+ ctx.addA 'ciao_come'
57
+ ctx.addA '@@@'
58
+ ctx.addB 123.45
59
+ assert_equal({'ciao_come'=>1,'@@@'=>1,123.45=>1},ctx.values_map)
60
+ end
61
+
62
+ def test_empty_terms_map
63
+ n = MyMetaClass.new
64
+ lsl = MyDummyLanguageSpecificLogic.new
65
+ tb = TermsBreaker.new lsl
66
+ assert_equal({},n.terms_map(tb))
67
+ end
68
+
69
+ def test_simple_terms_map
70
+ ctx = MyMetaClass.new
71
+ n = MyMetaClass.new
72
+ n.addA 'ciao_come'
73
+ n.addA '@@@'
74
+ n.addB 123.45
75
+ lsl = MyDummyLanguageSpecificLogic.new
76
+ assert_equal({'ciao'=>1,'come'=>1,'@@@'=>1,'123.45'=>1},n.terms_map(lsl,ctx))
77
+ end
78
+
79
+ def test_terms_map_with_composition
80
+ ctx = MyMetaClass.new
81
+ ctx.addA 'ciao_come'
82
+ lsl = MyDummyLanguageSpecificLogic.new
83
+ n = MyMetaClass.new
84
+ n.addA 'ciao_come_stai'
85
+ n.addA '@@@'
86
+ n.addB 123.45
87
+ assert_equal({'ciao_come'=>1,'stai'=>1,'@@@'=>1,'123.45'=>1},n.terms_map(lsl,ctx))
88
+ end
89
+
90
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class TestLanguage < Test::Unit::TestCase
4
+
5
+ include CodeModels
6
+
7
+ class MyLanguage < Language
8
+ def initialize
9
+ super('MyLanguage')
10
+ @extensions << 'my1'
11
+ @extensions << 'my2'
12
+ @parser = 'p'
13
+ end
14
+ end
15
+
16
+ def setup
17
+ CodeModels.register_language(MyLanguage.new)
18
+ end
19
+
20
+ def test_my_language
21
+ assert_equal 1,CodeModels.registered_languages.count
22
+ l = CodeModels.registered_languages[0]
23
+ assert_equal 'MyLanguage',l.name
24
+ assert_equal ['my1','my2'],l.extensions
25
+ assert_equal 'p',l.parser
26
+ end
27
+
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module A
4
+ module B
5
+ module C
6
+ end
7
+ end
8
+ end
9
+
10
+ class TestMonkeyPatching < Test::Unit::TestCase
11
+
12
+ def test_module_simple_name
13
+ assert_equal 'A',A.simple_name
14
+ assert_equal 'B',A::B.simple_name
15
+ assert_equal 'C',A::B::C.simple_name
16
+ end
17
+
18
+ def test_strig_remove_prefix
19
+ assert_equal 'abc','123abc'.remove_prefix('123')
20
+ assert_equal '','123'.remove_prefix('123')
21
+ end
22
+
23
+ def test_strig_remove_postfix
24
+ assert_equal '123','123abc'.remove_postfix('abc')
25
+ assert_equal '','123'.remove_postfix('123')
26
+ end
27
+
28
+ def test_proper_capitalize
29
+ assert_equal 'CiaoMondo','ciaoMondo'.proper_capitalize
30
+ assert_equal 'CiaoMondo','CiaoMondo'.proper_capitalize
31
+ end
32
+
33
+ def test_proper_uncapitalize
34
+ assert_equal 'ciaoMondo','CiaoMondo'.proper_uncapitalize
35
+ assert_equal 'ciaoMondo','ciaoMondo'.proper_uncapitalize
36
+ end
37
+
38
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class TestQuerySerialized < Test::Unit::TestCase
4
+
5
+ def test_rel_conts_on_complex_node
6
+ set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
7
+
8
+ assert_equal [
9
+ 'relcont_layoutInformations',
10
+ 'relcont_typeReference',
11
+ 'relcont_arrayDimensionsBefore',
12
+ 'relcont_arrayDimensionsAfter',
13
+ 'relcont_typeParameters',
14
+ 'relcont_parameters',
15
+ 'relcont_exceptions',
16
+ 'relcont_annotationsAndModifiers',
17
+ 'relcont_statements'],
18
+ CodeModels::QuerySerialized.rel_conts(set_completed)
19
+ end
20
+
21
+ def test_rel_nonconts_on_complex_node
22
+ set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
23
+
24
+ assert_equal [
25
+ 'relnoncont_getterFor',
26
+ 'relnoncont_setterFor'],
27
+ CodeModels::QuerySerialized.rel_non_conts(set_completed)
28
+ end
29
+
30
+ def test_attrs_on_complex_node
31
+ set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
32
+
33
+ assert_equal [
34
+ 'attr_name',
35
+ 'attr_getter',
36
+ 'attr_setter'],
37
+ CodeModels::QuerySerialized.attrs(set_completed)
38
+ end
39
+
40
+ end