summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-05 05:03:47 (EDT)
committer Ed Merks2011-08-05 05:03:47 (EDT)
commitab568a880d440f6ecd6cae1e0609a0e773ba6b03 (patch)
treea1be675d5c79dc247952b3b26bb7e5097a6fc0d5
parent206afc147d4c921e136404eedd4395d8e07d0887 (diff)
downloadorg.eclipse.emf-ab568a880d440f6ecd6cae1e0609a0e773ba6b03.zip
org.eclipse.emf-ab568a880d440f6ecd6cae1e0609a0e773ba6b03.tar.gz
org.eclipse.emf-ab568a880d440f6ecd6cae1e0609a0e773ba6b03.tar.bz2
added test for the mapping
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.xtend76
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.java188
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XPackageMapping.java2
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.xtend2
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java2
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java2
6 files changed, 269 insertions, 3 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.xtend
new file mode 100644
index 0000000..634bd3b
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.xtend
@@ -0,0 +1,76 @@
+package org.eclipse.emf.ecore.xcore.tests.mapping
+
+import org.junit.runner.RunWith
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider
+import com.google.inject.Inject
+import org.eclipse.xtext.junit4.util.ParseHelper
+import org.eclipse.emf.ecore.xcore.XPackage
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper
+import static org.junit.Assert.*
+import org.junit.Test
+import org.eclipse.emf.ecore.xcore.XClass
+import org.eclipse.emf.ecore.xcore.XStructuralFeature
+import org.eclipse.emf.ecore.xcore.XOperation
+
+@RunWith(typeof(XtextRunner))
+@InjectWith(typeof(XcoreInjectorProvider))
+class XcoreMapperTest {
+
+ @Inject
+ ParseHelper<XPackage> parser
+
+ @Inject
+ extension XcoreMapper mapper
+
+ @Test
+ def testMapping() {
+ val pack = parser.parse('''
+ package foo.bar
+
+ type String wraps java.lang.String
+
+ class X {
+ attr String name
+ refers Y reference
+ }
+
+ class Y extends X {
+ op String toString(X x) {
+ return null
+ }
+ }
+ ''')
+ assertNotNull(pack.mapping.EPackage)
+ assertEquals(pack.mapping.getEPackage,pack.mapping.genPackage.ecorePackage)
+ assertEquals(pack,pack.mapping.genPackage.toXcoreMapping.xcoreElement)
+ assertEquals(pack,pack.mapping.EPackage.toXcoreMapping.xcoreElement)
+
+ for (clazz : pack.classifiers.filter(typeof(XClass))) {
+ assertNotNull(clazz.mapping.eclass)
+ assertEquals(clazz.mapping.eclass,clazz.mapping.genClass.ecoreClass)
+ assertEquals(clazz,clazz.mapping.genClass.toXcoreMapping.xcoreElement)
+ assertEquals(clazz,clazz.mapping.eclass.toXcoreMapping.xcoreElement)
+
+ for (member : clazz.members) {
+ switch member {
+ XStructuralFeature :{
+ assertNotNull(member.mapping.EStructuralFeature)
+ assertEquals(member.mapping.EStructuralFeature, member.mapping.genFeature.ecoreFeature)
+ assertEquals(member,member.mapping.EStructuralFeature.toXcoreMapping.xcoreElement)
+ assertEquals(member,member.mapping.genFeature.toXcoreMapping.xcoreElement)
+ //TODO jvm stuff
+ }
+ XOperation :{
+ assertNotNull(member.mapping.EOperation)
+ assertEquals(member.mapping.EOperation, member.mapping.genOperation.ecoreOperation)
+ assertEquals(member,member.mapping.EOperation.toXcoreMapping.xcoreElement)
+ assertEquals(member,member.mapping.genOperation.toXcoreMapping.xcoreElement)
+ //TODO jvm stuff
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.java
new file mode 100644
index 0000000..d24182f
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/mapping/XcoreMapperTest.java
@@ -0,0 +1,188 @@
+package org.eclipse.emf.ecore.xcore.tests.mapping;
+
+import com.google.inject.Inject;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+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.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XClassifier;
+import org.eclipse.emf.ecore.xcore.XMember;
+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.XcoreInjectorProvider;
+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.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.util.ParseHelper;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(XcoreInjectorProvider.class)
+public class XcoreMapperTest {
+
+ @Inject
+ private ParseHelper<XPackage> parser;
+
+ @Inject
+ private XcoreMapper mapper;
+
+ @Test
+ public void testMapping() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo.bar");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("type String wraps java.lang.String");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class X {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("attr String name");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("refers Y reference");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class Y extends X {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op String toString(X x) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return null");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ XPackageMapping _mapping = this.mapper.getMapping(pack);
+ EPackage _ePackage = _mapping.getEPackage();
+ Assert.assertNotNull(_ePackage);
+ XPackageMapping _mapping_1 = this.mapper.getMapping(pack);
+ EPackage _ePackage_1 = _mapping_1.getEPackage();
+ XPackageMapping _mapping_2 = this.mapper.getMapping(pack);
+ GenPackage _genPackage = _mapping_2.getGenPackage();
+ EPackage _ecorePackage = _genPackage.getEcorePackage();
+ Assert.assertEquals(_ePackage_1, _ecorePackage);
+ XPackageMapping _mapping_3 = this.mapper.getMapping(pack);
+ GenPackage _genPackage_1 = _mapping_3.getGenPackage();
+ ToXcoreMapping _xcoreMapping = this.mapper.getToXcoreMapping(_genPackage_1);
+ XNamedElement _xcoreElement = _xcoreMapping.getXcoreElement();
+ Assert.assertEquals(pack, _xcoreElement);
+ XPackageMapping _mapping_4 = this.mapper.getMapping(pack);
+ EPackage _ePackage_2 = _mapping_4.getEPackage();
+ ToXcoreMapping _xcoreMapping_1 = this.mapper.getToXcoreMapping(_ePackage_2);
+ XNamedElement _xcoreElement_1 = _xcoreMapping_1.getXcoreElement();
+ Assert.assertEquals(pack, _xcoreElement_1);
+ EList<XClassifier> _classifiers = pack.getClassifiers();
+ Iterable<XClass> _filter = IterableExtensions.<XClass>filter(_classifiers, org.eclipse.emf.ecore.xcore.XClass.class);
+ for (XClass clazz : _filter) {
+ {
+ XClassMapping _mapping_5 = this.mapper.getMapping(clazz);
+ EClass _eclass = _mapping_5.getEclass();
+ Assert.assertNotNull(_eclass);
+ XClassMapping _mapping_6 = this.mapper.getMapping(clazz);
+ EClass _eclass_1 = _mapping_6.getEclass();
+ XClassMapping _mapping_7 = this.mapper.getMapping(clazz);
+ GenClass _genClass = _mapping_7.getGenClass();
+ EClass _ecoreClass = _genClass.getEcoreClass();
+ Assert.assertEquals(_eclass_1, _ecoreClass);
+ XClassMapping _mapping_8 = this.mapper.getMapping(clazz);
+ GenClass _genClass_1 = _mapping_8.getGenClass();
+ ToXcoreMapping _xcoreMapping_2 = this.mapper.getToXcoreMapping(_genClass_1);
+ XNamedElement _xcoreElement_2 = _xcoreMapping_2.getXcoreElement();
+ Assert.assertEquals(clazz, _xcoreElement_2);
+ XClassMapping _mapping_9 = this.mapper.getMapping(clazz);
+ EClass _eclass_2 = _mapping_9.getEclass();
+ ToXcoreMapping _xcoreMapping_3 = this.mapper.getToXcoreMapping(_eclass_2);
+ XNamedElement _xcoreElement_3 = _xcoreMapping_3.getXcoreElement();
+ Assert.assertEquals(clazz, _xcoreElement_3);
+ EList<XMember> _members = clazz.getMembers();
+ for (XMember member : _members) {
+ final XMember member_1 = member;
+ boolean matched = false;
+ if (!matched) {
+ if (member_1 instanceof XStructuralFeature) {
+ final XStructuralFeature member_2 = (XStructuralFeature) member_1;
+ matched=true;
+ {
+ XFeatureMapping _mapping_10 = this.mapper.getMapping(member_2);
+ EStructuralFeature _eStructuralFeature = _mapping_10.getEStructuralFeature();
+ Assert.assertNotNull(_eStructuralFeature);
+ XFeatureMapping _mapping_11 = this.mapper.getMapping(member_2);
+ EStructuralFeature _eStructuralFeature_1 = _mapping_11.getEStructuralFeature();
+ XFeatureMapping _mapping_12 = this.mapper.getMapping(member_2);
+ GenFeature _genFeature = _mapping_12.getGenFeature();
+ EStructuralFeature _ecoreFeature = _genFeature.getEcoreFeature();
+ Assert.assertEquals(_eStructuralFeature_1, _ecoreFeature);
+ XFeatureMapping _mapping_13 = this.mapper.getMapping(member_2);
+ EStructuralFeature _eStructuralFeature_2 = _mapping_13.getEStructuralFeature();
+ ToXcoreMapping _xcoreMapping_4 = this.mapper.getToXcoreMapping(_eStructuralFeature_2);
+ XNamedElement _xcoreElement_4 = _xcoreMapping_4.getXcoreElement();
+ Assert.assertEquals(member_2, _xcoreElement_4);
+ XFeatureMapping _mapping_14 = this.mapper.getMapping(member_2);
+ GenFeature _genFeature_1 = _mapping_14.getGenFeature();
+ ToXcoreMapping _xcoreMapping_5 = this.mapper.getToXcoreMapping(_genFeature_1);
+ XNamedElement _xcoreElement_5 = _xcoreMapping_5.getXcoreElement();
+ Assert.assertEquals(member_2, _xcoreElement_5);
+ }
+ }
+ }
+ if (!matched) {
+ if (member_1 instanceof XOperation) {
+ final XOperation member_3 = (XOperation) member_1;
+ matched=true;
+ {
+ XOperationMapping _mapping_15 = this.mapper.getMapping(member_3);
+ EOperation _eOperation = _mapping_15.getEOperation();
+ Assert.assertNotNull(_eOperation);
+ XOperationMapping _mapping_16 = this.mapper.getMapping(member_3);
+ EOperation _eOperation_1 = _mapping_16.getEOperation();
+ XOperationMapping _mapping_17 = this.mapper.getMapping(member_3);
+ GenOperation _genOperation = _mapping_17.getGenOperation();
+ EOperation _ecoreOperation = _genOperation.getEcoreOperation();
+ Assert.assertEquals(_eOperation_1, _ecoreOperation);
+ XOperationMapping _mapping_18 = this.mapper.getMapping(member_3);
+ EOperation _eOperation_2 = _mapping_18.getEOperation();
+ ToXcoreMapping _xcoreMapping_6 = this.mapper.getToXcoreMapping(_eOperation_2);
+ XNamedElement _xcoreElement_6 = _xcoreMapping_6.getXcoreElement();
+ Assert.assertEquals(member_3, _xcoreElement_6);
+ XOperationMapping _mapping_19 = this.mapper.getMapping(member_3);
+ GenOperation _genOperation_1 = _mapping_19.getGenOperation();
+ ToXcoreMapping _xcoreMapping_7 = this.mapper.getToXcoreMapping(_genOperation_1);
+ XNamedElement _xcoreElement_7 = _xcoreMapping_7.getXcoreElement();
+ Assert.assertEquals(member_3, _xcoreElement_7);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
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
index 08d78ac..56c6f1c 100644
--- 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
@@ -8,7 +8,7 @@ public class XPackageMapping extends AbstractMapping
private EPackage ePackage;
private GenPackage genPackage;
- public EPackage getePackage()
+ public EPackage getEPackage()
{
return ePackage;
}
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
index 889799a..5572303 100644
--- 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
@@ -19,7 +19,7 @@ class XcoreGenmodelBuilder {
@Inject extension XcoreMapper mapper
def getGenModel(XPackage pack) {
- val ePackage = pack.mapping.getePackage
+ val ePackage = pack.mapping.getEPackage
val genModel = GenModelFactory::eINSTANCE.createGenModel();
genModel.initialize(Collections::singleton(ePackage));
pack.eResource.getContents().add(1, genModel);
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 48f967f..edda8f5 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
@@ -230,6 +230,8 @@ public class XcoreJvmInferrer
{
List<JvmTypeReference> arguments = getJvmTypeReferences(eGenericType.getETypeArguments(), context);
String instanceTypeName = eClassifier.getInstanceTypeName();
+ if (instanceTypeName == null)
+ return null;
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/util/XcoreGenmodelBuilder.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/XcoreGenmodelBuilder.java
index 9211767..f3fe0b8 100644
--- 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
@@ -38,7 +38,7 @@ public class XcoreGenmodelBuilder {
public void getGenModel(final XPackage pack) {
{
XPackageMapping _mapping = this.mapper.getMapping(pack);
- EPackage _ePackage = _mapping.getePackage();
+ EPackage _ePackage = _mapping.getEPackage();
final EPackage ePackage = _ePackage;
GenModel _createGenModel = GenModelFactory.eINSTANCE.createGenModel();
final GenModel genModel = _createGenModel;