rgen 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +28 -0
- data/Rakefile +3 -4
- data/lib/ea_support/uml13_ea_metamodel.rb +3 -3
- data/lib/ea_support/uml13_ea_to_uml13.rb +33 -2
- data/lib/ea_support/uml13_to_uml13_ea.rb +7 -0
- data/lib/mmgen/mm_ext/ecore_mmgen_ext.rb +4 -4
- data/lib/mmgen/templates/metamodel_generator.tpl +143 -143
- data/lib/rgen/ecore/ecore.rb +11 -1
- data/lib/rgen/ecore/ecore_interface.rb +47 -0
- data/lib/rgen/ecore/ecore_to_ruby.rb +166 -0
- data/lib/rgen/ecore/{ecore_transformer.rb → ruby_to_ecore.rb} +11 -11
- data/lib/rgen/environment.rb +15 -2
- data/lib/rgen/fragment/dump_file_cache.rb +63 -0
- data/lib/rgen/fragment/fragmented_model.rb +139 -0
- data/lib/rgen/fragment/model_fragment.rb +268 -0
- data/lib/rgen/instantiator/abstract_xml_instantiator.rb +44 -72
- data/lib/rgen/instantiator/default_xml_instantiator.rb +2 -2
- data/lib/rgen/instantiator/ecore_xml_instantiator.rb +16 -1
- data/lib/rgen/instantiator/json_instantiator.rb +16 -2
- data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +118 -138
- data/lib/rgen/instantiator/qualified_name_resolver.rb +5 -1
- data/lib/rgen/instantiator/reference_resolver.rb +126 -24
- data/lib/rgen/instantiator/xmi11_instantiator.rb +6 -2
- data/lib/rgen/metamodel_builder.rb +18 -6
- data/lib/rgen/metamodel_builder/builder_extensions.rb +431 -407
- data/lib/rgen/metamodel_builder/builder_runtime.rb +8 -8
- data/lib/rgen/metamodel_builder/constant_order_helper.rb +4 -4
- data/lib/rgen/metamodel_builder/data_types.rb +5 -1
- data/lib/rgen/metamodel_builder/intermediate/feature.rb +167 -0
- data/lib/rgen/metamodel_builder/module_extension.rb +2 -2
- data/lib/rgen/model_builder.rb +10 -5
- data/lib/rgen/model_builder/builder_context.rb +17 -1
- data/lib/rgen/serializer/opposite_reference_filter.rb +18 -0
- data/lib/rgen/serializer/qualified_name_provider.rb +45 -0
- data/lib/rgen/template_language/template_container.rb +3 -1
- data/lib/rgen/{auto_class_creator.rb → util/auto_class_creator.rb} +6 -1
- data/lib/rgen/util/cached_glob.rb +67 -0
- data/lib/rgen/util/file_cache_map.rb +104 -0
- data/lib/rgen/util/file_change_detector.rb +78 -0
- data/lib/rgen/{method_delegation.rb → util/method_delegation.rb} +18 -3
- data/lib/rgen/{model_comparator.rb → util/model_comparator.rb} +17 -5
- data/lib/rgen/{model_comparator_base.rb → util/model_comparator_base.rb} +6 -1
- data/lib/rgen/{model_dumper.rb → util/model_dumper.rb} +6 -1
- data/lib/rgen/{name_helper.rb → util/name_helper.rb} +6 -1
- data/lib/rgen/util/pattern_matcher.rb +329 -0
- data/lib/transformers/uml13_to_ecore.rb +103 -60
- data/test/ecore_self_test.rb +43 -42
- data/test/json_test.rb +15 -0
- data/test/metamodel_builder_test.rb +361 -206
- data/test/metamodel_from_ecore_test.rb +45 -0
- data/test/metamodel_order_test.rb +10 -4
- data/test/metamodel_roundtrip_test.rb +2 -2
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +1 -1
- data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +50 -50
- data/test/method_delegation_test.rb +9 -9
- data/test/model_builder/ecore_internal.rb +19 -9
- data/test/model_builder/serializer_test.rb +1 -1
- data/test/reference_resolver_test.rb +79 -12
- data/test/rgen_test.rb +2 -0
- data/test/template_language_test.rb +7 -0
- data/test/template_language_test/templates/callback_indent_test/a.tpl +12 -0
- data/test/template_language_test/templates/callback_indent_test/b.tpl +5 -0
- data/test/testmodel/ea_testmodel_regenerated.xml +588 -583
- data/test/transformer_test.rb +3 -3
- data/test/util/file_cache_map_test.rb +91 -0
- data/test/util/file_cache_map_test/testdir/fileA +1 -0
- data/test/util_test.rb +4 -0
- data/test/xml_instantiator_test.rb +139 -135
- metadata +49 -104
- data/lib/rgen/ecore/ecore_instantiator.rb +0 -31
- data/lib/rgen/metamodel_builder/metamodel_description.rb +0 -232
- data/redist/xmlscan/ChangeLog +0 -1301
- data/redist/xmlscan/README +0 -34
- data/redist/xmlscan/THANKS +0 -11
- data/redist/xmlscan/doc/changes.html +0 -74
- data/redist/xmlscan/doc/changes.rd +0 -80
- data/redist/xmlscan/doc/en/conformance.html +0 -136
- data/redist/xmlscan/doc/en/conformance.rd +0 -152
- data/redist/xmlscan/doc/en/manual.html +0 -356
- data/redist/xmlscan/doc/en/manual.rd +0 -402
- data/redist/xmlscan/doc/ja/conformance.ja.html +0 -118
- data/redist/xmlscan/doc/ja/conformance.ja.rd +0 -134
- data/redist/xmlscan/doc/ja/manual.ja.html +0 -325
- data/redist/xmlscan/doc/ja/manual.ja.rd +0 -370
- data/redist/xmlscan/doc/src/Makefile +0 -41
- data/redist/xmlscan/doc/src/conformance.rd.src +0 -256
- data/redist/xmlscan/doc/src/langsplit.rb +0 -110
- data/redist/xmlscan/doc/src/manual.rd.src +0 -614
- data/redist/xmlscan/install.rb +0 -41
- data/redist/xmlscan/lib/xmlscan/encoding.rb +0 -311
- data/redist/xmlscan/lib/xmlscan/htmlscan.rb +0 -289
- data/redist/xmlscan/lib/xmlscan/namespace.rb +0 -352
- data/redist/xmlscan/lib/xmlscan/parser.rb +0 -299
- data/redist/xmlscan/lib/xmlscan/scanner.rb +0 -1109
- data/redist/xmlscan/lib/xmlscan/version.rb +0 -22
- data/redist/xmlscan/lib/xmlscan/visitor.rb +0 -158
- data/redist/xmlscan/lib/xmlscan/xmlchar.rb +0 -441
- data/redist/xmlscan/memo/CONFORMANCE +0 -1249
- data/redist/xmlscan/memo/PRODUCTIONS +0 -195
- data/redist/xmlscan/memo/contentspec.ry +0 -335
- data/redist/xmlscan/samples/chibixml.rb +0 -105
- data/redist/xmlscan/samples/getxmlchar.rb +0 -122
- data/redist/xmlscan/samples/rexml.rb +0 -159
- data/redist/xmlscan/samples/xmlbench.rb +0 -88
- data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +0 -22
- data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +0 -29
- data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +0 -62
- data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +0 -22
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +0 -62
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +0 -22
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +0 -22
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +0 -99
- data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +0 -116
- data/redist/xmlscan/samples/xmlconftest.rb +0 -200
- data/redist/xmlscan/test.rb +0 -7
- data/redist/xmlscan/tests/deftestcase.rb +0 -73
- data/redist/xmlscan/tests/runtest.rb +0 -47
- data/redist/xmlscan/tests/testall.rb +0 -14
- data/redist/xmlscan/tests/testencoding.rb +0 -438
- data/redist/xmlscan/tests/testhtmlscan.rb +0 -752
- data/redist/xmlscan/tests/testnamespace.rb +0 -457
- data/redist/xmlscan/tests/testparser.rb +0 -591
- data/redist/xmlscan/tests/testscanner.rb +0 -1749
- data/redist/xmlscan/tests/testxmlchar.rb +0 -143
- data/redist/xmlscan/tests/visitor.rb +0 -34
@@ -1,7 +1,7 @@
|
|
1
1
|
# RGen Framework
|
2
2
|
# (c) Martin Thiede, 2006
|
3
3
|
|
4
|
-
require 'rgen/name_helper'
|
4
|
+
require 'rgen/util/name_helper'
|
5
5
|
|
6
6
|
module RGen
|
7
7
|
|
@@ -11,27 +11,27 @@ module MetamodelBuilder
|
|
11
11
|
# The methods provided by this module are used by the methods generated
|
12
12
|
# by the class methods of MetamodelBuilder::BuilderExtensions
|
13
13
|
module BuilderRuntime
|
14
|
-
include NameHelper
|
14
|
+
include Util::NameHelper
|
15
15
|
|
16
16
|
def is_a?(c)
|
17
17
|
return super unless c.const_defined?(:ClassModule)
|
18
18
|
kind_of?(c::ClassModule)
|
19
19
|
end
|
20
20
|
|
21
|
-
def addGeneric(role, value)
|
22
|
-
send("add#{firstToUpper(role)}",value)
|
21
|
+
def addGeneric(role, value, index=-1)
|
22
|
+
send("add#{firstToUpper(role.to_s)}",value, index)
|
23
23
|
end
|
24
24
|
|
25
25
|
def removeGeneric(role, value)
|
26
|
-
send("remove#{firstToUpper(role)}",value)
|
26
|
+
send("remove#{firstToUpper(role.to_s)}",value)
|
27
27
|
end
|
28
28
|
|
29
29
|
def setGeneric(role, value)
|
30
|
-
send("#{role}
|
30
|
+
send("set#{firstToUpper(role.to_s)}",value)
|
31
31
|
end
|
32
32
|
|
33
33
|
def hasManyMethods(role)
|
34
|
-
respond_to?("add#{firstToUpper(role)}")
|
34
|
+
respond_to?("add#{firstToUpper(role.to_s)}")
|
35
35
|
end
|
36
36
|
|
37
37
|
def setOrAddGeneric(role, value)
|
@@ -43,7 +43,7 @@ module BuilderRuntime
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def getGeneric(role)
|
46
|
-
send("#{role}")
|
46
|
+
send("get#{firstToUpper(role.to_s)}")
|
47
47
|
end
|
48
48
|
|
49
49
|
def getGenericAsArray(role)
|
@@ -38,7 +38,7 @@ ConstantOrderHelper = Class.new do
|
|
38
38
|
def classCreated(c)
|
39
39
|
handlePendingEnum
|
40
40
|
cont = containerModule(c)
|
41
|
-
name = c.name.split("::").last
|
41
|
+
name = (c.name || "").split("::").last
|
42
42
|
return unless cont.respond_to?(:_constantOrder) && !cont._constantOrder.include?(name)
|
43
43
|
cont._constantOrder << name
|
44
44
|
end
|
@@ -46,7 +46,7 @@ ConstantOrderHelper = Class.new do
|
|
46
46
|
def moduleCreated(m)
|
47
47
|
handlePendingEnum
|
48
48
|
cont = containerModule(m)
|
49
|
-
name = m.name.split("::").last
|
49
|
+
name = (m.name || "").split("::").last
|
50
50
|
return unless cont.respond_to?(:_constantOrder) && !cont._constantOrder.include?(name)
|
51
51
|
cont._constantOrder << name
|
52
52
|
@currentModule = m
|
@@ -60,7 +60,7 @@ ConstantOrderHelper = Class.new do
|
|
60
60
|
private
|
61
61
|
|
62
62
|
def containerModule(m)
|
63
|
-
containerName = m.name.split("::")[0..-2].join("::")
|
63
|
+
containerName = (m.name || "").split("::")[0..-2].join("::")
|
64
64
|
containerName.empty? ? nil : eval(containerName, TOPLEVEL_BINDING)
|
65
65
|
end
|
66
66
|
|
@@ -72,7 +72,7 @@ ConstantOrderHelper = Class.new do
|
|
72
72
|
newConstants = m.constants - m._constantOrder
|
73
73
|
const = newConstants.find{|c| m.const_get(c).object_id == @pendingEnum.object_id}
|
74
74
|
if const
|
75
|
-
m._constantOrder << const
|
75
|
+
m._constantOrder << const.to_s
|
76
76
|
break
|
77
77
|
end
|
78
78
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'rgen/metamodel_builder/data_types'
|
2
|
+
|
3
|
+
module RGen
|
4
|
+
|
5
|
+
module MetamodelBuilder
|
6
|
+
|
7
|
+
module Intermediate
|
8
|
+
|
9
|
+
class Feature
|
10
|
+
attr_reader :etype, :impl_type
|
11
|
+
|
12
|
+
def value(prop)
|
13
|
+
@props[prop]
|
14
|
+
end
|
15
|
+
|
16
|
+
def annotations
|
17
|
+
@annotations ||= []
|
18
|
+
end
|
19
|
+
|
20
|
+
def many?
|
21
|
+
value(:upperBound) > 1 || value(:upperBound) == -1
|
22
|
+
end
|
23
|
+
|
24
|
+
def reference?
|
25
|
+
is_a?(Reference)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def check(props)
|
31
|
+
@props.keys.each do |p|
|
32
|
+
kind = props[p]
|
33
|
+
raise StandardError.new("invalid property #{p}") unless kind
|
34
|
+
raise StandardError.new("property '#{p}' not set") if value(p).nil? && kind == :required
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Attribute < Feature
|
41
|
+
|
42
|
+
Properties = {
|
43
|
+
:name => :required,
|
44
|
+
:ordered => :required,
|
45
|
+
:unique => :required,
|
46
|
+
:changeable => :required,
|
47
|
+
:volatile => :required,
|
48
|
+
:transient => :required,
|
49
|
+
:unsettable => :required,
|
50
|
+
:derived => :required,
|
51
|
+
:lowerBound => :required,
|
52
|
+
:upperBound => :required,
|
53
|
+
:defaultValueLiteral => :optional
|
54
|
+
}
|
55
|
+
|
56
|
+
Defaults = {
|
57
|
+
:ordered => true,
|
58
|
+
:unique => true,
|
59
|
+
:changeable => true,
|
60
|
+
:volatile => false,
|
61
|
+
:transient => false,
|
62
|
+
:unsettable => false,
|
63
|
+
:derived => false,
|
64
|
+
:lowerBound => 0
|
65
|
+
}
|
66
|
+
|
67
|
+
Types = {
|
68
|
+
String => :EString,
|
69
|
+
Integer => :EInt,
|
70
|
+
Float => :EFloat,
|
71
|
+
RGen::MetamodelBuilder::DataTypes::Boolean => :EBoolean,
|
72
|
+
Object => :ERubyObject,
|
73
|
+
Class => :ERubyClass
|
74
|
+
}
|
75
|
+
|
76
|
+
def self.default_value(prop)
|
77
|
+
Defaults[prop]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.properties
|
81
|
+
Properties.keys.sort{|a,b| a.to_s <=> b.to_s}
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize(type, props)
|
85
|
+
@props = Defaults.merge(props)
|
86
|
+
type ||= String
|
87
|
+
@etype = Types[type]
|
88
|
+
if @etype
|
89
|
+
@impl_type = type
|
90
|
+
elsif type.is_a?(RGen::MetamodelBuilder::DataTypes::Enum)
|
91
|
+
@etype = :EEnumerable
|
92
|
+
@impl_type = type
|
93
|
+
else
|
94
|
+
raise ArgumentError.new("invalid type '#{type}'")
|
95
|
+
end
|
96
|
+
if @props[:derived]
|
97
|
+
@props[:changeable] = false
|
98
|
+
@props[:volatile] = true
|
99
|
+
@props[:transient] = true
|
100
|
+
end
|
101
|
+
check(Properties)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
class Reference < Feature
|
107
|
+
attr_accessor :opposite
|
108
|
+
|
109
|
+
Properties = {
|
110
|
+
:name => :required,
|
111
|
+
:ordered => :required,
|
112
|
+
:unique => :required,
|
113
|
+
:changeable => :required,
|
114
|
+
:volatile => :required,
|
115
|
+
:transient => :required,
|
116
|
+
:unsettable => :required,
|
117
|
+
:derived => :required,
|
118
|
+
:lowerBound => :required,
|
119
|
+
:upperBound => :required,
|
120
|
+
:resolveProxies => :required,
|
121
|
+
:containment => :required
|
122
|
+
}
|
123
|
+
|
124
|
+
Defaults = {
|
125
|
+
:ordered => true,
|
126
|
+
:unique => true,
|
127
|
+
:changeable => true,
|
128
|
+
:volatile => false,
|
129
|
+
:transient => false,
|
130
|
+
:unsettable => false,
|
131
|
+
:derived => false,
|
132
|
+
:lowerBound => 0,
|
133
|
+
:resolveProxies => true
|
134
|
+
}
|
135
|
+
|
136
|
+
def self.default_value(prop)
|
137
|
+
Defaults[prop]
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.properties
|
141
|
+
Properties.keys.sort{|a,b| a.to_s <=> b.to_s}
|
142
|
+
end
|
143
|
+
|
144
|
+
def initialize(type, props)
|
145
|
+
@props = Defaults.merge(props)
|
146
|
+
if type.respond_to?(:_metamodel_description)
|
147
|
+
@etype = nil
|
148
|
+
@impl_type = type
|
149
|
+
else
|
150
|
+
raise ArgumentError.new("'#{type}' (#{type.class}) is not a MMBase in reference #{props[:name]}")
|
151
|
+
end
|
152
|
+
if @props[:derived]
|
153
|
+
@props[:changeable] = false
|
154
|
+
@props[:volatile] = true
|
155
|
+
@props[:transient] = true
|
156
|
+
end
|
157
|
+
check(Properties)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rgen/ecore/
|
1
|
+
require 'rgen/ecore/ecore_interface'
|
2
2
|
require 'rgen/metamodel_builder/intermediate/annotation'
|
3
3
|
|
4
4
|
module RGen
|
@@ -8,7 +8,7 @@ module MetamodelBuilder
|
|
8
8
|
# This module is used to extend modules which should be
|
9
9
|
# part of RGen metamodels
|
10
10
|
module ModuleExtension
|
11
|
-
include RGen::ECore::
|
11
|
+
include RGen::ECore::ECoreInterface
|
12
12
|
|
13
13
|
def annotation(hash)
|
14
14
|
_annotations << Intermediate::Annotation.new(hash)
|
data/lib/rgen/model_builder.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rgen/model_builder/builder_context'
|
2
|
-
require 'rgen/method_delegation'
|
2
|
+
require 'rgen/util/method_delegation'
|
3
3
|
#require 'ruby-prof'
|
4
4
|
|
5
5
|
module RGen
|
@@ -10,18 +10,23 @@ module ModelBuilder
|
|
10
10
|
resolver = ReferenceResolver.new
|
11
11
|
bc = BuilderContext.new(package, builderMethodsModule, resolver, env)
|
12
12
|
contextModule = eval("Module.nesting", block.binding).first
|
13
|
-
MethodDelegation.registerDelegate(bc, contextModule, "const_missing")
|
13
|
+
Util::MethodDelegation.registerDelegate(bc, contextModule, "const_missing")
|
14
|
+
BuilderContext.currentBuilderContext = bc
|
15
|
+
begin
|
14
16
|
#RubyProf.start
|
15
|
-
|
17
|
+
bc.instance_eval(&block)
|
16
18
|
#prof = RubyProf.stop
|
17
19
|
#File.open("profile_flat.txt","w+") do |f|
|
18
20
|
# RubyProf::FlatPrinter.new(prof).print(f, 0)
|
19
21
|
# end
|
20
|
-
|
22
|
+
ensure
|
23
|
+
BuilderContext.currentBuilderContext = nil
|
24
|
+
end
|
25
|
+
Util::MethodDelegation.unregisterDelegate(bc, contextModule, "const_missing")
|
21
26
|
#puts "Resolving..."
|
22
27
|
resolver.resolve(bc.toplevelElements)
|
23
28
|
bc.toplevelElements
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
end
|
32
|
+
end
|
@@ -25,6 +25,22 @@ class BuilderContext
|
|
25
25
|
ConstPathElement.new(const, self)
|
26
26
|
end
|
27
27
|
|
28
|
+
# in Ruby 1.9.0 and 1.9.1 #instance_eval looks up constants in the calling scope
|
29
|
+
# that's why const_missing needs to be prepared in BuilderContext, too
|
30
|
+
class << self
|
31
|
+
def currentBuilderContext=(bc)
|
32
|
+
@@currentBuilderContext = bc
|
33
|
+
end
|
34
|
+
|
35
|
+
def const_missing(name)
|
36
|
+
if @@currentBuilderContext
|
37
|
+
ConstPathElement.new(name, @@currentBuilderContext)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
class CommandResolver
|
29
45
|
def initialize(rootPackage, extensionsModule, builderContext)
|
30
46
|
@extensionFactory = ExtensionContainerFactory.new(rootPackage, extensionsModule, builderContext)
|
@@ -315,4 +331,4 @@ end
|
|
315
331
|
|
316
332
|
end
|
317
333
|
|
318
|
-
end
|
334
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RGen
|
2
|
+
|
3
|
+
module Serializer
|
4
|
+
|
5
|
+
# Filters refereences with an eOpposite:
|
6
|
+
# 1. containment references are always preferred
|
7
|
+
# 2. at a 1-to-n reference the 1-reference is always preferred
|
8
|
+
# 3. otherwise the reference with the name in string sort order before the opposite's name is prefereed
|
9
|
+
#
|
10
|
+
OppositeReferenceFilter = proc do |features|
|
11
|
+
features.reject{|f| f.is_a?(RGen::ECore::EReference) && !f.containment && f.eOpposite &&
|
12
|
+
(f.eOpposite.containment || (f.many && !f.eOpposite.many) || (!(!f.many && f.eOpposite.many) && (f.name < f.eOpposite.name)))}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RGen
|
2
|
+
|
3
|
+
module Serializer
|
4
|
+
|
5
|
+
# simple identifier calculation based on qualified names
|
6
|
+
# prerequisits:
|
7
|
+
# * containment relations must be bidirectionsl
|
8
|
+
# * local name stored in single attribute +@attribute_name+ for all classes
|
9
|
+
#
|
10
|
+
class QualifiedNameProvider
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@qualified_name_cache = {}
|
14
|
+
@attribute_name = options[:attribute_name] || "name"
|
15
|
+
@separator = options[:separator] || "/"
|
16
|
+
@leading_separator = options.has_key?(:leading_separator) ? options[:leading_separator] : true
|
17
|
+
end
|
18
|
+
|
19
|
+
def identifier(element)
|
20
|
+
(element.is_a?(RGen::MetamodelBuilder::MMProxy) && element.targetIdentifier) || qualified_name(element)
|
21
|
+
end
|
22
|
+
|
23
|
+
def qualified_name(element)
|
24
|
+
return @qualified_name_cache[element] if @qualified_name_cache[element]
|
25
|
+
localIdent = ((element.respond_to?(@attribute_name) && element.getGeneric(@attribute_name)) || "").strip
|
26
|
+
parentRef = element.class.ecore.eAllReferences.select{|r| r.eOpposite && r.eOpposite.containment}.first
|
27
|
+
parent = parentRef && element.getGeneric(parentRef.name)
|
28
|
+
if parent
|
29
|
+
if localIdent.size > 0
|
30
|
+
parentIdent = qualified_name(parent)
|
31
|
+
result = parentIdent + @separator + localIdent
|
32
|
+
else
|
33
|
+
result = qualified_name(parent)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
result = (@leading_separator ? @separator : "") + localIdent
|
37
|
+
end
|
38
|
+
@qualified_name_cache[element] = result
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -143,6 +143,7 @@ module RGen
|
|
143
143
|
def _expand(template, args, params)
|
144
144
|
raise StandardError.new("expand :for argument evaluates to nil") if params.has_key?(:for) && params[:for].nil?
|
145
145
|
context = params[:for]
|
146
|
+
old_indent = @indent
|
146
147
|
@indent = params[:indent] || @indent
|
147
148
|
noIndentNextLine = params[:_noIndentNextLine] ||
|
148
149
|
(@output.is_a?(OutputHandler) && @output.noIndentNextLine) ||
|
@@ -163,6 +164,7 @@ module RGen
|
|
163
164
|
end
|
164
165
|
_direct_concat(local_output) unless params[:_evalOnly]
|
165
166
|
@context = old_context if old_context
|
167
|
+
@indent = old_indent
|
166
168
|
local_output.to_s
|
167
169
|
end
|
168
170
|
|
@@ -229,4 +231,4 @@ module RGen
|
|
229
231
|
|
230
232
|
end
|
231
233
|
|
232
|
-
end
|
234
|
+
end
|