rgen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +20 -1
- data/MIT-LICENSE +1 -1
- data/README +12 -9
- data/lib/instantiators/ea_instantiator.rb +36 -0
- data/lib/metamodels/uml13_metamodel.rb +559 -0
- data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
- data/lib/mmgen/metamodel_generator.rb +5 -5
- data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
- data/lib/mmgen/mmgen.rb +6 -4
- data/lib/mmgen/templates/annotations.tpl +37 -0
- data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
- data/lib/rgen/ecore/ecore.rb +190 -0
- data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
- data/lib/rgen/ecore/ecore_transformer.rb +85 -0
- data/lib/rgen/environment.rb +9 -24
- data/lib/rgen/find_helper.rb +68 -0
- data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
- data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
- data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
- data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
- data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
- data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
- data/lib/rgen/metamodel_builder.rb +103 -9
- data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
- data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
- data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
- data/lib/rgen/metamodel_builder/data_types.rb +67 -0
- data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
- data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
- data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
- data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
- data/lib/rgen/model_comparator.rb +56 -0
- data/lib/rgen/model_dumper.rb +5 -5
- data/lib/rgen/name_helper.rb +17 -1
- data/lib/rgen/template_language.rb +148 -28
- data/lib/rgen/template_language/directory_template_container.rb +56 -38
- data/lib/rgen/template_language/output_handler.rb +93 -77
- data/lib/rgen/template_language/template_container.rb +186 -143
- data/lib/rgen/transformer.rb +19 -14
- data/lib/transformers/uml13_to_ecore.rb +75 -0
- data/redist/xmlscan/ChangeLog +1301 -0
- data/redist/xmlscan/README +34 -0
- data/redist/xmlscan/THANKS +11 -0
- data/redist/xmlscan/doc/changes.html +74 -0
- data/redist/xmlscan/doc/changes.rd +80 -0
- data/redist/xmlscan/doc/en/conformance.html +136 -0
- data/redist/xmlscan/doc/en/conformance.rd +152 -0
- data/redist/xmlscan/doc/en/manual.html +356 -0
- data/redist/xmlscan/doc/en/manual.rd +402 -0
- data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
- data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
- data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
- data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
- data/redist/xmlscan/doc/src/Makefile +41 -0
- data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
- data/redist/xmlscan/doc/src/langsplit.rb +110 -0
- data/redist/xmlscan/doc/src/manual.rd.src +614 -0
- data/redist/xmlscan/install.rb +41 -0
- data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
- data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
- data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
- data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
- data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
- data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
- data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
- data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
- data/redist/xmlscan/memo/CONFORMANCE +1249 -0
- data/redist/xmlscan/memo/PRODUCTIONS +195 -0
- data/redist/xmlscan/memo/contentspec.ry +335 -0
- data/redist/xmlscan/samples/chibixml.rb +105 -0
- data/redist/xmlscan/samples/getxmlchar.rb +122 -0
- data/redist/xmlscan/samples/rexml.rb +159 -0
- data/redist/xmlscan/samples/xmlbench.rb +88 -0
- data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
- data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
- data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
- data/redist/xmlscan/samples/xmlconftest.rb +200 -0
- data/redist/xmlscan/test.rb +7 -0
- data/redist/xmlscan/tests/deftestcase.rb +73 -0
- data/redist/xmlscan/tests/runtest.rb +47 -0
- data/redist/xmlscan/tests/testall.rb +14 -0
- data/redist/xmlscan/tests/testencoding.rb +438 -0
- data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
- data/redist/xmlscan/tests/testnamespace.rb +457 -0
- data/redist/xmlscan/tests/testparser.rb +591 -0
- data/redist/xmlscan/tests/testscanner.rb +1749 -0
- data/redist/xmlscan/tests/testxmlchar.rb +143 -0
- data/redist/xmlscan/tests/visitor.rb +34 -0
- data/test/array_extensions_test.rb +2 -2
- data/test/ea_instantiator_test.rb +41 -0
- data/test/ecore_self_test.rb +53 -0
- data/test/environment_test.rb +11 -6
- data/test/metamodel_builder_test.rb +404 -245
- data/test/metamodel_roundtrip_test.rb +52 -0
- data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
- data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
- data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
- data/test/rgen_test.rb +3 -3
- data/test/template_language_test.rb +65 -39
- data/test/template_language_test/expected_result.txt +24 -3
- data/test/template_language_test/templates/code/array.tpl +11 -0
- data/test/template_language_test/templates/content/author.tpl +7 -0
- data/test/template_language_test/templates/content/chapter.tpl +1 -1
- data/test/template_language_test/templates/root.tpl +17 -8
- data/test/template_language_test/testout.txt +24 -3
- data/test/testmodel/class_model_checker.rb +119 -0
- data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
- data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
- data/test/testmodel/ea_testmodel_partial.xml +317 -0
- data/test/testmodel/ecore_model_checker.rb +101 -0
- data/test/testmodel/manual_testmodel.xml +22 -0
- data/test/testmodel/object_model_checker.rb +67 -0
- data/test/transformer_test.rb +18 -10
- data/test/xml_instantiator_test.rb +81 -8
- data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
- data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
- data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
- data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
- metadata +126 -28
- data/lib/ea/xmi_class_instantiator.rb +0 -46
- data/lib/ea/xmi_helper.rb +0 -26
- data/lib/ea/xmi_metamodel.rb +0 -34
- data/lib/ea/xmi_object_instantiator.rb +0 -46
- data/lib/ea/xmi_to_classmodel.rb +0 -78
- data/lib/ea/xmi_to_objectmodel.rb +0 -92
- data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
- data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
- data/lib/rgen/xml_instantiator.rb +0 -132
- data/lib/uml/objectmodel_instantiator.rb +0 -53
- data/lib/uml/uml_classmodel.rb +0 -92
- data/lib/uml/uml_objectmodel.rb +0 -65
- data/test/metamodel_generator_test.rb +0 -44
- data/test/metamodel_generator_test/TestModel.rb +0 -40
- data/test/metamodel_generator_test/expected_result.txt +0 -40
- data/test/xmi_class_instantiator_test.rb +0 -24
- data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
- data/test/xmi_object_instantiator_test.rb +0 -65
- data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,26 @@
|
|
1
|
+
# Some handy extensions to the UML13 metamodel
|
2
|
+
#
|
3
|
+
module UML13
|
4
|
+
|
5
|
+
module AssociationEnd::ClassModule
|
6
|
+
def otherEnd
|
7
|
+
association.connection.find{|c| c != self}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Classifier::ClassModule
|
12
|
+
def localCompositeEnd
|
13
|
+
associationEnd.select{|e| e.aggregation == :composite}
|
14
|
+
end
|
15
|
+
def remoteCompositeEnd
|
16
|
+
associationEnd.otherEnd.select{|e| e.aggregation == :composite}
|
17
|
+
end
|
18
|
+
def localNavigableEnd
|
19
|
+
associationEnd.select{|e| e.isNavigable}
|
20
|
+
end
|
21
|
+
def remoteNavigableEnd
|
22
|
+
associationEnd.otherEnd.select{|e| e.isNavigable}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'rgen/environment'
|
2
2
|
require 'rgen/template_language'
|
3
|
-
require '
|
4
|
-
require 'mmgen/mm_ext/
|
3
|
+
require 'rgen/ecore/ecore'
|
4
|
+
require 'mmgen/mm_ext/ecore_ext'
|
5
5
|
|
6
6
|
module MMGen
|
7
7
|
|
8
8
|
module MetamodelGenerator
|
9
9
|
|
10
|
-
def generateMetamodel(rootPackage, out_file
|
11
|
-
tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(
|
10
|
+
def generateMetamodel(rootPackage, out_file)
|
11
|
+
tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(RGen::ECore, File.dirname(out_file))
|
12
12
|
tpl_path = File.dirname(__FILE__) + '/templates'
|
13
13
|
tc.load(tpl_path)
|
14
|
-
tc.expand('
|
14
|
+
tc.expand('metamodel_generator::GenerateMetamodel', File.basename(out_file), :for => rootPackage)
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rgen/name_helper'
|
2
|
+
|
3
|
+
module RGen
|
4
|
+
|
5
|
+
module ECore
|
6
|
+
|
7
|
+
module EPackage::ClassModule
|
8
|
+
include RGen::NameHelper
|
9
|
+
|
10
|
+
def moduleName
|
11
|
+
firstToUpper(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def qualifiedModuleName(rootPackage)
|
15
|
+
return moduleName unless eSuperPackage and self != rootPackage
|
16
|
+
eSuperPackage.qualifiedModuleName(rootPackage) + "::" + moduleName
|
17
|
+
end
|
18
|
+
|
19
|
+
def allClassifiers
|
20
|
+
eSubpackages.inject(eClassifiers) {|r,p| r.concat(p.allClassifiers) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def ancestorPackages
|
24
|
+
return [] unless eSuperPackage
|
25
|
+
[eSuperPackage] + eSuperPackage.ancestorPackages
|
26
|
+
end
|
27
|
+
|
28
|
+
def ownClasses
|
29
|
+
eClassifiers.select{|c| c.is_a?(EClass)}
|
30
|
+
end
|
31
|
+
|
32
|
+
def classesInGenerationOrdering
|
33
|
+
ownClasses + eSubpackages.collect{|s| s.classesInGenerationOrdering}.flatten
|
34
|
+
end
|
35
|
+
|
36
|
+
def needClassReorder?
|
37
|
+
classesInGenerationOrdering != inheritanceOrderClasses(classesInGenerationOrdering)
|
38
|
+
end
|
39
|
+
|
40
|
+
def allClassesSorted
|
41
|
+
inheritanceOrderClasses(classesInGenerationOrdering)
|
42
|
+
end
|
43
|
+
|
44
|
+
def inheritanceOrderClasses(cls)
|
45
|
+
sortArray = cls.dup
|
46
|
+
i1 = 0
|
47
|
+
while i1 < sortArray.size-1
|
48
|
+
again = false
|
49
|
+
for i2 in i1+1..sortArray.size-1
|
50
|
+
e2 = sortArray[i2]
|
51
|
+
if sortArray[i1].eSuperTypes.include?(e2)
|
52
|
+
sortArray.delete(e2)
|
53
|
+
sortArray.insert(i1,e2)
|
54
|
+
again = true
|
55
|
+
break
|
56
|
+
end
|
57
|
+
end
|
58
|
+
i1 += 1 unless again
|
59
|
+
end
|
60
|
+
sortArray
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module EClassifier::ClassModule
|
65
|
+
include RGen::NameHelper
|
66
|
+
def classifierName
|
67
|
+
firstToUpper(name)
|
68
|
+
end
|
69
|
+
def qualifiedName(rootPackage)
|
70
|
+
(ePackage ? ePackage.qualifiedModuleName(rootPackage) + "::" : "") + classifierName
|
71
|
+
end
|
72
|
+
def ancestorPackages
|
73
|
+
return [] unless ePackage
|
74
|
+
[ePackage] + ePackage.ancestorPackages
|
75
|
+
end
|
76
|
+
def qualifiedNameIfRequired(package)
|
77
|
+
if ePackage != package
|
78
|
+
commonSuper = (package.ancestorPackages & ancestorPackages).first
|
79
|
+
qualifiedName(commonSuper)
|
80
|
+
else
|
81
|
+
classifierName
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
module EAttribute::ClassModule
|
87
|
+
def RubyType
|
88
|
+
typeMap = {'float' => 'Float', 'int' => 'Integer'}
|
89
|
+
(self.getType && typeMap[self.getType.downcase]) || 'String'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/mmgen/mmgen.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__),"..")
|
2
2
|
|
3
|
-
require 'ea/
|
3
|
+
require 'ea/xmi_ecore_instantiator'
|
4
4
|
require 'mmgen/metamodel_generator'
|
5
5
|
|
6
6
|
include MMGen::MetamodelGenerator
|
@@ -16,11 +16,13 @@ else
|
|
16
16
|
puts out_file
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
env = RGen::Environment.new
|
20
20
|
File.open(file_name) { |f|
|
21
|
-
|
21
|
+
puts "instantiating ..."
|
22
|
+
XMIECoreInstantiator.new.instantiateECoreModel(env, f.read)
|
22
23
|
}
|
23
24
|
|
24
|
-
rootPackage =
|
25
|
+
rootPackage = env.find(:class => RGen::ECore::EPackage, :name => root_package_name).first
|
25
26
|
|
27
|
+
puts "generating ..."
|
26
28
|
generateMetamodel(rootPackage, out_file, modules)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<% define 'Annotations', :for => EPackage do %>
|
2
|
+
<% for a in eAnnotations %>
|
3
|
+
annotation <% expand 'AnnotationArgs', :for => a %>
|
4
|
+
<% end %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<% define 'Annotations', :for => EClass do %>
|
8
|
+
<% for a in eAnnotations %>
|
9
|
+
annotation <% expand 'AnnotationArgs', :for => a %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<% define 'Annotations', :for => EStructuralFeature do %>
|
14
|
+
<% oppositeAnnotations = (this.respond_to?(:eOpposite) && eOpposite && eOpposite.eAnnotations) || [] %>
|
15
|
+
<% if eAnnotations.size > 0 || oppositeAnnotations.size > 0 %>
|
16
|
+
do<%iinc%>
|
17
|
+
<% for a in eAnnotations %>
|
18
|
+
annotation <% expand 'AnnotationArgs', :for => a %>
|
19
|
+
<% end %>
|
20
|
+
<% for a in oppositeAnnotations %>
|
21
|
+
opposite_annotation <% expand 'AnnotationArgs', :for => a %>
|
22
|
+
<% end %><%idec%>
|
23
|
+
end<%nows%>
|
24
|
+
<% end %>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<% define 'AnnotationArgs', :for => EAnnotation do %>
|
28
|
+
<% if source.nil? %>
|
29
|
+
<% expand 'Details' %>
|
30
|
+
<% else %>
|
31
|
+
:source => "<%= source.to_s %>", :details => {<% expand 'Details' %>}<%nows%>
|
32
|
+
<% end %>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<% define 'Details', :for => EAnnotation do %>
|
36
|
+
<%= details.sort{|a,b| a.key<=>b.key}.collect{ |d| "\'" + d.key + "\' => \'"+ d.value.gsub('\'','\\\'').to_s + "\'"}.join(', ') %><%nows%>
|
37
|
+
<% end %>
|
@@ -0,0 +1,171 @@
|
|
1
|
+
|
2
|
+
<% define 'GenerateMetamodel', :for => EPackage do |filename| %>
|
3
|
+
<% file filename do %>
|
4
|
+
require 'rgen/metamodel_builder'
|
5
|
+
<%nl%>
|
6
|
+
<% if needClassReorder? %>
|
7
|
+
<% expand 'GeneratePackagesOnly' %>
|
8
|
+
<% expand 'GenerateClassesReordered' %>
|
9
|
+
<% else %>
|
10
|
+
<% expand 'GeneratePackage' %>
|
11
|
+
<% end %>
|
12
|
+
<%nl%>
|
13
|
+
<% expand 'GenerateAssocs' %>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<% define 'GeneratePackage', :for => EPackage do %>
|
18
|
+
module <%= moduleName %><% iinc %>
|
19
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
20
|
+
include RGen::MetamodelBuilder::DataTypes
|
21
|
+
<% expand 'annotations::Annotations' %>
|
22
|
+
<%nl%>
|
23
|
+
<% expand 'EnumTypes' %>
|
24
|
+
<% for c in ownClasses %><%nl%>
|
25
|
+
<% expand 'ClassHeader', this, :for => c %><%iinc%>
|
26
|
+
<% expand 'annotations::Annotations', :for => c %>
|
27
|
+
<% expand 'Attribute', this, :foreach => c.eAttributes %>
|
28
|
+
<%idec%>
|
29
|
+
end
|
30
|
+
<% end %><%nl%>
|
31
|
+
<% for p in eSubpackages %>
|
32
|
+
<%nl%><% expand 'GeneratePackage', :for => p %>
|
33
|
+
<% end %><%idec%>
|
34
|
+
end
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<% define 'GenerateClassesReordered', :for => EPackage do %>
|
38
|
+
<% for c in allClassesSorted %><%nl%>
|
39
|
+
<% expand 'ClassHeaderFullyQualified', this, :for => c %><%iinc%>
|
40
|
+
<% expand 'annotations::Annotations', :for => c %>
|
41
|
+
<% expand 'Attribute', this, :foreach => c.eAttributes %>
|
42
|
+
<%idec%>
|
43
|
+
end
|
44
|
+
<% end %><%nl%>
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
<% define 'GeneratePackagesOnly', :for => EPackage do %>
|
48
|
+
module <%= moduleName %><% iinc %>
|
49
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
50
|
+
include RGen::MetamodelBuilder::DataTypes
|
51
|
+
<% expand 'annotations::Annotations' %>
|
52
|
+
<%nl%>
|
53
|
+
<% expand 'EnumTypes' %>
|
54
|
+
<% for p in eSubpackages %>
|
55
|
+
<%nl%><% expand 'GeneratePackagesOnly', :for => p %>
|
56
|
+
<% end %><%idec%>
|
57
|
+
end
|
58
|
+
<% end %>
|
59
|
+
|
60
|
+
<% define 'Attribute', :for => EAttribute do |rootp| %>
|
61
|
+
<% if upperBound == 1%>
|
62
|
+
has_attr '<%= name %>', <%nows%>
|
63
|
+
<% if eType.is_a?(EEnum) %><%nows%>
|
64
|
+
<%= eType.qualifiedName(rootp) %><%nows%>
|
65
|
+
<% else %><%nows%>
|
66
|
+
<%= eType && eType.instanceClass.to_s %><%nows%>
|
67
|
+
<% end %><%nows%>
|
68
|
+
<% for p in RGen::MetamodelBuilder::AttributeDescription.propertySet %>
|
69
|
+
<% unless p == :name || p == :upperBound || RGen::MetamodelBuilder::AttributeDescription.default_value(p) == getGeneric(p) %>
|
70
|
+
, :<%=p%> => <%nows%>
|
71
|
+
<% if getGeneric(p).is_a?(String) %>
|
72
|
+
"<%= getGeneric(p) %>"<%nows%>
|
73
|
+
<% elsif getGeneric(p).is_a?(Symbol) %>
|
74
|
+
:<%= getGeneric(p) %><%nows%>
|
75
|
+
<% else %>
|
76
|
+
<%= getGeneric(p) %><%nows%>
|
77
|
+
<% end %>
|
78
|
+
<% end %>
|
79
|
+
<% end %>
|
80
|
+
<%ws%><% expand 'annotations::Annotations' %><%nl%>
|
81
|
+
<% end %>
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
<% define 'EnumTypes', :for => EPackage do %>
|
85
|
+
<% for enum in eClassifiers.select{|c| c.is_a?(EEnum)} %>
|
86
|
+
<%= enum.name %> = Enum.new([ <%nows%>
|
87
|
+
<%= enum.eLiterals.collect { |lit| ":"+lit.name }.join(', ') %> ])
|
88
|
+
<% end %>
|
89
|
+
<% end %>
|
90
|
+
|
91
|
+
<% define 'GenerateAssocs', :for => EPackage do %>
|
92
|
+
<% refDone = {} %>
|
93
|
+
<% for ref in allClassifiers.select{|c| c.is_a?(EClass)}.eReferences %>
|
94
|
+
<% if !refDone[ref] && ref.eOpposite %>
|
95
|
+
<% ref = ref.eOpposite if ref.eOpposite.containment %>
|
96
|
+
<% refDone[ref] = refDone[ref.eOpposite] = true %>
|
97
|
+
<% if !ref.many && !ref.eOpposite.many %>
|
98
|
+
<% if ref.containment %>
|
99
|
+
<% expand 'Reference', "contains_one", this, :for => ref %>
|
100
|
+
<% else %>
|
101
|
+
<% expand 'Reference', "one_to_one", this, :for => ref %>
|
102
|
+
<% end %>
|
103
|
+
<% elsif !ref.many && ref.eOpposite.many %>
|
104
|
+
<% expand 'Reference', "many_to_one", this, :for => ref %>
|
105
|
+
<% elsif ref.many && !ref.eOpposite.many %>
|
106
|
+
<% if ref.containment %>
|
107
|
+
<% expand 'Reference', "contains_many", this, :for => ref %>
|
108
|
+
<% else %>
|
109
|
+
<% expand 'Reference', "one_to_many", this, :for => ref %>
|
110
|
+
<% end %>
|
111
|
+
<% elsif ref.many && ref.eOpposite.many %>
|
112
|
+
<% expand 'Reference', "many_to_many", this, :for => ref %>
|
113
|
+
<% end %>
|
114
|
+
<% expand 'annotations::Annotations', :for => ref %><%nl%>
|
115
|
+
<% elsif !refDone[ref] %>
|
116
|
+
<% refDone[ref] = true %>
|
117
|
+
<% if !ref.many %>
|
118
|
+
<% if ref.containment %>
|
119
|
+
<% expand 'Reference', "contains_one_uni", this, :for => ref %>
|
120
|
+
<% else %>
|
121
|
+
<% expand 'Reference', "has_one", this, :for => ref %>
|
122
|
+
<% end %>
|
123
|
+
<% elsif ref.many %>
|
124
|
+
<% if ref.containment %>
|
125
|
+
<% expand 'Reference', "contains_many_uni", this, :for => ref %>
|
126
|
+
<% else %>
|
127
|
+
<% expand 'Reference', "has_many", this, :for => ref %>
|
128
|
+
<% end %>
|
129
|
+
<% end %>
|
130
|
+
<% expand 'annotations::Annotations', :for => ref %><%nl%>
|
131
|
+
<% end %>
|
132
|
+
<% end %>
|
133
|
+
<% end %>
|
134
|
+
|
135
|
+
<% define 'Reference', :for => EReference do |cmd, rootpackage| %>
|
136
|
+
<%= eContainingClass.qualifiedName(rootpackage) %>.<%= cmd %> '<%= name %>', <%= eType && eType.qualifiedName(rootpackage) %><%nows%>
|
137
|
+
<% if eOpposite %><%nows%>
|
138
|
+
, '<%= eOpposite.name%>'<%nows%>
|
139
|
+
<% end %><%nows%>
|
140
|
+
<% pset = RGen::MetamodelBuilder::ReferenceDescription.propertySet.reject{|p| p == :name || p == :upperBound || p == :containment} %>
|
141
|
+
<% for p in pset.reject{|p| RGen::MetamodelBuilder::ReferenceDescription.default_value(p) == getGeneric(p)} %>
|
142
|
+
, :<%=p%> => <%=getGeneric(p)%><%nows%>
|
143
|
+
<% end %>
|
144
|
+
<% if eOpposite %>
|
145
|
+
<% for p in pset.reject{|p| RGen::MetamodelBuilder::ReferenceDescription.default_value(p) == eOpposite.getGeneric(p)} %>
|
146
|
+
, :opposite_<%=p%> => <%=eOpposite.getGeneric(p)%><%nows%>
|
147
|
+
<% end %>
|
148
|
+
<% end %><%ws%>
|
149
|
+
<% end %>
|
150
|
+
|
151
|
+
<% define 'ClassHeader', :for => EClass do |rootp| %>
|
152
|
+
class <%= classifierName %> < <% nows %>
|
153
|
+
<% if eSuperTypes.size > 1 %><% nows %>
|
154
|
+
RGen::MetamodelBuilder::MMMultiple(<%= eSuperTypes.collect{|t| t.qualifiedNameIfRequired(rootp)}.join(', ') %>)
|
155
|
+
<% elsif eSuperTypes.size > 0 %><% nows %>
|
156
|
+
<%= eSuperTypes.first.qualifiedNameIfRequired(rootp) %>
|
157
|
+
<% else %><% nows %>
|
158
|
+
RGen::MetamodelBuilder::MMBase
|
159
|
+
<% end %>
|
160
|
+
<% end %>
|
161
|
+
|
162
|
+
<% define 'ClassHeaderFullyQualified', :for => EClass do |rootp| %>
|
163
|
+
class <%= qualifiedName(rootp) %> < <% nows %>
|
164
|
+
<% if eSuperTypes.size > 1 %><% nows %>
|
165
|
+
RGen::MetamodelBuilder::MMMultiple(<%= eSuperTypes.collect{|t| t.qualifiedName(rootp)}.join(', ') %>)
|
166
|
+
<% elsif eSuperTypes.size > 0 %><% nows %>
|
167
|
+
<%= eSuperTypes.first.qualifiedName(rootp) %>
|
168
|
+
<% else %><% nows %>
|
169
|
+
RGen::MetamodelBuilder::MMBase
|
170
|
+
<% end %>
|
171
|
+
<% end %>
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'rgen/metamodel_builder'
|
2
|
+
|
3
|
+
module RGen
|
4
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
5
|
+
|
6
|
+
# This is the ECore metamodel described using the RGen::MetamodelBuilder language.
|
7
|
+
#
|
8
|
+
# Known differences to the Java/EMF implementation are:
|
9
|
+
# * Attributes can not be "many"
|
10
|
+
#
|
11
|
+
module ECore
|
12
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
13
|
+
|
14
|
+
class EObject < RGen::MetamodelBuilder::MMBase
|
15
|
+
end
|
16
|
+
|
17
|
+
class EModelElement < RGen::MetamodelBuilder::MMBase
|
18
|
+
end
|
19
|
+
|
20
|
+
class EAnnotation < RGen::MetamodelBuilder::MMMultiple(EModelElement, EObject)
|
21
|
+
has_attr 'source', String
|
22
|
+
end
|
23
|
+
|
24
|
+
class ENamedElement < EModelElement
|
25
|
+
has_attr 'name', String
|
26
|
+
end
|
27
|
+
|
28
|
+
class ETypedElement < ENamedElement
|
29
|
+
has_attr 'lowerBound', Integer, :defaultValueLiteral => "0"
|
30
|
+
has_attr 'ordered', Boolean, :defaultValueLiteral => "true"
|
31
|
+
has_attr 'unique', Boolean, :defaultValueLiteral => "true"
|
32
|
+
has_attr 'upperBound', Integer, :defaultValueLiteral => "1"
|
33
|
+
has_attr 'many', Boolean, :derived=>true
|
34
|
+
has_attr 'required', Boolean, :derived=>true
|
35
|
+
module ClassModule
|
36
|
+
def many_derived
|
37
|
+
upperBound > 1 || upperBound == -1
|
38
|
+
end
|
39
|
+
def required_derived
|
40
|
+
lowerBound > 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class EStructuralFeature < ETypedElement
|
46
|
+
has_attr 'changeable', Boolean, :defaultValueLiteral => "true"
|
47
|
+
has_attr 'defaultValue', Object, :derived=>true
|
48
|
+
has_attr 'defaultValueLiteral', String
|
49
|
+
has_attr 'derived', Boolean, :defaultValueLiteral => "false"
|
50
|
+
has_attr 'transient', Boolean, :defaultValueLiteral => "false"
|
51
|
+
has_attr 'unsettable', Boolean, :defaultValueLiteral => "false"
|
52
|
+
has_attr 'volatile', Boolean, :defaultValueLiteral => "false"
|
53
|
+
module ClassModule
|
54
|
+
def defaultValue_derived
|
55
|
+
eval(defaultValueLiteral) unless defaultValueLiteral.nil?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class EAttribute < EStructuralFeature
|
61
|
+
has_attr 'iD', Boolean, :defaultValueLiteral => "false"
|
62
|
+
end
|
63
|
+
|
64
|
+
class EClassifier < ENamedElement
|
65
|
+
has_attr 'defaultValue', Object, :derived=>true
|
66
|
+
has_attr 'instanceClass', Object, :derived=>true
|
67
|
+
has_attr 'instanceClassName', String
|
68
|
+
module ClassModule
|
69
|
+
def instanceClass_derived
|
70
|
+
map = {"java.lang.String" => "String", "boolean" => "RGen::MetamodelBuilder::DataTypes::Boolean", "int" => "Integer"}
|
71
|
+
icn = instanceClassName
|
72
|
+
icn = "NilClass" if icn.nil?
|
73
|
+
icn = map[icn] if map[icn]
|
74
|
+
eval(icn)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class EDataType < EClassifier
|
80
|
+
has_attr 'serializable', Boolean
|
81
|
+
end
|
82
|
+
|
83
|
+
class EEnum < EDataType
|
84
|
+
end
|
85
|
+
|
86
|
+
class EEnumLiteral < ENamedElement
|
87
|
+
# instance may point to a "singleton object" (e.g. a Symbol) representing the literal
|
88
|
+
# has_attr 'instance', Object, :eType=>:EEnumerator, :transient=>true
|
89
|
+
has_attr 'literal', String
|
90
|
+
has_attr 'value', Integer
|
91
|
+
end
|
92
|
+
|
93
|
+
# TODO: check if required
|
94
|
+
class EFactory < EModelElement
|
95
|
+
end
|
96
|
+
|
97
|
+
class EOperation < ETypedElement
|
98
|
+
end
|
99
|
+
|
100
|
+
class EPackage < ENamedElement
|
101
|
+
has_attr 'nsPrefix', String
|
102
|
+
has_attr 'nsURI', String
|
103
|
+
end
|
104
|
+
|
105
|
+
class EParameter < ETypedElement
|
106
|
+
end
|
107
|
+
|
108
|
+
class EReference < EStructuralFeature
|
109
|
+
has_attr 'container', Boolean, :derived=>true
|
110
|
+
has_attr 'containment', Boolean, :defaultValueLiteral => "false"
|
111
|
+
has_attr 'resolveProxies', Boolean, :defaultValueLiteral => "true"
|
112
|
+
end
|
113
|
+
|
114
|
+
class EStringToStringMapEntry < RGen::MetamodelBuilder::MMBase
|
115
|
+
has_attr 'key', String
|
116
|
+
has_attr 'value', String
|
117
|
+
end
|
118
|
+
|
119
|
+
class EClass < EClassifier
|
120
|
+
has_attr 'abstract', Boolean
|
121
|
+
has_attr 'interface', Boolean
|
122
|
+
has_one 'eIDAttribute', ECore::EAttribute, :derived=>true, :resolveProxies=>false
|
123
|
+
|
124
|
+
has_many 'eAllAttributes', ECore::EAttribute, :derived=>true
|
125
|
+
has_many 'eAllContainments', ECore::EReference, :derived=>true
|
126
|
+
has_many 'eAllOperations', ECore::EOperation, :derived=>true
|
127
|
+
has_many 'eAllReferences', ECore::EReference, :derived=>true
|
128
|
+
has_many 'eAllStructuralFeatures', ECore::EStructuralFeature, :derived=>true
|
129
|
+
has_many 'eAllSuperTypes', ECore::EClass, :derived=>true
|
130
|
+
has_many 'eAttributes', ECore::EAttribute, :derived=>true
|
131
|
+
has_many 'eReferences', ECore::EReference, :derived=>true
|
132
|
+
|
133
|
+
module ClassModule
|
134
|
+
def eAllAttributes_derived
|
135
|
+
eAttributes + eSuperTypes.eAllAttributes
|
136
|
+
end
|
137
|
+
def eAllContainments_derived
|
138
|
+
eReferences.select{|r| r.containment} + eSuperTypes.eAllContainments
|
139
|
+
end
|
140
|
+
def eAllReferences_derived
|
141
|
+
eReferences + eSuperTypes.eAllReferences
|
142
|
+
end
|
143
|
+
def eAllStructuralFeatures_derived
|
144
|
+
eStructuralFeatures + eSuperTypes.eAllStructuralFeatures
|
145
|
+
end
|
146
|
+
def eAllSuperTypes_derived
|
147
|
+
eSuperTypes + eSuperTypes.eAllSuperTypes
|
148
|
+
end
|
149
|
+
def eAttributes_derived
|
150
|
+
eStructuralFeatures.select{|f| f.is_a?(EAttribute)}
|
151
|
+
end
|
152
|
+
def eReferences_derived
|
153
|
+
eStructuralFeatures.select{|f| f.is_a?(EReference)}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# predefined datatypes
|
159
|
+
|
160
|
+
EString = EDataType.new(:name => "EString", :instanceClassName => "String")
|
161
|
+
EInt = EDataType.new(:name => "EInt", :instanceClassName => "Integer")
|
162
|
+
EBoolean = EDataType.new(:name => "EBoolean", :instanceClassName => "RGen::MetamodelBuilder::DataTypes::Boolean")
|
163
|
+
EFloat = EDataType.new(:name => "EFloat", :instanceClassName => "Float")
|
164
|
+
ERubyObject = EDataType.new(:name => "ERubyObject", :instanceClassName => "Object")
|
165
|
+
EJavaObject = EDataType.new(:name => "EJavaObject")
|
166
|
+
ERubyClass = EDataType.new(:name => "ERubyClass", :instanceClassName => "Class")
|
167
|
+
EJavaClass = EDataType.new(:name => "EJavaClass")
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
ECore::EModelElement.contains_many 'eAnnotations', ECore::EAnnotation, 'eModelElement', :resolveProxies=>false
|
172
|
+
ECore::EAnnotation.contains_many_uni 'details', ECore::EStringToStringMapEntry, :resolveProxies=>false
|
173
|
+
ECore::EAnnotation.contains_many_uni 'contents', ECore::EObject, :resolveProxies=>false
|
174
|
+
ECore::EAnnotation.has_many 'references', ECore::EObject
|
175
|
+
ECore::EPackage.contains_many 'eClassifiers', ECore::EClassifier, 'ePackage'
|
176
|
+
ECore::EPackage.contains_many 'eSubpackages', ECore::EPackage, 'eSuperPackage'
|
177
|
+
ECore::ETypedElement.has_one 'eType', ECore::EClassifier
|
178
|
+
ECore::EClass.contains_many 'eOperations', ECore::EOperation, 'eContainingClass', :resolveProxies=>false
|
179
|
+
ECore::EClass.contains_many 'eStructuralFeatures', ECore::EStructuralFeature, 'eContainingClass', :resolveProxies=>false
|
180
|
+
ECore::EClass.has_many 'eSuperTypes', ECore::EClass
|
181
|
+
ECore::EEnum.contains_many 'eLiterals', ECore::EEnumLiteral, 'eEnum', :resolveProxies=>false
|
182
|
+
ECore::EFactory.one_to_one 'ePackage', ECore::EPackage, 'eFactoryInstance', :lowerBound=>1, :transient=>true, :resolveProxies=>false
|
183
|
+
ECore::EOperation.contains_many 'eParameters', ECore::EParameter, 'eOperation', :resolveProxies=>false
|
184
|
+
ECore::EOperation.has_many 'eExceptions', ECore::EClassifier
|
185
|
+
ECore::EReference.has_one 'eOpposite', ECore::EReference
|
186
|
+
|
187
|
+
ECore::EAttribute.has_one 'eAttributeType', ECore::EDataType, :lowerBound=>1, :derived=>true
|
188
|
+
ECore::EReference.has_one 'eReferenceType', ECore::EClass, :lowerBound=>1, :derived=>true
|
189
|
+
|
190
|
+
end
|