rgen 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +20 -1
  2. data/MIT-LICENSE +1 -1
  3. data/README +12 -9
  4. data/lib/instantiators/ea_instantiator.rb +36 -0
  5. data/lib/metamodels/uml13_metamodel.rb +559 -0
  6. data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
  7. data/lib/mmgen/metamodel_generator.rb +5 -5
  8. data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
  9. data/lib/mmgen/mmgen.rb +6 -4
  10. data/lib/mmgen/templates/annotations.tpl +37 -0
  11. data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
  12. data/lib/rgen/ecore/ecore.rb +190 -0
  13. data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
  14. data/lib/rgen/ecore/ecore_transformer.rb +85 -0
  15. data/lib/rgen/environment.rb +9 -24
  16. data/lib/rgen/find_helper.rb +68 -0
  17. data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
  18. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
  19. data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
  20. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
  21. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
  22. data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
  23. data/lib/rgen/metamodel_builder.rb +103 -9
  24. data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
  27. data/lib/rgen/metamodel_builder/data_types.rb +67 -0
  28. data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
  29. data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
  30. data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
  31. data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
  32. data/lib/rgen/model_comparator.rb +56 -0
  33. data/lib/rgen/model_dumper.rb +5 -5
  34. data/lib/rgen/name_helper.rb +17 -1
  35. data/lib/rgen/template_language.rb +148 -28
  36. data/lib/rgen/template_language/directory_template_container.rb +56 -38
  37. data/lib/rgen/template_language/output_handler.rb +93 -77
  38. data/lib/rgen/template_language/template_container.rb +186 -143
  39. data/lib/rgen/transformer.rb +19 -14
  40. data/lib/transformers/uml13_to_ecore.rb +75 -0
  41. data/redist/xmlscan/ChangeLog +1301 -0
  42. data/redist/xmlscan/README +34 -0
  43. data/redist/xmlscan/THANKS +11 -0
  44. data/redist/xmlscan/doc/changes.html +74 -0
  45. data/redist/xmlscan/doc/changes.rd +80 -0
  46. data/redist/xmlscan/doc/en/conformance.html +136 -0
  47. data/redist/xmlscan/doc/en/conformance.rd +152 -0
  48. data/redist/xmlscan/doc/en/manual.html +356 -0
  49. data/redist/xmlscan/doc/en/manual.rd +402 -0
  50. data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
  51. data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
  52. data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
  53. data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
  54. data/redist/xmlscan/doc/src/Makefile +41 -0
  55. data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
  56. data/redist/xmlscan/doc/src/langsplit.rb +110 -0
  57. data/redist/xmlscan/doc/src/manual.rd.src +614 -0
  58. data/redist/xmlscan/install.rb +41 -0
  59. data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
  60. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
  61. data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
  62. data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
  63. data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
  64. data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
  65. data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
  66. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
  67. data/redist/xmlscan/memo/CONFORMANCE +1249 -0
  68. data/redist/xmlscan/memo/PRODUCTIONS +195 -0
  69. data/redist/xmlscan/memo/contentspec.ry +335 -0
  70. data/redist/xmlscan/samples/chibixml.rb +105 -0
  71. data/redist/xmlscan/samples/getxmlchar.rb +122 -0
  72. data/redist/xmlscan/samples/rexml.rb +159 -0
  73. data/redist/xmlscan/samples/xmlbench.rb +88 -0
  74. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
  75. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
  76. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
  77. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
  78. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
  79. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
  80. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
  81. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
  82. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
  83. data/redist/xmlscan/samples/xmlconftest.rb +200 -0
  84. data/redist/xmlscan/test.rb +7 -0
  85. data/redist/xmlscan/tests/deftestcase.rb +73 -0
  86. data/redist/xmlscan/tests/runtest.rb +47 -0
  87. data/redist/xmlscan/tests/testall.rb +14 -0
  88. data/redist/xmlscan/tests/testencoding.rb +438 -0
  89. data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
  90. data/redist/xmlscan/tests/testnamespace.rb +457 -0
  91. data/redist/xmlscan/tests/testparser.rb +591 -0
  92. data/redist/xmlscan/tests/testscanner.rb +1749 -0
  93. data/redist/xmlscan/tests/testxmlchar.rb +143 -0
  94. data/redist/xmlscan/tests/visitor.rb +34 -0
  95. data/test/array_extensions_test.rb +2 -2
  96. data/test/ea_instantiator_test.rb +41 -0
  97. data/test/ecore_self_test.rb +53 -0
  98. data/test/environment_test.rb +11 -6
  99. data/test/metamodel_builder_test.rb +404 -245
  100. data/test/metamodel_roundtrip_test.rb +52 -0
  101. data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
  102. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
  103. data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
  104. data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
  105. data/test/rgen_test.rb +3 -3
  106. data/test/template_language_test.rb +65 -39
  107. data/test/template_language_test/expected_result.txt +24 -3
  108. data/test/template_language_test/templates/code/array.tpl +11 -0
  109. data/test/template_language_test/templates/content/author.tpl +7 -0
  110. data/test/template_language_test/templates/content/chapter.tpl +1 -1
  111. data/test/template_language_test/templates/root.tpl +17 -8
  112. data/test/template_language_test/testout.txt +24 -3
  113. data/test/testmodel/class_model_checker.rb +119 -0
  114. data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
  115. data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
  116. data/test/testmodel/ea_testmodel_partial.xml +317 -0
  117. data/test/testmodel/ecore_model_checker.rb +101 -0
  118. data/test/testmodel/manual_testmodel.xml +22 -0
  119. data/test/testmodel/object_model_checker.rb +67 -0
  120. data/test/transformer_test.rb +18 -10
  121. data/test/xml_instantiator_test.rb +81 -8
  122. data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
  123. data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
  124. data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
  125. data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
  126. metadata +126 -28
  127. data/lib/ea/xmi_class_instantiator.rb +0 -46
  128. data/lib/ea/xmi_helper.rb +0 -26
  129. data/lib/ea/xmi_metamodel.rb +0 -34
  130. data/lib/ea/xmi_object_instantiator.rb +0 -46
  131. data/lib/ea/xmi_to_classmodel.rb +0 -78
  132. data/lib/ea/xmi_to_objectmodel.rb +0 -92
  133. data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
  134. data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
  135. data/lib/rgen/xml_instantiator.rb +0 -132
  136. data/lib/uml/objectmodel_instantiator.rb +0 -53
  137. data/lib/uml/uml_classmodel.rb +0 -92
  138. data/lib/uml/uml_objectmodel.rb +0 -65
  139. data/test/metamodel_generator_test.rb +0 -44
  140. data/test/metamodel_generator_test/TestModel.rb +0 -40
  141. data/test/metamodel_generator_test/expected_result.txt +0 -40
  142. data/test/xmi_class_instantiator_test.rb +0 -24
  143. data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
  144. data/test/xmi_object_instantiator_test.rb +0 -65
  145. data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,52 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+
