rgen 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/CHANGELOG +7 -0
  2. data/lib/rgen/metamodel_builder.rb +5 -4
  3. data/lib/rgen/metamodel_builder.rb.bak +196 -0
  4. data/lib/rgen/metamodel_builder/builder_extensions.rb +51 -38
  5. data/lib/rgen/metamodel_builder/builder_extensions.rb.bak +437 -0
  6. data/lib/rgen/metamodel_builder/builder_runtime.rb +2 -20
  7. data/lib/rgen/metamodel_builder/builder_runtime.rb.bak +73 -0
  8. data/lib/rgen/name_helper.rb.bak +37 -0
  9. data/lib/rgen/template_language.rb +8 -0
  10. data/lib/rgen/template_language.rb.bak +289 -0
  11. data/lib/rgen/template_language/directory_template_container.rb +11 -0
  12. data/lib/rgen/template_language/directory_template_container.rb.bak +69 -0
  13. data/lib/rgen/template_language/output_handler.rb +3 -2
  14. data/lib/rgen/template_language/output_handler.rb.bak +88 -0
  15. data/lib/rgen/template_language/template_container.rb +5 -4
  16. data/lib/rgen/template_language/template_container.rb.bak +196 -0
  17. data/lib/rgen/transformer.rb.bak +381 -0
  18. data/test/environment_test.rb.bak +52 -0
  19. data/test/metamodel_builder_test.rb +6 -0
  20. data/test/metamodel_builder_test.rb.bak +443 -0
  21. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +34 -32
  22. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +58 -58
  23. data/test/output_handler_test.rb +8 -0
  24. data/test/output_handler_test.rb.bak +50 -0
  25. data/test/template_language_test.rb +23 -0
  26. data/test/template_language_test.rb.bak +72 -0
  27. data/test/template_language_test/indentStringTestDefaultIndent.out +1 -0
  28. data/test/template_language_test/indentStringTestTabIndent.out +1 -0
  29. data/test/template_language_test/templates/indent_string_test.tpl +12 -0
  30. data/test/template_language_test/templates/null_context_test.tpl +12 -0
  31. data/test/transformer_test.rb.bak +223 -0
  32. metadata +65 -48
  33. data/lib/rgen/environment.rb.bak +0 -42
@@ -0,0 +1,223 @@
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
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rgen
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.2
7
- date: 2008-03-02 00:00:00 +01:00
6
+ version: 0.4.3
7
+ date: 2008-08-12 00:00:00 +02:00
8
8
  summary: Ruby Modelling and Generator Framework
9
9
  require_paths:
10
10
  - lib
@@ -30,89 +30,109 @@ authors:
30
30
  - Martin Thiede
31
31
  files:
32
32
  - lib/instantiators
33
- - lib/instantiators/ea_instantiator.rb
34
33
  - lib/metamodels
34
+ - lib/mmgen
35
+ - lib/rgen
36
+ - lib/transformers
37
+ - lib/instantiators/ea_instantiator.rb
35
38
  - lib/metamodels/uml13_metamodel.rb
36
39
  - lib/metamodels/uml13_metamodel_ext.rb
37
- - lib/mmgen
38
40
  - lib/mmgen/metamodel_generator.rb
39
41
  - lib/mmgen/mmgen.rb
40
42
  - lib/mmgen/mm_ext
41
- - lib/mmgen/mm_ext/ecore_ext.rb
42
43
  - lib/mmgen/templates
44
+ - lib/mmgen/mm_ext/ecore_ext.rb
43
45
  - lib/mmgen/templates/annotations.tpl
44
46
  - lib/mmgen/templates/metamodel_generator.tpl
45
- - lib/rgen
46
47
  - lib/rgen/array_extensions.rb
47
48
  - lib/rgen/auto_class_creator.rb
48
49
  - lib/rgen/ecore
50
+ - lib/rgen/environment.rb
51
+ - lib/rgen/instantiator
52
+ - lib/rgen/metamodel_builder
53
+ - lib/rgen/metamodel_builder.rb
54
+ - lib/rgen/metamodel_builder.rb.bak
55
+ - lib/rgen/model_comparator.rb
56
+ - lib/rgen/model_dumper.rb
57
+ - lib/rgen/name_helper.rb
58
+ - lib/rgen/name_helper.rb.bak
59
+ - lib/rgen/serializer
60
+ - lib/rgen/template_language
61
+ - lib/rgen/template_language.rb
62
+ - lib/rgen/template_language.rb.bak
63
+ - lib/rgen/transformer.rb
64
+ - lib/rgen/transformer.rb.bak
49
65
  - lib/rgen/ecore/ecore.rb
50
66
  - lib/rgen/ecore/ecore_instantiator.rb
51
67
  - lib/rgen/ecore/ecore_transformer.rb
52
- - lib/rgen/environment.rb
53
- - lib/rgen/environment.rb.bak
54
- - lib/rgen/instantiator
55
68
  - lib/rgen/instantiator/abstract_instantiator.rb
56
69
  - lib/rgen/instantiator/abstract_xml_instantiator.rb
57
70
  - lib/rgen/instantiator/default_xml_instantiator.rb
