summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-05 04:37:58 (EDT)
committerEd Merks2011-08-05 04:37:58 (EDT)
commit206afc147d4c921e136404eedd4395d8e07d0887 (patch)
tree523a0c5fc3fe25ad97904093324f4629a2f6ec51
parent7faa72f64152278725edc960ce3e69de7043a404 (diff)
downloadorg.eclipse.emf-206afc147d4c921e136404eedd4395d8e07d0887.zip
org.eclipse.emf-206afc147d4c921e136404eedd4395d8e07d0887.tar.gz
org.eclipse.emf-206afc147d4c921e136404eedd4395d8e07d0887.tar.bz2
reworked the mapping
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore8
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore10
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java10
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore1
-rw-r--r--org.eclipse.emf.ecore.xcore.ui/src/org/eclipse/emf/ecore/xcore/ui/hyperlinking/XcoreHyperLinkHelper.java39
-rw-r--r--org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend7
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/AbstractMapping.java12
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/ToXcoreMapping.java18
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XClassMapping.java55
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XFeatureMapping.java58
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XOperationMapping.java44
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XPackageMapping.java28
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XcoreMapper.java84
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java32
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java266
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/EcoreXcoreBuilder.java47
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend27
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java133
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.xtend57
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java91
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java13
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java31
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java122
24 files changed, 817 insertions, 379 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
index 57f2e84..195244c 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
@@ -7,8 +7,8 @@ class X
attr EBoolean notify 'false'
attr EBoolean createChild 'false'
attr EBoolean propertySortChoices 'true'
- ref GenClass genClass ref: GenClass@/2/foo/X
- ref EStructuralFeature ecoreFeature 'x' ref: EReference@/1/X/x
+ ref GenClass genClass ref: GenClass@/1/foo/X
+ ref EStructuralFeature ecoreFeature 'x' ref: EReference@/2/X/x
}
--- */
refers X x opposite y
@@ -18,8 +18,8 @@ class X
attr EBoolean notify 'false'
attr EBoolean createChild 'false'
attr EBoolean propertySortChoices 'true'
- ref GenClass genClass ref: GenClass@/2/foo/X
- ref EStructuralFeature ecoreFeature 'y' ref: EReference@/1/X/y
+ ref GenClass genClass ref: GenClass@/1/foo/X
+ ref EStructuralFeature ecoreFeature 'y' ref: EReference@/2/X/y
}
--- */
refers X y opposite x
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
index 37c287d..65fded0 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
@@ -2,16 +2,16 @@
GenPackage {
attr EString prefix 'Foo'
attr EBoolean disposableProviderFactory 'true'
- ref EPackage ecorePackage 'foo' ref: EPackage@/1
- ref GenModel genModel ref: GenModel@/2
+ ref EPackage ecorePackage 'foo' ref: EPackage@/2
+ ref GenModel genModel ref: GenModel@/1
cref GenClass genClasses [
0: GenClass {
- ref GenPackage genPackage ref: GenPackage@/2/foo
- ref EClass ecoreClass 'Bar' ref: EClass@/1/Bar
+ ref GenPackage genPackage ref: GenPackage@/1/foo
+ ref EClass ecoreClass 'Bar' ref: EClass@/2/Bar
}
]
ref GenClassifier genClassifiers [
- 0: GenClass@/2/foo/Bar
+ 0: GenClass@/1/foo/Bar
]
}
---
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
index 04863f2..717f95f 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
@@ -2,8 +2,9 @@ package org.eclipse.emf.ecore.xcore.tests.genmodel;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xcore.XNamedElement;
import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
-import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.xtext.junit4.InjectWith;
import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner;
import org.eclipse.xtext.junit4.parameterized.ResourceURIs;
@@ -15,6 +16,8 @@ import org.eclipse.xtext.util.EmfFormatter;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.google.inject.Inject;
+
@InjectWith(XcoreInjectorProvider.class)
@RunWith(ParameterizedXtextRunner.class)
@ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/genmodel", fileExtensions = "xcore")
@@ -40,13 +43,16 @@ public class XcoreGenModelTest
}
this.expected = expected;
}
+
+ @Inject
+ private XcoreMapper mapper = new XcoreMapper();
@Test
public String gen()
{
EObject obj = NodeModelUtils.findActualSemanticObjectFor(leaf);
EcoreUtil.resolveAll(obj.eResource());
- EObject gen = XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(obj));
+ EObject gen = mapper.getGen((XNamedElement) obj);
return EmfFormatter.objToStr(gen);
}
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
index 2464d1c..240b303 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
@@ -2,7 +2,6 @@ package foo
/* XPECT issues ---
error for 'baz' message 'Couldn't resolve reference to GenBase 'baz'.'
-error for 'baz' message 'The feature 'type' of 'org.eclipse.emf.ecore.xcore.impl.XGenericTypeImpl@???' contains an unresolved proxy '???''
error ' message 'A generic super type must refer to a class'
---
*/
diff --git a/org.eclipse.emf.ecore.xcore.ui/src/org/eclipse/emf/ecore/xcore/ui/hyperlinking/XcoreHyperLinkHelper.java b/org.eclipse.emf.ecore.xcore.ui/src/org/eclipse/emf/ecore/xcore/ui/hyperlinking/XcoreHyperLinkHelper.java
index e9400c5..7b14c1c 100644
--- a/org.eclipse.emf.ecore.xcore.ui/src/org/eclipse/emf/ecore/xcore/ui/hyperlinking/XcoreHyperLinkHelper.java
+++ b/org.eclipse.emf.ecore.xcore.ui/src/org/eclipse/emf/ecore/xcore/ui/hyperlinking/XcoreHyperLinkHelper.java
@@ -1,45 +1,28 @@
package org.eclipse.emf.ecore.xcore.ui.hyperlinking;
-import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
-import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
+import org.eclipse.emf.ecore.xcore.XNamedElement;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.jface.text.Region;
-import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.common.types.xtext.ui.TypeAwareHyperlinkHelper;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor;
+import com.google.inject.Inject;
+
public class XcoreHyperLinkHelper extends TypeAwareHyperlinkHelper
{
+ @Inject
+ private XcoreMapper mapper;
+
@Override
public void createHyperlinksTo(XtextResource from, Region region, EObject to, IHyperlinkAcceptor acceptor)
{
- if (to instanceof JvmIdentifiableElement)
- {
- GenBase genBase = XcoreEcoreBuilder.getGen(to);
- if (genBase != null)
- {
- EModelElement eModelElement = genBase.getEcoreModelElement();
- if (eModelElement != null)
- {
- super.createHyperlinksTo(from, region, XcoreEcoreBuilder.get(eModelElement), acceptor);
- }
- }
- }
- else if (to instanceof GenBase)
+ XNamedElement element = mapper.getToXcoreMapping(to).getXcoreElement();
+ if (element != null)
{
- EModelElement eModelElement = ((GenBase)to).getEcoreModelElement();
- if (eModelElement != null)
- {
- super.createHyperlinksTo(from, region, XcoreEcoreBuilder.get(eModelElement), acceptor);
- }
- }
- else if (to instanceof EModelElement)
- {
- super.createHyperlinksTo(from, region, XcoreEcoreBuilder.get(to), acceptor);
- }
- else
+ super.createHyperlinksTo(from, region, element, acceptor);
+ } else
{
super.createHyperlinksTo(from, region, to, acceptor);
}
diff --git a/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF b/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
index 4945819..d8c0d0f 100644
--- a/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
@@ -25,7 +25,10 @@ Import-Package: org.apache.log4j,
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.emf.ecore.xcore,
org.eclipse.emf.ecore.xcore.formatting,
+ org.eclipse.emf.ecore.xcore.generator,
+ org.eclipse.emf.ecore.xcore.impl,
org.eclipse.emf.ecore.xcore.linking,
+ org.eclipse.emf.ecore.xcore.mappings,
org.eclipse.emf.ecore.xcore.parser.antlr,
org.eclipse.emf.ecore.xcore.parser.antlr.internal,
org.eclipse.emf.ecore.xcore.resource,
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend
index e982297..3307fb1 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend
@@ -20,11 +20,12 @@ import org.eclipse.emf.codegen.ecore.genmodel.GenModel
import org.eclipse.emf.codegen.ecore.generator.Generator
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter
import org.eclipse.emf.common.util.BasicMonitor
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper
class XcoreGenerator implements IGenerator {
@Inject
- extension MappingFacade mappings
+ extension XcoreMapper mappings
@Inject
XbaseCompiler compiler
@@ -33,14 +34,14 @@ class XcoreGenerator implements IGenerator {
val pack = resource.contents.head as XPackage
// install operation bodies
for (op : pack.allContentsIterable.filter(typeof(XOperation))) {
- val eOperation = op.EOperation
+ val eOperation = op.mapping.EOperation
val appendable = new StringBuilderBasedAppendable()
// val expectedType = op.jvmOperation.returnType
compiler.compile(op.body, appendable, null)
eOperation.EAnnotations.add(createGenModelAnnotation("body", appendable.toString))
}
- generateGenModel(resource.contents.get(2) as GenModel)
+ generateGenModel(resource.contents.filter(typeof(GenModel)).head)
}
def generateGenModel(GenModel genModel) {
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/AbstractMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/AbstractMapping.java
new file mode 100644
index 0000000..cce0e83
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/AbstractMapping.java
@@ -0,0 +1,12 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+
+public class AbstractMapping extends AdapterImpl
+{
+ @Override
+ public boolean isAdapterForType(Object type)
+ {
+ return type == getClass();
+ }
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/ToXcoreMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/ToXcoreMapping.java
new file mode 100644
index 0000000..d377a24
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/ToXcoreMapping.java
@@ -0,0 +1,18 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.ecore.xcore.XNamedElement;
+
+public class ToXcoreMapping extends AbstractMapping
+{
+ private XNamedElement xcoreElement;
+
+ public XNamedElement getXcoreElement()
+ {
+ return xcoreElement;
+ }
+
+ public void setXcoreElement(XNamedElement xcoreElement)
+ {
+ this.xcoreElement = xcoreElement;
+ }
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XClassMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XClassMapping.java
new file mode 100644
index 0000000..a72a40b
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XClassMapping.java
@@ -0,0 +1,55 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.xtext.common.types.JvmGenericType;
+
+public class XClassMapping extends AbstractMapping
+{
+ private EClass eclass;
+ private GenClass genClass;
+ private JvmGenericType interfaceType;
+ private JvmGenericType classType;
+
+ public EClass getEclass()
+ {
+ return eclass;
+ }
+
+ public void setEclass(EClass eclass)
+ {
+ this.eclass = eclass;
+ }
+
+ public GenClass getGenClass()
+ {
+ return genClass;
+ }
+
+ public void setGenClass(GenClass genClass)
+ {
+ this.genClass = genClass;
+ }
+
+ public JvmGenericType getInterfaceType()
+ {
+ return interfaceType;
+ }
+
+ public void setInterfaceType(JvmGenericType interfaceType)
+ {
+ this.interfaceType = interfaceType;
+ }
+
+ public JvmGenericType getClassType()
+ {
+ return classType;
+ }
+
+ public void setClassType(JvmGenericType classType)
+ {
+ this.classType = classType;
+ }
+
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XFeatureMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XFeatureMapping.java
new file mode 100644
index 0000000..cd5ebfa
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XFeatureMapping.java
@@ -0,0 +1,58 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.xtext.common.types.JvmField;
+import org.eclipse.xtext.common.types.JvmOperation;
+
+public class XFeatureMapping extends AbstractMapping
+{
+ private GenFeature genFeature;
+ private JvmField field;
+ private JvmOperation getter;
+ private JvmOperation setter;
+ private EStructuralFeature eStructuralFeature;
+
+ public GenFeature getGenFeature()
+ {
+ return genFeature;
+ }
+ public void setGenFeature(GenFeature genFeature)
+ {
+ this.genFeature = genFeature;
+ }
+ public JvmField getField()
+ {
+ return field;
+ }
+ public void setField(JvmField field)
+ {
+ this.field = field;
+ }
+ public JvmOperation getGetter()
+ {
+ return getter;
+ }
+ public void setGetter(JvmOperation getter)
+ {
+ this.getter = getter;
+ }
+ public JvmOperation getSetter()
+ {
+ return setter;
+ }
+ public void setSetter(JvmOperation setter)
+ {
+ this.setter = setter;
+ }
+
+ public EStructuralFeature getEStructuralFeature()
+ {
+ return eStructuralFeature;
+ }
+
+ public void setEStructuralFeature(EStructuralFeature eStructuralFeature)
+ {
+ this.eStructuralFeature = eStructuralFeature;
+ }
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XOperationMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XOperationMapping.java
new file mode 100644
index 0000000..b9a5f8d
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XOperationMapping.java
@@ -0,0 +1,44 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.xtext.common.types.JvmOperation;
+
+public class XOperationMapping extends AbstractMapping
+{
+ private EOperation eOperation;
+ private GenOperation genOperation;
+ private JvmOperation jvmOperation;
+
+ public EOperation getEOperation()
+ {
+ return eOperation;
+ }
+
+ public void setEOperation(EOperation eOperation)
+ {
+ this.eOperation = eOperation;
+ }
+
+ public GenOperation getGenOperation()
+ {
+ return genOperation;
+ }
+
+ public void setGenOperation(GenOperation genOperation)
+ {
+ this.genOperation = genOperation;
+ }
+
+ public JvmOperation getJvmOperation()
+ {
+ return jvmOperation;
+ }
+
+ public void setJvmOperation(JvmOperation jvmOperation)
+ {
+ this.jvmOperation = jvmOperation;
+ }
+
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XPackageMapping.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XPackageMapping.java
new file mode 100644
index 0000000..08d78ac
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XPackageMapping.java
@@ -0,0 +1,28 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.ecore.EPackage;
+
+public class XPackageMapping extends AbstractMapping
+{
+ private EPackage ePackage;
+ private GenPackage genPackage;
+
+ public EPackage getePackage()
+ {
+ return ePackage;
+ }
+ public void setEPackage(EPackage ePackage)
+ {
+ this.ePackage = ePackage;
+ }
+ public GenPackage getGenPackage()
+ {
+ return genPackage;
+ }
+ public void setGenPackage(GenPackage genPackage)
+ {
+ this.genPackage = genPackage;
+ }
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XcoreMapper.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XcoreMapper.java
new file mode 100644
index 0000000..f843c83
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XcoreMapper.java
@@ -0,0 +1,84 @@
+package org.eclipse.emf.ecore.xcore.mappings;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XNamedElement;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.XStructuralFeature;
+
+public class XcoreMapper
+{
+ public XClass getXClass(EObject element) {
+ return (XClass) getXcoreElement(element);
+ }
+ public XOperation getXOperation(EObject element) {
+ return (XOperation) getXcoreElement(element);
+ }
+ public XStructuralFeature getXFeature(EObject element) {
+ return (XStructuralFeature) getXcoreElement(element);
+ }
+ public XPackageMapping getMapping(XPackage aPackage) {
+ return lazyCreateMapping(aPackage, XPackageMapping.class);
+ }
+ public XClassMapping getMapping(XClass clazz) {
+ return lazyCreateMapping(clazz, XClassMapping.class);
+ }
+ public XFeatureMapping getMapping(XStructuralFeature feature) {
+ return lazyCreateMapping(feature, XFeatureMapping.class);
+ }
+ public XOperationMapping getMapping(XOperation feature) {
+ return lazyCreateMapping(feature, XOperationMapping.class);
+ }
+
+ public ToXcoreMapping getToXcoreMapping(EObject derivedElement) {
+ return lazyCreateMapping(derivedElement, ToXcoreMapping.class);
+ }
+
+ public GenBase getGen(XNamedElement namedElement) {
+ if (namedElement instanceof XPackage) {
+ return getMapping((XPackage)namedElement).getGenPackage();
+ } else if (namedElement instanceof XClass) {
+ return getMapping((XClass)namedElement).getGenClass();
+ } else if (namedElement instanceof XStructuralFeature) {
+ return getMapping((XStructuralFeature)namedElement).getGenFeature();
+ } else if (namedElement instanceof XOperation) {
+ return getMapping((XOperation)namedElement).getGenOperation();
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends Adapter> T lazyCreateMapping(EObject object, Class<T> mapperType)
+ {
+ if (object == null)
+ throw new NullPointerException("object");
+ if (mapperType == null)
+ throw new NullPointerException("mapperType");
+ T adapter = (T) EcoreUtil.getAdapter(object.eAdapters(), mapperType);
+ if (adapter == null) {
+ try
+ {
+ adapter = mapperType.newInstance();
+ object.eAdapters().add(adapter);
+ } catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ }
+ return adapter;
+ }
+
+
+ protected EObject getXcoreElement(EObject object) {
+ ToXcoreMapping adapter = (ToXcoreMapping) EcoreUtil.getAdapter(object.eAdapters(), ToXcoreMapping.class);
+ if (adapter != null)
+ return adapter.getXcoreElement();
+ return null;
+ }
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
index d3257cd..3a23500 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
@@ -1,21 +1,18 @@
package org.eclipse.emf.ecore.xcore.resource;
-import java.util.Collections;
import java.util.Iterator;
-import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
-import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xcore.XPackage;
import org.eclipse.emf.ecore.xcore.scoping.LazyCreationProxyUriConverter;
import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
+import org.eclipse.emf.ecore.xcore.util.XcoreGenmodelBuilder;
import org.eclipse.emf.ecore.xcore.util.XcoreJvmInferrer;
import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
@@ -25,6 +22,7 @@ import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.xbase.resource.XbaseResource;
import com.google.inject.Inject;
+import com.google.inject.Provider;
public class XcoreResource extends XbaseResource {
@@ -36,6 +34,12 @@ public class XcoreResource extends XbaseResource {
@Inject
private XcoreJvmInferrer jvmInferrer;
+
+ @Inject
+ private XcoreGenmodelBuilder genModelBuilder;
+
+ @Inject
+ private Provider<XcoreEcoreBuilder> xcoreEcoreBuilderProvider;
protected boolean fullyInitialized = false;
@@ -80,26 +84,10 @@ public class XcoreResource extends XbaseResource {
if (getParseResult() != null && getParseResult().getRootASTElement() instanceof XPackage)
{
XPackage model = (XPackage) getParseResult().getRootASTElement();
- XcoreEcoreBuilder xcoreEcoreBuilder = new XcoreEcoreBuilder();
+ XcoreEcoreBuilder xcoreEcoreBuilder = xcoreEcoreBuilderProvider.get();
EPackage ePackage = xcoreEcoreBuilder.getEPackage(model);
super.getContents().add(ePackage);
- GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
- genModel.initialize(Collections.singleton(ePackage));
- super.getContents().add(1, genModel);
- genModel.initialize();
- for (Iterator<EObject> i = genModel.eAllContents(); i.hasNext(); )
- {
- EObject eObject = i.next();
- if (eObject instanceof GenBase)
- {
- GenBase genBase = (GenBase)eObject;
- EModelElement eModelElement = genBase.getEcoreModelElement();
- if (eModelElement != null)
- {
- XcoreEcoreBuilder.map(eModelElement, (GenBase)eObject);
- }
- }
- }
+ genModelBuilder.getGenModel(model);
xcoreEcoreBuilder.link();
super.getContents().addAll(jvmInferrer.getDeclaredTypes(model));
getCache().clear(this);
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
index 10ea158..25a7b25 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
@@ -4,6 +4,7 @@
package org.eclipse.emf.ecore.xcore.scoping;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
@@ -14,122 +15,177 @@ import org.eclipse.emf.codegen.ecore.genmodel.GenTypeParameter;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.xcore.XClassifier;
+import org.eclipse.emf.ecore.xcore.XClass;
import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XReference;
import org.eclipse.emf.ecore.xcore.XcorePackage;
-import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
+import org.eclipse.xtext.EcoreUtil2;
+import org.eclipse.xtext.common.types.JvmDeclaredType;
+import org.eclipse.xtext.common.types.JvmFormalParameter;
+import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.AbstractScope;
+import org.eclipse.xtext.scoping.impl.SimpleScope;
+import org.eclipse.xtext.xbase.scoping.LocalVariableScopeContext;
import org.eclipse.xtext.xbase.scoping.XbaseScopeProvider;
+import com.google.inject.Inject;
+
+import static com.google.common.collect.Lists.*;
+
/**
* This class contains custom scoping description.
*
- * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping
- * on how and when to use it
- *
+ * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping on
+ * how and when to use it
+ *
*/
-public class XcoreScopeProvider extends XbaseScopeProvider {
-
- @Override
- public IScope getScope(final EObject context, EReference reference)
- {
- if (reference == XcorePackage.Literals.XREFERENCE__OPPOSITE)
- {
- return
- new AbstractScope(IScope.NULLSCOPE, false)
- {
- @Override
- protected Iterable<IEObjectDescription> getAllLocalElements()
- {
- ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
- GenFeature genFeature = (GenFeature)XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(context));
- GenClass genClass = genFeature.getTypeGenClass();
- if (genClass != null)
- {
- for (GenFeature opposite : genClass.getGenFeatures())
- {
- if (opposite.isReferenceType())
- {
- result.add(new EObjectDescription(QualifiedName.create(opposite.getName()), opposite, null));
- }
- }
- }
- return result;
- }
- };
- }
- else if (reference == XcorePackage.Literals.XREFERENCE__KEYS)
- {
- return
- new AbstractScope(IScope.NULLSCOPE, false)
- {
- @Override
- protected Iterable<IEObjectDescription> getAllLocalElements()
- {
- ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
- GenFeature genFeature = (GenFeature)XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(context));
- GenClass genClass = genFeature.getTypeGenClass();
- if (genClass != null)
- {
- for (GenFeature key : genClass.getGenFeatures())
- {
- if (!key.isReferenceType())
- {
- result.add(new EObjectDescription(QualifiedName.create(key.getName()), key, null));
- }
- }
- }
- return result;
- }
- };
-
- }
- else
- {
- IScope scope = super.getScope(context, reference);
- if (reference == XcorePackage.Literals.XGENERIC_TYPE__TYPE)
- {
- return
- new AbstractScope(scope, false)
- {
- void handleGenTypeParameters(List<IEObjectDescription> result, EList<GenTypeParameter> genTypeParameters)
- {
- for (final GenTypeParameter genTypeParameter : genTypeParameters)
- {
- result.add(new EObjectDescription(QualifiedName.create(genTypeParameter.getName()), genTypeParameter, null));
- }
- }
-
- @Override
- protected Iterable<IEObjectDescription> getAllLocalElements()
- {
- ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
- for (EObject eObject = context; eObject != null; eObject = eObject.eContainer())
- {
- if (eObject instanceof XOperation)
- {
- GenOperation genOperation = (GenOperation)XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(eObject));
- handleGenTypeParameters(result, genOperation.getGenTypeParameters());
- }
- else if (eObject instanceof XClassifier)
- {
- GenClassifier genClassifier = (GenClassifier)XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(eObject));
- handleGenTypeParameters(result, genClassifier.getGenTypeParameters());
- break;
- }
- }
- return result;
- }
- };
- }
- else
- {
- return scope;
- }
- }
- }
+public class XcoreScopeProvider extends XbaseScopeProvider
+{
+
+ @Inject
+ private XcoreMapper mapper;
+
+ protected IScope createLocalVarScope(IScope parent, LocalVariableScopeContext scopeContext)
+ {
+ if (scopeContext.getContext() instanceof XClass)
+ {
+ JvmDeclaredType jvmType = mapper.getMapping((XClass) scopeContext.getContext()).getInterfaceType();
+ if (jvmType != null)
+ {
+ return new SimpleScope(parent, Collections.singleton(EObjectDescription
+ .create(XbaseScopeProvider.THIS, jvmType)));
+ }
+ } else if (scopeContext.getContext() instanceof XOperation)
+ {
+ List<IEObjectDescription> list = newArrayList();
+ JvmOperation op = mapper.getMapping((XOperation) scopeContext.getContext()).getJvmOperation();
+ if (op != null)
+ {
+ for (JvmFormalParameter param : op.getParameters())
+ {
+ list.add(EObjectDescription.create(QualifiedName.create(param.getName()), param, null));
+ }
+ return new SimpleScope(parent, list);
+ }
+ }
+ return super.createLocalVarScope(parent, scopeContext);
+ }
+
+ protected JvmDeclaredType getContextType(EObject call)
+ {
+ if (call == null)
+ return null;
+ XClass containerClass = EcoreUtil2.getContainerOfType(call, XClass.class);
+ if (containerClass != null)
+ // TODO use impl class
+ return mapper.getMapping(containerClass).getInterfaceType();
+ else
+ return super.getContextType(call);
+ }
+
+ @Override
+ public IScope getScope(final EObject context, EReference reference)
+ {
+ if (reference == XcorePackage.Literals.XREFERENCE__OPPOSITE)
+ {
+ return new AbstractScope(IScope.NULLSCOPE, false)
+ {
+ @Override
+ protected Iterable<IEObjectDescription> getAllLocalElements()
+ {
+ ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
+ if (context instanceof XReference)
+ {
+ XReference ref = (XReference) context;
+ GenFeature genFeature = mapper.getMapping(ref).getGenFeature();
+ GenClass genClass = genFeature.getTypeGenClass();
+ if (genClass != null)
+ {
+ for (GenFeature opposite : genClass.getGenFeatures())
+ {
+ if (opposite.isReferenceType())
+ {
+ result.add(new EObjectDescription(QualifiedName.create(opposite.getName()), opposite, null));
+ }
+ }
+ }
+ }
+ return result;
+ }
+ };
+ } else if (reference == XcorePackage.Literals.XREFERENCE__KEYS)
+ {
+ return new AbstractScope(IScope.NULLSCOPE, false)
+ {
+ @Override
+ protected Iterable<IEObjectDescription> getAllLocalElements()
+ {
+ ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
+ if (context instanceof XReference)
+ {
+ XReference ref = (XReference) context;
+ GenFeature genFeature = mapper.getMapping(ref).getGenFeature();
+ GenClass genClass = genFeature.getTypeGenClass();
+ if (genClass != null)
+ {
+ for (GenFeature key : genClass.getGenFeatures())
+ {
+ if (!key.isReferenceType())
+ {
+ result.add(new EObjectDescription(QualifiedName.create(key.getName()), key, null));
+ }
+ }
+ }
+ }
+ return result;
+ }
+ };
+
+ } else
+ {
+ IScope scope = super.getScope(context, reference);
+ if (reference == XcorePackage.Literals.XGENERIC_TYPE__TYPE)
+ {
+ return new AbstractScope(scope, false)
+ {
+ void handleGenTypeParameters(List<IEObjectDescription> result, EList<GenTypeParameter> genTypeParameters)
+ {
+ for (final GenTypeParameter genTypeParameter : genTypeParameters)
+ {
+ result.add(new EObjectDescription(QualifiedName.create(genTypeParameter.getName()), genTypeParameter,
+ null));
+ }
+ }
+
+ @Override
+ protected Iterable<IEObjectDescription> getAllLocalElements()
+ {
+ ArrayList<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
+ for (EObject eObject = context; eObject != null; eObject = eObject.eContainer())
+ {
+ if (eObject instanceof XOperation)
+ {
+ GenOperation genOperation = mapper.getMapping((XOperation)eObject).getGenOperation();
+ handleGenTypeParameters(result, genOperation.getGenTypeParameters());
+ } else if (eObject instanceof XClass)
+ {
+ GenClassifier genClassifier = mapper.getMapping((XClass)eObject).getGenClass();
+ handleGenTypeParameters(result, genClassifier.getGenTypeParameters());
+ break;
+ }
+ }
+ return result;
+ }
+ };
+ } else
+ {
+ return scope;
+ }
+ }
+ }
}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/EcoreXcoreBuilder.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/EcoreXcoreBuilder.java
index 603f447..706f01c 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/EcoreXcoreBuilder.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/EcoreXcoreBuilder.java
@@ -5,6 +5,8 @@ import java.util.List;
import java.util.Map;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EAttribute;
@@ -45,21 +47,60 @@ import org.eclipse.emf.ecore.xcore.XTypeParameter;
import org.eclipse.emf.ecore.xcore.XTypedElement;
import org.eclipse.emf.ecore.xcore.XcoreFactory;
import org.eclipse.emf.ecore.xcore.XcorePackage;
-import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder.Mapping;
import org.eclipse.xtext.xbase.XBlockExpression;
public class EcoreXcoreBuilder
{
List<Runnable> runnables = new ArrayList<Runnable>();
+ static class Mapping extends AdapterImpl
+ {
+ public EObject eObject;
+ private Mapping other;
+
+ Mapping(EObject eObject)
+ {
+ this.eObject = eObject;
+ }
+ Mapping(EObject eObject, Mapping other)
+ {
+ this.eObject = eObject;
+ this.other = other;
+ }
+ @Override
+ public boolean isAdapterForType(Object type)
+ {
+ return type == Mapping.class;
+ }
+ @Override
+ public void notifyChanged(Notification notification)
+ {
+ if (other != null && notification.getEventType() == Notification.REMOVING_ADAPTER)
+ {
+ eObject.eAdapters().remove(other);
+ }
+ }
+ }
public static void map(EObject eObject1, EObject eObject2)
{
- XcoreEcoreBuilder.map(eObject2, eObject1);
+ if (eObject1.eClass().getEPackage() != EcorePackage.eINSTANCE)
+ {
+ throw new IllegalArgumentException("The first argument must be an instance from the EcorePackage");
+ }
+ if (eObject2.eClass().getEPackage() != XcorePackage.eINSTANCE)
+ {
+ throw new IllegalArgumentException("The second argument must be an instance from the XcorePackage");
+ }
+ final Mapping mapping2 = new Mapping(eObject1);
+ eObject2.eAdapters().add(mapping2);
+
+ Mapping mapping1 = new Mapping(eObject2, mapping2);
+ eObject1.eAdapters().add(mapping1);
}
public static EObject get(EObject eObject)
{
- return XcoreEcoreBuilder.get(eObject);
+ return ((Mapping)EcoreUtil.getAdapter(eObject.eAdapters(), Mapping.class)).eObject;
}
public XPackage getXPackage(EPackage ePackage)
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend
deleted file mode 100644
index ea00eae..0000000
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.eclipse.emf.ecore.xcore.util
-
-import org.eclipse.emf.ecore.xcore.XOperation
-import org.eclipse.emf.ecore.EOperation
-import org.eclipse.emf.codegen.ecore.genmodel.GenOperation
-import org.eclipse.xtext.common.types.JvmOperation
-
-class MappingFacade {
-
- def getEOperation(XOperation op) {
- XcoreEcoreBuilder::get(op) as EOperation
- }
-
- def getGenOperation(XOperation op) {
- XcoreEcoreBuilder::get(op) as GenOperation
- }
-
- def getXOperation(GenOperation op) {
- XcoreEcoreBuilder::get(op) as GenOperation
- }
-
- def JvmOperation getJvmOperation(XOperation op) {
- null //TODO
- }
-
-
-} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
index a076388..1533e2d 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
@@ -50,86 +50,44 @@ import org.eclipse.emf.ecore.xcore.XStructuralFeature;
import org.eclipse.emf.ecore.xcore.XTypeParameter;
import org.eclipse.emf.ecore.xcore.XTypedElement;
import org.eclipse.emf.ecore.xcore.XcorePackage;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.xbase.XBlockExpression;
+import com.google.inject.Inject;
+
public class XcoreEcoreBuilder
{
+ @Inject
+ private XcoreMapper mapper;
+
List<Runnable> runnables = new ArrayList<Runnable>();
- static class Mapping extends AdapterImpl
- {
- public EObject eObject;
- private Mapping other;
-
- Mapping(EObject eObject)
- {
- this.eObject = eObject;
- }
- Mapping(EObject eObject, Mapping other)
- {
- this.eObject = eObject;
- this.other = other;
- }
- @Override
- public boolean isAdapterForType(Object type)
- {
- return type == Mapping.class;
- }
- @Override
- public void notifyChanged(Notification notification)
- {
- if (other != null && notification.getEventType() == Notification.REMOVING_ADAPTER)
- {
- eObject.eAdapters().remove(other);
- }
- }
- }
- public static void map(EObject eObject1, EObject eObject2)
- {
- if (eObject1.eClass().getEPackage() != EcorePackage.eINSTANCE)
- {
- throw new IllegalArgumentException("The first argument must be an instance from the EcorePackage");
- }
- if (eObject2.eClass().getEPackage() != XcorePackage.eINSTANCE)
- {
- throw new IllegalArgumentException("The second argument must be an instance from the XcorePackage");
- }
- final Mapping mapping2 = new Mapping(eObject1);
- eObject2.eAdapters().add(mapping2);
-
- Mapping mapping1 = new Mapping(eObject2, mapping2);
- eObject1.eAdapters().add(mapping1);
- }
- public static EObject get(EObject eObject)
- {
- return ((Mapping)EcoreUtil.getAdapter(eObject.eAdapters(), Mapping.class)).eObject;
- }
- static class GenMapping extends AdapterImpl
- {
- public GenBase genBase;
- GenMapping(GenBase genBase)
- {
- this.genBase = genBase;
- }
- @Override
- public boolean isAdapterForType(Object type)
- {
- return type == GenMapping.class;
- }
- }
-
- public static void map(EObject eObject, GenBase genBase)
- {
- eObject.eAdapters().add(new GenMapping(genBase));
- }
-
- public static GenBase getGen(EObject eObject)
- {
- return ((GenMapping)EcoreUtil.getAdapter(eObject.eAdapters(), GenMapping.class)).genBase;
- }
+// static class GenMapping extends AdapterImpl
+// {
+// public GenBase genBase;
+// GenMapping(GenBase genBase)
+// {
+// this.genBase = genBase;
+// }
+// @Override
+// public boolean isAdapterForType(Object type)
+// {
+// return type == GenMapping.class;
+// }
+// }
+//
+// public static void map(EObject eObject, GenBase genBase)
+// {
+// eObject.eAdapters().add(new GenMapping(genBase));
+// }
+//
+// public static GenBase getGen(EObject eObject)
+// {
+// return ((GenMapping)EcoreUtil.getAdapter(eObject.eAdapters(), GenMapping.class)).genBase;
+// }
public void link()
{
@@ -151,7 +109,8 @@ public class XcoreEcoreBuilder
public EPackage getEPackage(XPackage xPackage)
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
- map(ePackage, xPackage);
+ mapper.getMapping(xPackage).setEPackage(ePackage);
+ mapper.getToXcoreMapping(ePackage).setXcoreElement(xPackage);
handleAnnotations(xPackage, ePackage);
String name = xPackage.getName();
String basePackage;
@@ -193,7 +152,7 @@ public class XcoreEcoreBuilder
for (XAnnotation xAnnotation : xModelElement.getAnnotations())
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
- map(eAnnotation, xAnnotation);
+// map(eAnnotation, xAnnotation);
XAnnotationDirective source = xAnnotation.getSource();
if (source != null)
{
@@ -241,7 +200,8 @@ public class XcoreEcoreBuilder
EClass getEClass(final XClass xClass)
{
final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
- map(eClass, xClass);
+ mapper.getMapping(xClass).setEclass(eClass);
+ mapper.getToXcoreMapping(eClass).setXcoreElement(xClass);
if (xClass.isInterface())
{
eClass.setInterface(true);
@@ -279,7 +239,8 @@ public class XcoreEcoreBuilder
EOperation getEOperation(XOperation xOperation)
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
- map(eOperation, xOperation);
+ mapper.getMapping(xOperation).setEOperation(eOperation);
+ mapper.getToXcoreMapping(eOperation).setXcoreElement(xOperation);
eOperation.setUnique(false);
handleETypedElement(eOperation, xOperation);
for (XTypeParameter xTypeParameter : xOperation.getTypeParameters())
@@ -311,7 +272,7 @@ public class XcoreEcoreBuilder
EParameter getEParameter(XParameter xParameter)
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
- map(eParameter, xParameter);
+// map(eParameter, xParameter);
eParameter.setUnique(false);
handleETypedElement(eParameter, xParameter);
return eParameter;
@@ -320,7 +281,8 @@ public class XcoreEcoreBuilder
ETypeParameter getETypeParameter(XTypeParameter xTypeParameter)
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
- map(eTypeParameter, xTypeParameter);
+ //TODO
+// map(eTypeParameter, xTypeParameter);
handleAnnotations(xTypeParameter, eTypeParameter);
eTypeParameter.setName(xTypeParameter.getName());
for (XGenericType xGenericType : xTypeParameter.getBounds())
@@ -400,7 +362,7 @@ public class XcoreEcoreBuilder
else
{
final EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
- map(eGenericType, xGenericType);
+// map(eGenericType, xGenericType);
XGenericType lowerBound = xGenericType.getLowerBound();
if (lowerBound != null)
{
@@ -439,7 +401,8 @@ public class XcoreEcoreBuilder
EReference getEReference(final XReference xReference)
{
final EReference eReference = EcoreFactory.eINSTANCE.createEReference();
- map(eReference, xReference);
+ mapper.getMapping(xReference).setEStructuralFeature(eReference);
+ mapper.getToXcoreMapping(eReference).setXcoreElement(xReference);
if (xReference.isContainment())
{
eReference.setContainment(true);
@@ -479,7 +442,8 @@ public class XcoreEcoreBuilder
EAttribute getEAttribute(final XAttribute xAttribute)
{
final EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
- map(eAttribute, xAttribute);
+ mapper.getMapping(xAttribute).setEStructuralFeature(eAttribute);
+ mapper.getToXcoreMapping(eAttribute).setXcoreElement(xAttribute);
eAttribute.setUnique(false);
if (xAttribute.isID())
{
@@ -519,14 +483,16 @@ public class XcoreEcoreBuilder
EDataType getEDataType(XDataType xDataType)
{
EDataType eDataType = EcoreFactory.eINSTANCE.createEDataType();
- map(eDataType, xDataType);
+ //TODO
+// map(eDataType, xDataType);
return eDataType;
}
EEnum getEEnum(XEnum xEnum)
{
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
- map(eEnum, xEnum);
+ //TODO
+// map(eEnum, xEnum);
for (XEnumLiteral xEnumLiteral : xEnum.getLiterals())
{
eEnum.getELiterals().add(getEEnumLiteral(xEnumLiteral));
@@ -537,7 +503,8 @@ public class XcoreEcoreBuilder
EEnumLiteral getEEnumLiteral(XEnumLiteral xEnumLiteral)
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
- map(eEnumLiteral, xEnumLiteral);
+ //TODO
+// map(eEnumLiteral, xEnumLiteral);
handleAnnotations(xEnumLiteral, eEnumLiteral);
eEnumLiteral.setName(xEnumLiteral.getName());
eEnumLiteral.setLiteral(xEnumLiteral.getLiteral());
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.xtend
new file mode 100644
index 0000000..889799a
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.xtend
@@ -0,0 +1,57 @@
+package org.eclipse.emf.ecore.xcore.util
+
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper
+import com.google.inject.Inject
+import org.eclipse.emf.ecore.xcore.XPackage
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory
+import java.util.Collections
+import static extension org.eclipse.xtext.xtend2.lib.EObjectExtensions.*
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage
+import org.eclipse.emf.ecore.xcore.XClass
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature
+import org.eclipse.emf.ecore.xcore.XStructuralFeature
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation
+import org.eclipse.emf.ecore.xcore.XOperation
+
+class XcoreGenmodelBuilder {
+
+ @Inject extension XcoreMapper mapper
+
+ def getGenModel(XPackage pack) {
+ val ePackage = pack.mapping.getePackage
+ val genModel = GenModelFactory::eINSTANCE.createGenModel();
+ genModel.initialize(Collections::singleton(ePackage));
+ pack.eResource.getContents().add(1, genModel);
+ genModel.initialize();
+ for (genElement : genModel.allContentsIterable)
+ {
+ switch genElement {
+ GenPackage :
+ {
+ val xPack = genElement.ecorePackage.toXcoreMapping.xcoreElement as XPackage
+ xPack.mapping.genPackage = genElement
+ genElement.toXcoreMapping.xcoreElement = xPack
+ }
+ GenClass :
+ {
+ val xClass = genElement.ecoreClass.toXcoreMapping.xcoreElement as XClass
+ xClass.mapping.genClass = genElement
+ genElement.toXcoreMapping.xcoreElement = xClass
+ }
+ GenFeature :
+ {
+ val xFeature = genElement.ecoreFeature.toXcoreMapping.xcoreElement as XStructuralFeature
+ xFeature.mapping.genFeature = genElement
+ genElement.toXcoreMapping.xcoreElement = xFeature
+ }
+ GenOperation :
+ {
+ val xOperation = genElement.ecoreOperation.toXcoreMapping.xcoreElement as XOperation
+ xOperation.mapping.genOperation = genElement
+ genElement.toXcoreMapping.xcoreElement = xOperation
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
index 9343538..48f967f 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
@@ -8,7 +8,6 @@ import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
import org.eclipse.emf.codegen.ecore.genmodel.GenEnum;
-import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenParameter;
@@ -20,10 +19,14 @@ import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.util.EcoreValidator;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XOperation;
import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.mappings.XClassMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XOperationMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.emf.ecore.xcore.scoping.LazyCreationProxyUriConverter;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.common.types.JvmFormalParameter;
@@ -39,7 +42,6 @@ import org.eclipse.xtext.common.types.TypesFactory;
import org.eclipse.xtext.common.types.util.TypeReferences;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.util.EmfFormatter;
import com.google.inject.Inject;
@@ -49,25 +51,27 @@ public class XcoreJvmInferrer
private TypeReferences typeReferences;
@Inject
- LazyCreationProxyUriConverter proxyUriConverter;
+ private LazyCreationProxyUriConverter proxyUriConverter;
@Inject
private IQualifiedNameConverter nameConverter;
+ @Inject
+ private XcoreMapper mapper;
- public static void map(EObject eObject, GenBase genBase)
- {
- XcoreEcoreBuilder.map(eObject, genBase);
- }
-
- public static GenBase getGen(EObject eObject)
- {
- return XcoreEcoreBuilder.getGen(eObject);
- }
+// public static void map(EObject eObject, GenBase genBase)
+// {
+// XcoreEcoreBuilder.map(eObject, genBase);
+// }
+//
+// public static GenBase getGen(EObject eObject)
+// {
+// return XcoreEcoreBuilder.getGen(eObject);
+// }
public List<? extends JvmDeclaredType> getDeclaredTypes(XPackage xPackage)
{
- GenPackage genPackage = (GenPackage)XcoreEcoreBuilder.getGen(XcoreEcoreBuilder.get(xPackage));
+ GenPackage genPackage = mapper.getMapping(xPackage).getGenPackage();
return getDeclaredTypes(genPackage);
}
@@ -78,11 +82,6 @@ public class XcoreJvmInferrer
{
result.addAll(getDeclaredTypes(genClassifier));
}
-
- if (true)
- {
- System.out.println(EmfFormatter.listToStr(result));
- }
return result;
}
@@ -106,12 +105,14 @@ public class XcoreJvmInferrer
public List<? extends JvmDeclaredType> getDeclaredTypes(GenClass genClass)
{
- // TODO set java.lang.Object super type or inferred super type
ArrayList<JvmDeclaredType> result = new ArrayList<JvmDeclaredType>();
+ final XClass xClass = mapper.getXClass(genClass);
+ final XClassMapping mapping = mapper.getMapping(xClass);
if (!genClass.isExternalInterface() && (!genClass.getGenModel().isSuppressInterfaces() || genClass.isInterface()))
{
JvmGenericType jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
- map(jvmGenericType, genClass);
+ mapping.setInterfaceType(jvmGenericType);
+ mapper.getToXcoreMapping(jvmGenericType).setXcoreElement(xClass);
jvmGenericType.setSimpleName(genClass.getName());
jvmGenericType.setPackageName(genClass.getGenPackage().getInterfacePackageName());
jvmGenericType.setVisibility(JvmVisibility.PUBLIC);
@@ -123,7 +124,8 @@ public class XcoreJvmInferrer
for (GenTypeParameter genTypeParameter : genTypeParameters)
{
JvmTypeParameter jvmTypeParameter = TypesFactory.eINSTANCE.createJvmTypeParameter();
- map(jvmTypeParameter, genTypeParameter);
+ //TODO
+// map(jvmTypeParameter, genTypeParameter);
jvmTypeParameter.setName(genTypeParameter.getName());
typeParameters.add(jvmTypeParameter);
// TODO Need to handle the bounds.
@@ -144,46 +146,17 @@ public class XcoreJvmInferrer
members.add(getJvmOperation(genOperation));
}
- for (GenFeature genFeature : genClass.getGenFeatures())
- {
- EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature();
- if (eStructuralFeature.getName() != null && eStructuralFeature.getEGenericType() != null)
- {
- members.addAll(getJvmFeatureAccessors(genFeature));
- }
- }
result.add(jvmGenericType);
}
return result;
}
- List<JvmOperation> getJvmFeatureAccessors(GenFeature genFeature)
- {
- List<JvmOperation> result = new ArrayList<JvmOperation>();
- if (genFeature.isGet() && !genFeature.isSuppressedGetVisibility())
- {
- JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
- map(jvmOperation, genFeature);
- jvmOperation.setSimpleName(genFeature.getGetAccessor());
- jvmOperation.setReturnType(getJvmTypeReference(genFeature.getType(genFeature.getGenClass()), genFeature));
- result.add(jvmOperation);
- }
- if (genFeature.isSet() && !genFeature.isSuppressedSetVisibility())
- {
- JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
- map(jvmOperation, genFeature);
- jvmOperation.setSimpleName("set" + genFeature.getAccessorName());
- jvmOperation.setReturnType(getJvmTypeReference(genFeature.getType(genFeature.getGenClass()), genFeature));
- result.add(jvmOperation);
- }
-
- return result;
- }
-
JvmOperation getJvmOperation(GenOperation genOperation)
{
+ XOperation xOperation = mapper.getXOperation(genOperation);
JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
- map(jvmOperation, genOperation);
+ mapper.getMapping(xOperation).setJvmOperation(jvmOperation);
+ mapper.getToXcoreMapping(jvmOperation).setXcoreElement(xOperation);
jvmOperation.setSimpleName(genOperation.getName());
for (GenParameter genParameter : genOperation.getGenParameters())
{
@@ -205,7 +178,8 @@ public class XcoreJvmInferrer
for (GenTypeParameter genTypeParameter : genTypeParameters)
{
JvmTypeParameter jvmTypeParameter = TypesFactory.eINSTANCE.createJvmTypeParameter();
- map(jvmTypeParameter, genTypeParameter);
+ //TODO
+// map(jvmTypeParameter, genTypeParameter);
jvmTypeParameter.setName(genTypeParameter.getName());
typeParameters.add(jvmTypeParameter);
// TODO Need to handle the bounds.
@@ -217,7 +191,8 @@ public class XcoreJvmInferrer
JvmFormalParameter getJvmFormalParameter(GenParameter genParameter)
{
JvmFormalParameter jvmFormalParameter = TypesFactory.eINSTANCE.createJvmFormalParameter();
- map(jvmFormalParameter, genParameter);
+ //TODO
+// map(jvmFormalParameter, genParameter);
jvmFormalParameter.setName(genParameter.getName());
jvmFormalParameter.setParameterType(getJvmTypeReference(genParameter.getEcoreParameter().getEGenericType(), genParameter));
return jvmFormalParameter;
@@ -255,10 +230,6 @@ public class XcoreJvmInferrer
{
List<JvmTypeReference> arguments = getJvmTypeReferences(eGenericType.getETypeArguments(), context);
String instanceTypeName = eClassifier.getInstanceTypeName();
- if (instanceTypeName == null)
- {
- System.err.println("###");
- }
QualifiedName qualifiedName = nameConverter.toQualifiedName(instanceTypeName);
JvmGenericType jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
proxyUriConverter.installProxyURI(context.eResource().getURI(), jvmGenericType, qualifiedName);
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java
index aeeae8c..952f2ab 100644
--- a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java
+++ b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java
@@ -16,7 +16,8 @@ import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xcore.XOperation;
import org.eclipse.emf.ecore.xcore.XPackage;
-import org.eclipse.emf.ecore.xcore.util.MappingFacade;
+import org.eclipse.emf.ecore.xcore.mappings.XOperationMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.xbase.XBlockExpression;
@@ -29,7 +30,7 @@ import org.eclipse.xtext.xtend2.lib.EObjectExtensions;
public class XcoreGenerator implements IGenerator {
@Inject
- private MappingFacade mappings;
+ private XcoreMapper mappings;
@Inject
private XbaseCompiler compiler;
@@ -43,7 +44,8 @@ public class XcoreGenerator implements IGenerator {
Iterable<XOperation> _filter = IterableExtensions.<XOperation>filter(_allContentsIterable, org.eclipse.emf.ecore.xcore.XOperation.class);
for (XOperation op : _filter) {
{
- EOperation _eOperation = this.mappings.getEOperation(op);
+ XOperationMapping _mapping = this.mappings.getMapping(op);
+ EOperation _eOperation = _mapping.getEOperation();
final EOperation eOperation = _eOperation;
StringBuilderBasedAppendable _stringBuilderBasedAppendable = new StringBuilderBasedAppendable();
final StringBuilderBasedAppendable appendable = _stringBuilderBasedAppendable;
@@ -56,8 +58,9 @@ public class XcoreGenerator implements IGenerator {
}
}
EList<EObject> _contents_1 = resource.getContents();
- EObject _get = _contents_1.get(2);
- this.generateGenModel(((GenModel) _get));
+ Iterable<GenModel> _filter_1 = IterableExtensions.<GenModel>filter(_contents_1, org.eclipse.emf.codegen.ecore.genmodel.GenModel.class);
+ GenModel _head_1 = IterableExtensions.<GenModel>head(_filter_1);
+ this.generateGenModel(_head_1);
}
}
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java
deleted file mode 100644
index 70c83e7..0000000
--- a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.eclipse.emf.ecore.xcore.util;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.xcore.XOperation;
-import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
-import org.eclipse.xtext.common.types.JvmOperation;
-
-@SuppressWarnings("all")
-public class MappingFacade {
-
- public EOperation getEOperation(final XOperation op) {
- EObject _get = XcoreEcoreBuilder.get(op);
- return ((EOperation) _get);
- }
-
- public GenOperation getGenOperation(final XOperation op) {
- EObject _get = XcoreEcoreBuilder.get(op);
- return ((GenOperation) _get);
- }
-
- public GenOperation getXOperation(final GenOperation op) {
- EObject _get = XcoreEcoreBuilder.get(op);
- return ((GenOperation) _get);
- }
-
- public JvmOperation getJvmOperation(final XOperation op) {
- return null;
- }
-} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java
new file mode 100644
index 0000000..9211767
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java
@@ -0,0 +1,122 @@
+package org.eclipse.emf.ecore.xcore.util;
+
+import com.google.inject.Inject;
+import java.util.Collections;
+import java.util.Set;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XNamedElement;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.XStructuralFeature;
+import org.eclipse.emf.ecore.xcore.mappings.ToXcoreMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XClassMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XFeatureMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XOperationMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XPackageMapping;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
+import org.eclipse.xtext.xtend2.lib.EObjectExtensions;
+
+@SuppressWarnings("all")
+public class XcoreGenmodelBuilder {
+
+ @Inject
+ private XcoreMapper mapper;
+
+ public void getGenModel(final XPackage pack) {
+ {
+ XPackageMapping _mapping = this.mapper.getMapping(pack);
+ EPackage _ePackage = _mapping.getePackage();
+ final EPackage ePackage = _ePackage;
+ GenModel _createGenModel = GenModelFactory.eINSTANCE.createGenModel();
+ final GenModel genModel = _createGenModel;
+ Set<EPackage> _singleton = Collections.<EPackage>singleton(ePackage);
+ genModel.initialize(_singleton);
+ Resource _eResource = pack.eResource();
+ EList<EObject> _contents = _eResource.getContents();
+ _contents.add(1, genModel);
+ genModel.initialize();
+ Iterable<EObject> _allContentsIterable = EObjectExtensions.allContentsIterable(genModel);
+ for (EObject genElement : _allContentsIterable) {
+ final EObject genElement_1 = genElement;
+ boolean matched = false;
+ if (!matched) {
+ if (genElement_1 instanceof GenPackage) {
+ final GenPackage genElement_2 = (GenPackage) genElement_1;
+ matched=true;
+ {
+ EPackage _ecorePackage = genElement_2.getEcorePackage();
+ ToXcoreMapping _xcoreMapping = this.mapper.getToXcoreMapping(_ecorePackage);
+ XNamedElement _xcoreElement = _xcoreMapping.getXcoreElement();
+ final XPackage xPack = ((XPackage) _xcoreElement);
+ XPackageMapping _mapping_1 = this.mapper.getMapping(xPack);
+ _mapping_1.setGenPackage(genElement_2);
+ ToXcoreMapping _xcoreMapping_1 = this.mapper.getToXcoreMapping(genElement_2);
+ _xcoreMapping_1.setXcoreElement(xPack);
+ }
+ }
+ }
+ if (!matched) {
+ if (genElement_1 instanceof GenClass) {
+ final GenClass genElement_3 = (GenClass) genElement_1;
+ matched=true;
+ {
+ EClass _ecoreClass = genElement_3.getEcoreClass();
+ ToXcoreMapping _xcoreMapping_2 = this.mapper.getToXcoreMapping(_ecoreClass);
+ XNamedElement _xcoreElement_1 = _xcoreMapping_2.getXcoreElement();
+ final XClass xClass = ((XClass) _xcoreElement_1);
+ XClassMapping _mapping_2 = this.mapper.getMapping(xClass);
+ _mapping_2.setGenClass(genElement_3);
+ ToXcoreMapping _xcoreMapping_3 = this.mapper.getToXcoreMapping(genElement_3);
+ _xcoreMapping_3.setXcoreElement(xClass);
+ }
+ }
+ }
+ if (!matched) {
+ if (genElement_1 instanceof GenFeature) {
+ final GenFeature genElement_4 = (GenFeature) genElement_1;
+ matched=true;
+ {
+ EStructuralFeature _ecoreFeature = genElement_4.getEcoreFeature();
+ ToXcoreMapping _xcoreMapping_4 = this.mapper.getToXcoreMapping(_ecoreFeature);
+ XNamedElement _xcoreElement_2 = _xcoreMapping_4.getXcoreElement();
+ final XStructuralFeature xFeature = ((XStructuralFeature) _xcoreElement_2);
+ XFeatureMapping _mapping_3 = this.mapper.getMapping(xFeature);
+ _mapping_3.setGenFeature(genElement_4);
+ ToXcoreMapping _xcoreMapping_5 = this.mapper.getToXcoreMapping(genElement_4);
+ _xcoreMapping_5.setXcoreElement(xFeature);
+ }
+ }
+ }
+ if (!matched) {
+ if (genElement_1 instanceof GenOperation) {
+ final GenOperation genElement_5 = (GenOperation) genElement_1;
+ matched=true;
+ {
+ EOperation _ecoreOperation = genElement_5.getEcoreOperation();
+ ToXcoreMapping _xcoreMapping_6 = this.mapper.getToXcoreMapping(_ecoreOperation);
+ XNamedElement _xcoreElement_3 = _xcoreMapping_6.getXcoreElement();
+ final XOperation xOperation = ((XOperation) _xcoreElement_3);
+ XOperationMapping _mapping_4 = this.mapper.getMapping(xOperation);
+ _mapping_4.setGenOperation(genElement_5);
+ ToXcoreMapping _xcoreMapping_7 = this.mapper.getToXcoreMapping(genElement_5);
+ _xcoreMapping_7.setXcoreElement(xOperation);
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file