rgen 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/CHANGELOG +6 -0
  2. data/lib/mmgen/metamodel_generator.rb +2 -1
  3. data/lib/mmgen/mm_ext/{ecore_ext.rb → ecore_mmgen_ext.rb} +3 -7
  4. data/lib/mmgen/templates/metamodel_generator.tpl +10 -8
  5. data/lib/rgen/ecore/ecore_ext.rb +69 -0
  6. data/lib/rgen/ecore/ecore_transformer.rb +1 -1
  7. data/lib/rgen/metamodel_builder/builder_extensions.rb +10 -2
  8. data/lib/rgen/serializer/xmi11_serializer.rb +101 -0
  9. data/lib/rgen/serializer/xmi20_serializer.rb +7 -7
  10. data/lib/rgen/serializer/xml_serializer.rb +47 -14
  11. data/test/ea_serializer_test.rb +29 -0
  12. data/test/ea_serializer_test/ea_testmodel_regenerated.xml +821 -0
  13. data/test/metamodel_roundtrip_test.rb +1 -2
  14. data/test/metamodel_roundtrip_test/TestModel.rb +1 -0
  15. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +34 -35
  16. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +128 -236
  17. data/test/rgen_test.rb +1 -0
  18. metadata +93 -95
  19. data/lib/rgen/metamodel_builder.rb.bak +0 -196
  20. data/lib/rgen/metamodel_builder/builder_extensions.rb.bak +0 -437
  21. data/lib/rgen/metamodel_builder/builder_runtime.rb.bak +0 -73
  22. data/lib/rgen/name_helper.rb.bak +0 -37
  23. data/lib/rgen/template_language.rb.bak +0 -289
  24. data/lib/rgen/template_language/directory_template_container.rb.bak +0 -69
  25. data/lib/rgen/template_language/output_handler.rb.bak +0 -88
  26. data/lib/rgen/template_language/template_container.rb.bak +0 -196
  27. data/lib/rgen/transformer.rb.bak +0 -381
  28. data/test/environment_test.rb.bak +0 -52
  29. data/test/metamodel_builder_test.rb.bak +0 -443
  30. data/test/output_handler_test.rb.bak +0 -50
  31. data/test/template_language_test.rb.bak +0 -72
  32. data/test/transformer_test.rb.bak +0 -223