58
71
  - lib/rgen/instantiator/ecore_xml_instantiator.rb
59
72
  - lib/rgen/instantiator/nodebased_xml_instantiator.rb
60
73
  - lib/rgen/instantiator/xmi11_instantiator.rb
61
- - lib/rgen/metamodel_builder
62
74
  - lib/rgen/metamodel_builder/builder_extensions.rb
75
+ - lib/rgen/metamodel_builder/builder_extensions.rb.bak
63
76
  - lib/rgen/metamodel_builder/builder_runtime.rb
77
+ - lib/rgen/metamodel_builder/builder_runtime.rb.bak
64
78
  - lib/rgen/metamodel_builder/data_types.rb
65
79
  - lib/rgen/metamodel_builder/intermediate
66
- - lib/rgen/metamodel_builder/intermediate/annotation.rb
67
80
  - lib/rgen/metamodel_builder/metamodel_description.rb
68
81
  - lib/rgen/metamodel_builder/mm_multiple.rb
69
82
  - lib/rgen/metamodel_builder/module_extension.rb
70
- - lib/rgen/metamodel_builder.rb
71
- - lib/rgen/model_comparator.rb
72
- - lib/rgen/model_dumper.rb
73
- - lib/rgen/name_helper.rb
74
- - lib/rgen/serializer
83
+ - lib/rgen/metamodel_builder/intermediate/annotation.rb
75
84
  - lib/rgen/serializer/xmi20_serializer.rb
76
85
  - lib/rgen/serializer/xml_serializer.rb
77
- - lib/rgen/template_language
78
86
  - lib/rgen/template_language/directory_template_container.rb
87
+ - lib/rgen/template_language/directory_template_container.rb.bak
79
88
  - lib/rgen/template_language/output_handler.rb
89
+ - lib/rgen/template_language/output_handler.rb.bak
80
90
  - lib/rgen/template_language/template_container.rb
91
+ - lib/rgen/template_language/template_container.rb.bak
81
92
  - lib/rgen/template_language/template_helper.rb
82
- - lib/rgen/template_language.rb
83
- - lib/rgen/transformer.rb
84
- - lib/transformers
85
93
  - lib/transformers/uml13_to_ecore.rb
86
94
  - test/array_extensions_test.rb
87
95
  - test/ea_instantiator_test.rb
88
96
  - test/ecore_self_test.rb
89
97
  - test/environment_test.rb
98
+ - test/environment_test.rb.bak
90
99
  - test/metamodel_builder_test.rb
100
+ - test/metamodel_builder_test.rb.bak
91
101
  - test/metamodel_roundtrip_test
102
+ - test/metamodel_roundtrip_test.rb
103
+ - test/output_handler_test.rb
104
+ - test/output_handler_test.rb.bak
105
+ - test/rgen_test.rb
106
+ - test/template_language_test
107
+ - test/template_language_test.rb
108
+ - test/template_language_test.rb.bak
109
+ - test/testmodel
110
+ - test/transformer_test.rb
111
+ - test/transformer_test.rb.bak
112
+ - test/xml_instantiator_test
113
+ - test/xml_instantiator_test.rb
92
114
  - test/metamodel_roundtrip_test/houseMetamodel.ecore
93
115
  - test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb
94
116
  - test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore
95
117
  - test/metamodel_roundtrip_test/TestModel.rb
96
118
  - test/metamodel_roundtrip_test/TestModel_Regenerated.rb
97
- - test/metamodel_roundtrip_test.rb
98
- - test/output_handler_test.rb
99
- - test/rgen_test.rb
100
- - test/template_language_test
101
119
  - test/template_language_test/expected_result.txt
120
+ - test/template_language_test/indentStringTestDefaultIndent.out
121
+ - test/template_language_test/indentStringTestTabIndent.out
102
122
  - test/template_language_test/templates
123
+ - test/template_language_test/testout.txt
103
124
  - test/template_language_test/templates/code
104
- - test/template_language_test/templates/code/array.tpl
105
125
  - test/template_language_test/templates/content
126
+ - test/template_language_test/templates/indent_string_test.tpl
127
+ - test/template_language_test/templates/index
128
+ - test/template_language_test/templates/null_context_test.tpl
129
+ - test/template_language_test/templates/root.tpl
130
+ - test/template_language_test/templates/code/array.tpl
106
131
  - test/template_language_test/templates/content/author.tpl
107
132
  - test/template_language_test/templates/content/chapter.tpl
108
- - test/template_language_test/templates/index
109
133
  - test/template_language_test/templates/index/c
110
- - test/template_language_test/templates/index/c/cmod.tpl
111
134
  - test/template_language_test/templates/index/chapter.tpl
112
- - test/template_language_test/templates/root.tpl
113
- - test/template_language_test/testout.txt
114
- - test/template_language_test.rb
115
- - test/testmodel
135
+ - test/template_language_test/templates/index/c/cmod.tpl
116
136
  - test/testmodel/class_model_checker.rb
117
137
  - test/testmodel/ea_testmodel.eap
118
138
  - test/testmodel/ea_testmodel.xml