3
+ require 'test/unit'
4
+ require 'rgen/array_extensions'
5
+ require 'rgen/model_comparator'
6
+ require 'mmgen/metamodel_generator'
7
+ require 'rgen/instantiator/ecore_xml_instantiator'
8
+
9
+ class MetamodelGeneratorTest < Test::Unit::TestCase
10
+
11
+ TEST_DIR = File.dirname(__FILE__)+"/metamodel_roundtrip_test"
12
+
13
+ include MMGen::MetamodelGenerator
14
+ include RGen::ModelComparator
15
+
16
+ module Regenerated
17
+ Inside = binding
18
+ end
19
+
20
+ def test_generator
21
+ require TEST_DIR+"/TestModel.rb"
22
+ outfile = TEST_DIR+"/TestModel_Regenerated.rb"
23
+ generateMetamodel(HouseMetamodel.ecore, outfile)
24
+
25
+ File.open(outfile) do |f|
26
+ eval(f.read, Regenerated::Inside)
27
+ end
28
+
29
+ assert modelEqual?(HouseMetamodel.ecore, Regenerated::HouseMetamodel.ecore, ["instanceClassName"])
30
+ end
31
+
32
+ module UMLRegenerated
33
+ Inside = binding
34
+ end
35
+
36
+ def test_generate_from_ecore
37
+ outfile = TEST_DIR+"/houseMetamodel_from_ecore.rb"
38
+
39
+ env = RGen::Environment.new
40
+ File.open(TEST_DIR+"/houseMetamodel.ecore") { |f|
41
+ ECoreXMLInstantiator.new(env).instantiate(f.read)
42
+ }
43
+ rootpackage = env.find(:class => RGen::ECore::EPackage).first
44
+ rootpackage.name = "HouseMetamodel"
45
+ generateMetamodel(rootpackage, outfile)
46
+
47
+ File.open(outfile) do |f|
48
+ eval(f.read, UMLRegenerated::Inside, "test_eval", 0)
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,65 @@
1
+ require 'rgen/metamodel_builder'
2
+
3
+ module HouseMetamodel
4
+ extend RGen::MetamodelBuilder::ModuleExtension
5
+ include RGen::MetamodelBuilder::DataTypes
6
+
7
+ # TODO: Datatypes
8
+ # AggregationKind = Enum.new([ :none, :aggregate, :composite ])
9
+
10
+ class MeetingPlace < RGen::MetamodelBuilder::MMBase
11
+ annotation :source => "testmodel", :details => { 'complexity' => '1', 'date_created' => '2006-07-12 08:40:46', 'date_modified' => '2006-07-12 08:44:02', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0' }
12
+ end
13
+
14
+ class Person < RGen::MetamodelBuilder::MMBase
15
+ annotation 'complexity' => '1', 'date_created' => '2006-06-27 08:34:23', 'date_modified' => '2006-06-27 08:34:26', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
16
+ end
17
+
18
+ class House < RGen::MetamodelBuilder::MMBase
19
+ annotation 'complexity' => '1', 'date_created' => '2005-09-16 19:52:18', 'date_modified' => '2006-02-28 08:29:19', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'stereotype' => 'dummy', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
20
+ has_attr 'size', Integer
21
+ has_attr 'module'
22
+ has_attr 'address', String, :changeable => false do
23
+ annotation 'collection' => 'false', 'containment' => 'Not Specified', 'derived' => '0', 'duplicates' => '0', 'ea_guid' => '{A8DF581B-9AC6-4f75-AB48-8FAEDFC6E068}', 'lowerBound' => '1', 'ordered' => '0', 'position' => '0', 'styleex' => 'volatile=0;', 'type' => 'String', 'upperBound' => '1'
24
+ end
25
+
26
+ end
27
+
28
+
29
+ module Rooms
30
+ extend RGen::MetamodelBuilder::ModuleExtension
31
+
32
+
33
+ class Room < RGen::MetamodelBuilder::MMBase
34
+ annotation 'complexity' => '1', 'date_created' => '2005-09-16 19:52:28', 'date_modified' => '2006-06-22 21:15:25', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
35
+ end
36
+
37
+ class Bathroom < Room
38
+ annotation 'complexity' => '1', 'date_created' => '2006-06-27 08:32:25', 'date_modified' => '2006-06-27 08:34:23', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
39
+ end
40
+
41
+ class Kitchen < RGen::MetamodelBuilder::MMMultiple(HouseMetamodel::MeetingPlace, Room)
42
+ annotation 'complexity' => '1', 'date_created' => '2005-11-30 19:26:13', 'date_modified' => '2006-06-22 21:15:34', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
43
+ end
44
+
45
+ end
46
+
47
+ module DependingOnRooms
48
+ extend RGen::MetamodelBuilder::ModuleExtension
49
+ class RoomSub < Rooms::Room
50
+ end
51
+ end
52
+ end
53
+
54
+ HouseMetamodel::Person.has_many 'home', HouseMetamodel::House do
55
+ annotation 'containment' => 'Unspecified'
56
+ end
57
+ HouseMetamodel::House.has_one 'bathroom', HouseMetamodel::Rooms::Bathroom, :lowerBound => 1, :transient => true
58
+ HouseMetamodel::House.one_to_one 'kitchen', HouseMetamodel::Rooms::Kitchen, 'house', :lowerBound => 1, :opposite_lowerBound => 1 do
59
+ annotation 'containment' => 'Unspecified'
60
+ opposite_annotation 'containment' => 'Unspecified'
61
+ end
62
+ HouseMetamodel::House.contains_many 'room', HouseMetamodel::Rooms::Room, 'house', :lowerBound => 1 do
63
+ # only an opposite annotation
64
+ opposite_annotation 'containment' => 'Unspecified'
65
+ end
@@ -0,0 +1,64 @@
1
+ require 'rgen/metamodel_builder'
2
+
3
+ module HouseMetamodel
4
+ extend RGen::MetamodelBuilder::ModuleExtension
5
+ include RGen::MetamodelBuilder::DataTypes
6
+
7
+
8
+ module Rooms
9
+ extend RGen::MetamodelBuilder::ModuleExtension
10
+ include RGen::MetamodelBuilder::DataTypes
11
+
12
+ end
13
+
14
+ module DependingOnRooms
15
+ extend RGen::MetamodelBuilder::ModuleExtension
16
+ include RGen::MetamodelBuilder::DataTypes
17
+
18
+ end
19
+ end
20
+
21
+ class HouseMetamodel::House < RGen::MetamodelBuilder::MMBase
22
+ annotation 'complexity' => '1', 'date_created' => '2005-09-16 19:52:18', 'date_modified' => '2006-02-28 08:29:19', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'stereotype' => 'dummy', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
23
+ has_attr 'size', Integer
24
+ has_attr 'module', String
25
+ has_attr 'address', String, :changeable => false do
26
+ annotation 'collection' => 'false', 'containment' => 'Not Specified', 'derived' => '0', 'duplicates' => '0', 'ea_guid' => '{A8DF581B-9AC6-4f75-AB48-8FAEDFC6E068}', 'lowerBound' => '1', 'ordered' => '0', 'position' => '0', 'styleex' => 'volatile=0;', 'type' => 'String', 'upperBound' => '1'
27
+ end
28
+ end
29
+
30
+ class HouseMetamodel::MeetingPlace < RGen::MetamodelBuilder::MMBase
31
+ annotation :source => "testmodel", :details => {'complexity' => '1', 'date_created' => '2006-07-12 08:40:46', 'date_modified' => '2006-07-12 08:44:02', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'}
32
+ end
33
+
34
+ class HouseMetamodel::Person < RGen::MetamodelBuilder::MMBase
35
+ annotation 'complexity' => '1', 'date_created' => '2006-06-27 08:34:23', 'date_modified' => '2006-06-27 08:34:26', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_A1B83D59_CAE1_422c_BA5F_D3624D7156AD', 'package_name' => 'HouseMetamodel', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
36
+ end
37
+
38
+ class HouseMetamodel::Rooms::Room < RGen::MetamodelBuilder::MMBase
39
+ annotation 'complexity' => '1', 'date_created' => '2005-09-16 19:52:28', 'date_modified' => '2006-06-22 21:15:25', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
40
+ end
41
+
42
+ class HouseMetamodel::Rooms::Kitchen < RGen::MetamodelBuilder::MMMultiple(HouseMetamodel::MeetingPlace, HouseMetamodel::Rooms::Room)
43
+ annotation 'complexity' => '1', 'date_created' => '2005-11-30 19:26:13', 'date_modified' => '2006-06-22 21:15:34', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
44
+ end
45
+
46
+ class HouseMetamodel::Rooms::Bathroom < HouseMetamodel::Rooms::Room
47
+ annotation 'complexity' => '1', 'date_created' => '2006-06-27 08:32:25', 'date_modified' => '2006-06-27 08:34:23', 'ea_ntype' => '0', 'ea_stype' => 'Class', 'gentype' => 'Java', 'isSpecification' => 'false', 'package' => 'EAPK_F9D8C6E3_4DAD_4aa2_AD47_D0ABA4E93E08', 'package_name' => 'Rooms', 'phase' => '1.0', 'status' => 'Proposed', 'style' => 'BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;', 'tagged' => '0', 'version' => '1.0'
48
+ end
49
+
50
+ class HouseMetamodel::DependingOnRooms::RoomSub < HouseMetamodel::Rooms::Room
51
+ end
52
+
53
+
54
+ HouseMetamodel::House.has_one 'bathroom', HouseMetamodel::Rooms::Bathroom, :transient => true, :lowerBound => 1
55
+ HouseMetamodel::House.one_to_one 'kitchen', HouseMetamodel::Rooms::Kitchen, 'house', :lowerBound => 1, :opposite_lowerBound => 1 do
56
+ annotation 'containment' => 'Unspecified'
57
+ opposite_annotation 'containment' => 'Unspecified'
58
+ end
59
+ HouseMetamodel::House.contains_many 'room', HouseMetamodel::Rooms::Room, 'house', :lowerBound => 1 do
60
+ opposite_annotation 'containment' => 'Unspecified'
61
+ end
62
+ HouseMetamodel::Person.has_many 'home', HouseMetamodel::House do
63
+ annotation 'containment' => 'Unspecified'
64
+ end
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ecore:EPackage xmi:version="2.0"
3
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="HouseMetamodel">
5
+ <eClassifiers xsi:type="ecore:EClass" name="House">
6
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="address" eType="#//String"
7
+ changeable="false"/>
8
+ <eStructuralFeatures xsi:type="ecore:EReference" name="bathroom" lowerBound="1"
9
+ eType="#//Rooms/Bathroom"/>
10
+ <eStructuralFeatures xsi:type="ecore:EReference" name="kitchen" lowerBound="1"
11
+ eType="#//Rooms/Kitchen" eOpposite="#//Rooms/Kitchen/house"/>
12
+ <eStructuralFeatures xsi:type="ecore:EReference" name="room" upperBound="-1" eType="#//Rooms/Room"
13
+ containment="true" eOpposite="#//Rooms/Room/house"/>
14
+ </eClassifiers>
15
+ <eClassifiers xsi:type="ecore:EClass" name="MeetingPlace"/>
16
+ <eClassifiers xsi:type="ecore:EClass" name="Person">
17
+ <eStructuralFeatures xsi:type="ecore:EReference" name="house" upperBound="-1"
18
+ eType="#//House"/>
19
+ </eClassifiers>
20
+ <eClassifiers xsi:type="ecore:EDataType" name="String" instanceClassName="java.lang.String"/>
21
+ <eSubpackages name="Rooms">
22
+ <eClassifiers xsi:type="ecore:EClass" name="Room">
23
+ <eStructuralFeatures xsi:type="ecore:EReference" name="house" eType="#//House"
24
+ defaultValueLiteral="" eOpposite="#//House/room"/>
25
+ </eClassifiers>
26
+ <eClassifiers xsi:type="ecore:EClass" name="Bathroom" eSuperTypes="#//Rooms/Room"/>
27
+ <eClassifiers xsi:type="ecore:EClass" name="Kitchen" eSuperTypes="#//Rooms/Room #//MeetingPlace">
28
+ <eStructuralFeatures xsi:type="ecore:EReference" name="house" eType="#//House"
29
+ eOpposite="#//House/kitchen"/>
30
+ </eClassifiers>
31
+ </eSubpackages>
32
+ </ecore:EPackage>
@@ -0,0 +1,39 @@
1
+ require 'rgen/metamodel_builder'
2
+
3
+ module HouseMetamodel
4
+ extend RGen::MetamodelBuilder::ModuleExtension
5
+ include RGen::MetamodelBuilder::DataTypes
6
+
7
+
8
+ class House < RGen::MetamodelBuilder::MMBase
9
+ has_attr 'address', String, :ordered => :true, :unique => :true, :changeable => false, :volatile => :false, :transient => :false, :unsettable => :false, :derived => :false
10
+ end
11
+
12
+ class MeetingPlace < RGen::MetamodelBuilder::MMBase
13
+ end
14
+
15
+ class Person < RGen::MetamodelBuilder::MMBase
16
+ end
17
+
18
+
19
+ module Rooms
20
+ extend RGen::MetamodelBuilder::ModuleExtension
21
+ include RGen::MetamodelBuilder::DataTypes
22
+
23
+
24
+ class Room < RGen::MetamodelBuilder::MMBase
25
+ end
26
+
27
+ class Bathroom < Room
28
+ end
29
+
30
+ class Kitchen < RGen::MetamodelBuilder::MMMultiple(Room, HouseMetamodel::MeetingPlace)
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ HouseMetamodel::House.contains_one_uni 'bathroom', HouseMetamodel::Rooms::Bathroom, :ordered => true, :unique => true, :changeable => true, :volatile => false, :transient => false, :unsettable => false, :derived => false, :lowerBound => 1, :resolveProxies => true
37
+ HouseMetamodel::Rooms::Kitchen.contains_one 'house', HouseMetamodel::House, 'kitchen', :ordered => true, :unique => true, :changeable => true, :volatile => false, :transient => false, :unsettable => false, :derived => false, :resolveProxies => true, :opposite_ordered => true, :opposite_unique => true, :opposite_changeable => true, :opposite_volatile => false, :opposite_transient => false, :opposite_unsettable => false, :opposite_derived => false, :opposite_lowerBound => 1, :opposite_resolveProxies => true
38
+ HouseMetamodel::Rooms::Room.many_to_one 'house', HouseMetamodel::House, 'room', :ordered => true, :unique => true, :changeable => true, :volatile => false, :transient => false, :unsettable => false, :derived => false, :resolveProxies => true, :opposite_ordered => true, :opposite_unique => true, :opposite_changeable => true, :opposite_volatile => false, :opposite_transient => false, :opposite_unsettable => false, :opposite_derived => false, :opposite_resolveProxies => true
39
+ HouseMetamodel::Person.contains_many_uni 'house', HouseMetamodel::House, :ordered => true, :unique => true, :changeable => true, :volatile => false, :transient => false, :unsettable => false, :derived => false, :resolveProxies => true
data/test/rgen_test.rb CHANGED
@@ -3,12 +3,12 @@ $:.unshift File.dirname(__FILE__)
3
3
  require 'test/unit'
4
4
 
5
5
  require 'array_extensions_test'
6
+ require 'ea_instantiator_test'
7
+ require 'ecore_self_test'
6
8
  require 'environment_test'
7
9
  require 'metamodel_builder_test'
10
+ require 'metamodel_roundtrip_test'
8
11
  require 'output_handler_test'
9
12
  require 'template_language_test'
10
- require 'xmi_class_instantiator_test'
11
- require 'xmi_object_instantiator_test'
12
- require 'metamodel_generator_test'
13
13
  require 'transformer_test'
14
14
  require 'xml_instantiator_test'
@@ -2,45 +2,71 @@ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rgen/template_language'
5
+ require 'rgen/metamodel_builder'
5
6
 
6
7
  class TemplateContainerTest < Test::Unit::TestCase
7
-
8
- TEMPLATES_DIR = File.dirname(__FILE__)+"/template_language_test/templates"
9
- OUTPUT_DIR = File.dirname(__FILE__)+"/template_language_test"
10
-
11
- module MyMM
12
-
13
- class Chapter
14
- attr_reader :title
15
- def initialize(title)
16
- @title = title
17
- end
18
- end
19
-
20
- class Document
21
- attr_reader :title, :author, :chapters
22
- def initialize(title, author)
23
- @title, @author = title, author
24
- @chapters = []
25
- end
26
- end
27
-
28
- end
29
-
30
- TEST_MODEL = MyMM::Document.new("SomeDocument","MyName")
31
- TEST_MODEL.chapters << MyMM::Chapter.new("Intro")
32
- TEST_MODEL.chapters << MyMM::Chapter.new("MainPart")
33
- TEST_MODEL.chapters << MyMM::Chapter.new("Summary")
34
-
35
- def test_with_model
36
- tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(MyMM, OUTPUT_DIR)
37
- tc.load(TEMPLATES_DIR)
38
- File.delete(OUTPUT_DIR+"/testout.txt") if File.exists? OUTPUT_DIR+"/testout.txt"
39
- tc.expand('root::Root', :for => TEST_MODEL, :indent => 1)
40
- result = expected = ""
41
- File.open(OUTPUT_DIR+"/testout.txt") {|f| result = f.read}
42
- File.open(OUTPUT_DIR+"/expected_result.txt") {|f| expected = f.read}
43
- assert_equal expected, result
44
- end
45
-
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
+
46
72
  end
@@ -1,10 +1,31 @@
1
1
  Document: SomeDocument
2
+
3
+ by Martin, EMail: martin(at)somewhe.re and Otherguy, EMail: other(at)somewhereel.se
4
+
2
5
  Index:
3
6
  1 Intro in SomeDocument
4
7
  2 MainPart in SomeDocument
5
8
  3 Summary in SomeDocument
6
- by MyName
9
+
7
10
  ----------------
8
- *** Intro ***
9
- *** MainPart ***
11
+
12
+ Chapters in one line:
13
+ *** Intro ***, *** MainPart ***, *** Summary ***
14
+
15
+ Chapters each in one line:
16
+ *** Intro ***,
17
+ *** MainPart ***,
10
18
  *** Summary ***
19
+
20
+ Here are some code examples:
21
+ Text from Root
22
+ Text from Root
23
+ int myArray[5] = {
24
+ 1,
25
+ 2,
26
+ 3,
27
+ 4,
28
+ 5
29
+ };
30
+ Text from Root
31
+ Text from Root
@@ -0,0 +1,11 @@
1
+ <% define 'ArrayDefinition', :for => CArray do %>
2
+ <%= getType %> <%= name %>[<%= size %>] = {<%iinc%>
3
+ <% expand 'InitValue', :foreach => initvalue, :separator => ",\n" %><%nl%><%idec%>
4
+ };
5
+ <% expand '../root::TextFromRoot' %>
6
+ <% expand '/root::TextFromRoot' %>
7
+ <% end %>
8
+
9
+ <% define 'InitValue', :for => PrimitiveInitValue do %>
10
+ <%= value %><%nows%>
11
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% define 'Author', :for => Author do %>
2
+ <% expand 'SubAuthor' %>
3
+ <% end %>
4
+
5
+ <% define 'SubAuthor', :for => Author do %>
6
+ <%= name %>, EMail: <%= email.sub('@','(at)') %><%nows%>
7
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  <% define 'Root', :for => Chapter do %>
2
- *** <%= title %> ***
2
+ *** <%= title %> ***<%nows%>
3
3
 
4
4
 
5
5
  <% end %>