@@ -1,50 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- require 'test/unit'
4
- require 'rgen/template_language/output_handler'
5
-
6
- class MetamodelBuilderTest < Test::Unit::TestCase
7
- def test_direct_nl
8
- h = RGen::TemplateLanguage::OutputHandler.new
9
- h.mode = :direct
10
- h << "Test"
11
- h.ignoreNextNL
12
- h << "\nContent"
13
- assert_equal "TestContent", h.to_s
14
- end
15
- def test_direct_ws
16
- h = RGen::TemplateLanguage::OutputHandler.new
17
- h.mode = :direct
18
- h << "Test"
19
- h.ignoreNextWS
20
- h << " \n Content"
21
- assert_equal "TestContent", h.to_s
22
- end
23
- def test_explicit_indent
24
- h = RGen::TemplateLanguage::OutputHandler.new
25
- h.mode = :explicit
26
- h.indent = 1
27
- h << "Start"
28
- h << " \n "
29
- h << "Test"
30
- h << " \n \n Content"
31
- assert_equal " Start\n Test\n Content", h.to_s
32
- end
33
- def test_explicit_endswithws
34
- h = RGen::TemplateLanguage::OutputHandler.new
35
- h.mode = :explicit
36
- h.indent = 1
37
- h << "Start \n\n"
38
- assert_equal " Start\n", h.to_s
39
- end
40
- def test_performance
41
- h = RGen::TemplateLanguage::OutputHandler.new
42
- h.mode = :explicit
43
- h.indent = 1
44
- line = (1..50).collect{|w| "someword"}.join(" ")+"\n"
45
- # repeat more often to make performance differences visible
46
- 20.times do
47
- h << line
48
- end
49
- end
50
- end
@@ -1,72 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- require 'test/unit'
4
- require 'rgen/template_language'
5
- require 'rgen/metamodel_builder'
6
-
7
- class TemplateContainerTest < Test::Unit::TestCase
8
-
9
- TEMPLATES_DIR = File.dirname(__FILE__)+"/template_language_test/templates"
10
- OUTPUT_DIR = File.dirname(__FILE__)+"/template_language_test"
11
-
12
- module MyMM
13
-
14
- class Chapter
15
- attr_reader :title
16
- def initialize(title)
17
- @title = title
18
- end
19
- end
20
-
21
- class Document
22
- attr_reader :title, :authors, :chapters
23
- attr_accessor :sampleArray
24
- def initialize(title)
25
- @title = title
26
- @chapters = []
27
- @authors = []
28
- end
29
- end
30
-
31
- class Author
32
- attr_reader :name, :email
33
- def initialize(name, email)
34
- @name, @email = name, email
35
- end
36
- end
37
-
38
- end
39
-
40
- module CCodeMM
41
- class CArray < RGen::MetamodelBuilder::MMBase
42
- has_attr 'name'
43
- has_attr 'size', Integer
44
- has_attr 'type'
45
- end
46
- class PrimitiveInitValue < RGen::MetamodelBuilder::MMBase
47
- has_attr 'value', Integer
48
- end
49
- CArray.has_many 'initvalue', PrimitiveInitValue
50
- end
51
-
52
- TEST_MODEL = MyMM::Document.new("SomeDocument")
53
- TEST_MODEL.authors << MyMM::Author.new("Martin", "martin@somewhe.re")
54
- TEST_MODEL.authors << MyMM::Author.new("Otherguy", "other@somewhereel.se")
55
- TEST_MODEL.chapters << MyMM::Chapter.new("Intro")
56
- TEST_MODEL.chapters << MyMM::Chapter.new("MainPart")
57
- TEST_MODEL.chapters << MyMM::Chapter.new("Summary")
58
- TEST_MODEL.sampleArray = CCodeMM::CArray.new(:name => "myArray", :type => "int", :size => 5,
59
- :initvalue => (1..5).collect { |v| CCodeMM::PrimitiveInitValue.new(:value => v) })
60
-
61
- def test_with_model
62
- tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new([MyMM, CCodeMM], OUTPUT_DIR)
63
- tc.load(TEMPLATES_DIR)
64
- File.delete(OUTPUT_DIR+"/testout.txt") if File.exists? OUTPUT_DIR+"/testout.txt"
65
- tc.expand('root::Root', :for => TEST_MODEL, :indent => 1)
66
- result = expected = ""
67
- File.open(OUTPUT_DIR+"/testout.txt") {|f| result = f.read}
68
- File.open(OUTPUT_DIR+"/expected_result.txt") {|f| expected = f.read}
69
- assert_equal expected, result
70
- end
71
-
72
- end
@@ -1,223 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
- $:.unshift File.join(File.dirname(__FILE__),"..","test")
3
-
4
- require 'test/unit'
5
- require 'rgen/transformer'
6
- require 'rgen/environment'
7
- require 'rgen/model_comparator'
8
- require 'metamodels/uml13_metamodel'
9
- require 'instantiators/ea_instantiator'
10
- require 'testmodel/class_model_checker'
11
-
12
- class TransformerTest < Test::Unit::TestCase
13
-
14
- class ModelIn
15
- attr_accessor :name
16
- end
17
-
18
- class ModelInSub < ModelIn
19
- end
20
-
21
- class ModelAIn
22
- attr_accessor :name
23
- attr_accessor :modelB
24
- end
25
-
26
- class ModelBIn
27
- attr_accessor :name
28
- attr_accessor :modelA
29
- end
30
-
31
- class ModelCIn
32
- attr_accessor :number
33
- end
34
-
35
- class ModelOut
36
- attr_accessor :name
37
- end
38
-
39
- class ModelAOut
40
- attr_accessor :name
41
- attr_accessor :modelB
42
- end
43
-
44
- class ModelBOut
45
- attr_accessor :name
46
- attr_accessor :modelA
47
- end
48
-
49
- class ModelCOut
50
- attr_accessor :number
51
- end
52
-
53
- class MyTransformer < RGen::Transformer
54
- attr_reader :modelInTrans_count
55
- attr_reader :modelAInTrans_count
56
- attr_reader :modelBInTrans_count
57
-
58
- transform ModelIn, :to => ModelOut do
59
- # aribitrary ruby code may be placed before the hash creating the output element
60
- @modelInTrans_count ||= 0; @modelInTrans_count += 1
61
- { :name => name }
62
- end
63
-
64
- transform ModelAIn, :to => ModelAOut do
65
- @modelAInTrans_count ||= 0; @modelAInTrans_count += 1
66
- { :name => name, :modelB => trans(modelB) }
67
- end
68
-
69
- transform ModelBIn, :to => ModelBOut do
70
- @modelBInTrans_count ||= 0; @modelBInTrans_count += 1
71
- { :name => name, :modelA => trans(modelA) }
72
- end
73
-
74
- transform ModelCIn, :to => ModelCOut, :if => :largeNumber do
75
- # a method can be called anywhere in a transformer block
76
- { :number => duplicateNumber }
77
- end
78
-
79
- transform ModelCIn, :to => ModelCOut, :if => :smallNumber do
80
- { :number => number / 2 }
81
- end
82
-
83
- method :largeNumber do
84
- number > 1000
85
- end
86
-
87
- method :smallNumber do
88
- number < 500
89
- end
90
-
91
- method :duplicateNumber do
92
- number * 2;
93
- end
94
-
95
- end
96
-
97
- class MyTransformer2 < RGen::Transformer
98
- # check that subclasses are independent (i.e. do not share the rules)
99
- transform ModelIn, :to => ModelOut do
100
- { :name => name }
101
- end
102
- end
103
-
104
- def test_transformer
105
- from = ModelIn.new
106
- from.name = "TestName"
107
- env_out = RGen::Environment.new
108
- t = MyTransformer.new(:env_in, env_out)
109
- assert t.trans(from).is_a?(ModelOut)
110
- assert_equal "TestName", t.trans(from).name
111
- assert_equal 1, env_out.elements.size
112
- assert_equal env_out.elements.first, t.trans(from)
113
- assert_equal 1, t.modelInTrans_count
114
- end
115
-
116
- def test_transformer_subclass
117
- from = ModelInSub.new
118
- from.name = "TestName"
119
- t = MyTransformer.new
120
- assert t.trans(from).is_a?(ModelOut)
121
- assert_equal "TestName", t.trans(from).name
122
- assert_equal 1, t.modelInTrans_count
123
- end
124
-
125
- def test_transformer_array
126
- froms = [ModelIn.new, ModelIn.new]
127
- froms[0].name = "M1"
128
- froms[1].name = "M2"
129
- env_out = RGen::Environment.new
130
- t = MyTransformer.new(:env_in, env_out)
131
- assert t.trans(froms).is_a?(Array)
132
- assert t.trans(froms)[0].is_a?(ModelOut)
133
- assert_equal "M1", t.trans(froms)[0].name
134
- assert t.trans(froms)[1].is_a?(ModelOut)
135
- assert_equal "M2", t.trans(froms)[1].name
136
- assert_equal 2, env_out.elements.size
137
- assert (t.trans(froms)-env_out.elements).empty?
138
- assert_equal 2, t.modelInTrans_count
139
- end
140
-
141
- def test_transformer_cyclic
142
- # setup a cyclic dependency between fromA and fromB
143
- fromA = ModelAIn.new
144
- fromB = ModelBIn.new
145
- fromA.modelB = fromB
146
- fromA.name = "ModelA"
147
- fromB.modelA = fromA
148
- fromB.name = "ModelB"
149
- env_out = RGen::Environment.new
150
- t = MyTransformer.new(:env_in, env_out)
151
- # check that trans resolves the cycle correctly (no endless loop)
152
- # both elements, fromA and fromB will be transformed with the transformation
153
- # of the first element, either fromA or fromB
154
- assert t.trans(fromA).is_a?(ModelAOut)
155
- assert_equal "ModelA", t.trans(fromA).name
156
- assert t.trans(fromA).modelB.is_a?(ModelBOut)
157
- assert_equal "ModelB", t.trans(fromA).modelB.name
158
- assert_equal t.trans(fromA), t.trans(fromA).modelB.modelA
159
- assert_equal t.trans(fromB), t.trans(fromA).modelB
160
- assert_equal 2, env_out.elements.size
161
- assert (env_out.elements - [t.trans(fromA), t.trans(fromB)]).empty?
162
- assert_equal 1, t.modelAInTrans_count
163
- assert_equal 1, t.modelBInTrans_count
164
- end
165
-
166
- def test_transformer_conditional
167
- froms = [ModelCIn.new, ModelCIn.new, ModelCIn.new]
168
- froms[0].number = 100
169
- froms[1].number = 1000
170
- froms[2].number = 2000
171
-
172
- env_out = RGen::Environment.new
173
- t = MyTransformer.new(:env_in, env_out)
174
-
175
- assert t.trans(froms).is_a?(Array)
176
- assert_equal 2, t.trans(froms).size
177
-
178
- # this one matched the smallNumber rule
179
- assert t.trans(froms[0]).is_a?(ModelCOut)
180
- assert_equal 50, t.trans(froms[0]).number
181
-
182
- # this one did not match any rule
183
- assert t.trans(froms[1]).nil?
184
-
185
- # this one matched the largeNumber rule
186
- assert t.trans(froms[2]).is_a?(ModelCOut)
187
- assert_equal 4000, t.trans(froms[2]).number
188
-
189
- # elements in environment are the same as the ones returned
190
- assert_equal 2, env_out.elements.size
191
- assert (t.trans(froms)-env_out.elements).empty?
192
- end
193
-
194
- class CopyTransformer < RGen::Transformer
195
- include UML13
196
- def transform
197
- trans(:class => UML13::Package)
198
- end
199
- UML13.ecore.eClassifiers.each do |c|
200
- copy c.instanceClass
201
- end
202
- end
203
-
204
- MODEL_DIR = File.join(File.dirname(__FILE__),"testmodel")
205
-
206
- include Testmodel::ClassModelChecker
207
- include RGen::ModelComparator
208
-
209
- def test_copyTransformer
210
- envIn = RGen::Environment.new
211
- envOut = RGen::Environment.new
212
- File.open(MODEL_DIR+"/ea_testmodel.xml") { |f|
213
- inst = EAInstantiator.new(envIn, EAInstantiator::ERROR)
214
- inst.instantiate(f.read)
215
- }
216
- CopyTransformer.new(envIn, envOut).transform
217
- checkClassModel(envOut)
218
- assert modelEqual?(
219
- envIn.find(:class => UML13::Model).first,
220
- envOut.find(:class => UML13::Model).first)
221
- end
222
-
223
- end