@@ -120,35 +140,38 @@ files:
120
140
  - test/testmodel/ecore_model_checker.rb
121
141
  - test/testmodel/manual_testmodel.xml
122
142
  - test/testmodel/object_model_checker.rb
123
- - test/transformer_test.rb
124
- - test/xml_instantiator_test
125
143
  - test/xml_instantiator_test/simple_ecore_model_checker.rb
126
144
  - test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb
127
145
  - test/xml_instantiator_test/simple_xmi_metamodel.rb
128
146
  - test/xml_instantiator_test/simple_xmi_to_ecore.rb
129
- - test/xml_instantiator_test.rb
130
147
  - redist/xmlscan
131
148
  - redist/xmlscan/ChangeLog
132
149
  - redist/xmlscan/doc
150
+ - redist/xmlscan/install.rb
151
+ - redist/xmlscan/lib
152
+ - redist/xmlscan/memo
153
+ - redist/xmlscan/README
154
+ - redist/xmlscan/samples
155
+ - redist/xmlscan/test.rb
156
+ - redist/xmlscan/tests
157
+ - redist/xmlscan/THANKS
133
158
  - redist/xmlscan/doc/changes.html
134
159
  - redist/xmlscan/doc/changes.rd
135
160
  - redist/xmlscan/doc/en
161
+ - redist/xmlscan/doc/ja
162
+ - redist/xmlscan/doc/src
136
163
  - redist/xmlscan/doc/en/conformance.html
137
164
  - redist/xmlscan/doc/en/conformance.rd
138
165
  - redist/xmlscan/doc/en/manual.html
139
166
  - redist/xmlscan/doc/en/manual.rd
140
- - redist/xmlscan/doc/ja
141
167
  - redist/xmlscan/doc/ja/conformance.ja.html
142
168
  - redist/xmlscan/doc/ja/conformance.ja.rd
143
169
  - redist/xmlscan/doc/ja/manual.ja.html
144
170
  - redist/xmlscan/doc/ja/manual.ja.rd
145
- - redist/xmlscan/doc/src
146
171
  - redist/xmlscan/doc/src/conformance.rd.src
147
172
  - redist/xmlscan/doc/src/langsplit.rb
148
173
  - redist/xmlscan/doc/src/Makefile
149
174
  - redist/xmlscan/doc/src/manual.rd.src
150
- - redist/xmlscan/install.rb
151
- - redist/xmlscan/lib
152
175
  - redist/xmlscan/lib/xmlscan
153
176
  - redist/xmlscan/lib/xmlscan/encoding.rb
154
177
  - redist/xmlscan/lib/xmlscan/htmlscan.rb
@@ -158,17 +181,17 @@ files:
158
181
  - redist/xmlscan/lib/xmlscan/version.rb
159
182
  - redist/xmlscan/lib/xmlscan/visitor.rb
160
183
  - redist/xmlscan/lib/xmlscan/xmlchar.rb
161
- - redist/xmlscan/memo
162
184
  - redist/xmlscan/memo/CONFORMANCE
163
185
  - redist/xmlscan/memo/contentspec.ry
164
186
  - redist/xmlscan/memo/PRODUCTIONS
165
- - redist/xmlscan/README
166
- - redist/xmlscan/samples
167
187
  - redist/xmlscan/samples/chibixml.rb
168
188
  - redist/xmlscan/samples/getxmlchar.rb
169
189
  - redist/xmlscan/samples/rexml.rb
170
190
  - redist/xmlscan/samples/xmlbench
191
+ - redist/xmlscan/samples/xmlbench.rb
192
+ - redist/xmlscan/samples/xmlconftest.rb
171
193
  - redist/xmlscan/samples/xmlbench/parser
194
+ - redist/xmlscan/samples/xmlbench/xmlbench-lib.rb
172
195
  - redist/xmlscan/samples/xmlbench/parser/chibixml.rb
173
196
  - redist/xmlscan/samples/xmlbench/parser/nqxml.rb
174
197
  - redist/xmlscan/samples/xmlbench/parser/rexml.rb
@@ -177,11 +200,6 @@ files:
177
200
  - redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb
178
201
  - redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb
179
202
  - redist/xmlscan/samples/xmlbench/parser/xmlscan.rb
180
- - redist/xmlscan/samples/xmlbench/xmlbench-lib.rb
181
- - redist/xmlscan/samples/xmlbench.rb
182
- - redist/xmlscan/samples/xmlconftest.rb
183
- - redist/xmlscan/test.rb
184
- - redist/xmlscan/tests
185
203
  - redist/xmlscan/tests/deftestcase.rb
186
204
  - redist/xmlscan/tests/runtest.rb
187
205
  - redist/xmlscan/tests/testall.rb
@@ -192,7 +210,6 @@ files:
192
210
  - redist/xmlscan/tests/testscanner.rb
193
211
  - redist/xmlscan/tests/testxmlchar.rb
194
212
  - redist/xmlscan/tests/visitor.rb
195
- - redist/xmlscan/THANKS
196
213
  - README
197
214
  - CHANGELOG
198
215
  - MIT-LICENSE