summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Eysholdt2011-08-09 12:46:32 (EDT)
committerEd Merks2011-08-09 12:46:32 (EDT)
commitb97bfc6d07d526d07d22a1642c4631dbf0fe46a3 (patch)
tree6db8e20fa4439534e427a2fa9957c34dd6650778
parentea4a54f2a7e0097972034323b5523090b6f648c6 (diff)
downloadorg.eclipse.emf-b97bfc6d07d526d07d22a1642c4631dbf0fe46a3.zip
org.eclipse.emf-b97bfc6d07d526d07d22a1642c4631dbf0fe46a3.tar.gz
org.eclipse.emf-b97bfc6d07d526d07d22a1642c4631dbf0fe46a3.tar.bz2
added tests for Ecore inference
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage1.xcore60
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage2.xcore20
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreGenModelTest.java38
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/mappings/XcoreMapper.java17
4 files changed, 135 insertions, 0 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage1.xcore
new file mode 100644
index 0000000..6e3198e
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage1.xcore
@@ -0,0 +1,60 @@
+// XPECT noValidationErrors
+
+/* XPECT eNamedElement ---
+ EPackage {
+ name = 'foo'
+ nsURI = 'foo'
+ nsPrefix = 'foo'
+ eFactoryInstance -> EFactory #//
+ eClassifiers = [
+ EClass {
+ name = 'Class1'
+ }
+ EClass {
+ name = 'Class2'
+ }
+ EDataType {
+ name = 'MyString1'
+ instanceClassName = 'java.lang.String'
+ }
+ EDataType {
+ name = 'MyString2'
+ instanceClassName = 'java.lang.String'
+ }
+ EEnum {
+ name = 'En1'
+ eLiterals = [
+ EEnumLiteral {
+ name = 'lit1'
+ }
+ EEnumLiteral {
+ name = 'lit2'
+ }
+ ]
+ }
+ EEnum {
+ name = 'En2'
+ eLiterals = [
+ EEnumLiteral {
+ name = 'lit1'
+ }
+ EEnumLiteral {
+ name = 'lit2'
+ }
+ ]
+ }
+ ]
+ }
+---
+*/
+
+package foo
+
+class Class1 {}
+class Class2 {}
+
+type MyString1 wraps java.lang.String
+type MyString2 wraps java.lang.String
+
+enum En1 { lit1, lit2 }
+enum En2 { lit1, lit2 } \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage2.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage2.xcore
new file mode 100644
index 0000000..66525ac
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/GenPackage2.xcore
@@ -0,0 +1,20 @@
+// XPECT noValidationErrors
+
+/* XPECT eNamedElement ---
+ EPackage {
+ name = 'foo'
+ nsURI = 'foo'
+ nsPrefix = 'foo'
+ eFactoryInstance -> EFactory #//
+ eClassifiers = [
+ EClass {
+ name = 'Bar'
+ }
+ ]
+ }
+---
+*/
+
+package foo
+
+class Bar {} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreGenModelTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreGenModelTest.java
new file mode 100644
index 0000000..8709397
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreGenModelTest.java
@@ -0,0 +1,38 @@
+package org.eclipse.emf.ecore.xcore.tests.ecore;
+
+import org.eclipse.emf.ecore.ENamedElement;
+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.mappings.XcoreMapper;
+import org.eclipse.emf.ecore.xcore.tests.GenModelFormatter;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest;
+import org.eclipse.xtext.junit4.parameterized.ResourceURIs;
+import org.eclipse.xtext.resource.XtextResource;
+import org.junit.Test;
+
+import com.google.inject.Inject;
+
+@InjectWith(XcoreInjectorProvider.class)
+@ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/ecore", fileExtensions = "xcore")
+public class XcoreGenModelTest extends AbstractParameterizedXtextTest
+{
+
+ public XcoreGenModelTest(XtextResource resource, int offset, String[] params)
+ {
+ super(resource, offset, params);
+ }
+
+ @Inject
+ private XcoreMapper mapper;
+
+ @Test
+ public String eNamedElement()
+ {
+ EcoreUtil.resolveAll(resource);
+ ENamedElement gen = mapper.getEcore((XNamedElement) getEObjectAtOffset());
+ return new GenModelFormatter().resolveCrossReferences().format(gen);
+ }
+
+}
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
index 9ac32ff..a4fcd4f 100644
--- 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
@@ -2,6 +2,8 @@ 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.EModelElement;
+import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xcore.XClass;
@@ -42,6 +44,21 @@ public class XcoreMapper
return lazyCreateMapping(derivedElement, ToXcoreMapping.class);
}
+ public ENamedElement getEcore(XNamedElement namedElement) {
+ if (namedElement instanceof XPackage) {
+ return getMapping((XPackage)namedElement).getEPackage();
+ } else if (namedElement instanceof XClass) {
+ return getMapping((XClass)namedElement).getEclass();
+ } else if (namedElement instanceof XDataType) {
+ return getMapping((XDataType)namedElement).getEDataType();
+ } else if (namedElement instanceof XStructuralFeature) {
+ return getMapping((XStructuralFeature)namedElement).getEStructuralFeature();
+ } else if (namedElement instanceof XOperation) {
+ return getMapping((XOperation)namedElement).getEOperation();
+ }
+ return null;
+ }
+
public GenBase getGen(XNamedElement namedElement) {
if (namedElement instanceof XPackage) {
return getMapping((XPackage)namedElement).getGenPackage();