summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Eysholdt2011-08-09 12:16:50 (EDT)
committerEd Merks2011-08-09 12:17:17 (EDT)
commit1c73a6df9b032fe8108def2a0fc76de10f962398 (patch)
tree61b3d1d6970133a685580e3a1852a15407eba14a
parente93af52f643f7c858ee563a091c5bce0e00b8161 (diff)
downloadorg.eclipse.emf-1c73a6df9b032fe8108def2a0fc76de10f962398.zip
org.eclipse.emf-1c73a6df9b032fe8108def2a0fc76de10f962398.tar.gz
org.eclipse.emf-1c73a6df9b032fe8108def2a0fc76de10f962398.tar.bz2
improved formatting of GenModels and EPackages
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/GenModelFormatter.java102
-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.java4
4 files changed, 113 insertions, 11 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/GenModelFormatter.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/GenModelFormatter.java
new file mode 100644
index 0000000..50713b3
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/GenModelFormatter.java
@@ -0,0 +1,102 @@
+package org.eclipse.emf.ecore.xcore.tests;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenDataType;
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.codegen.ecore.genmodel.util.GenModelSwitch;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EcoreSwitch;
+import org.eclipse.xtext.EcoreUtil2;
+
+public class GenModelFormatter extends EObjectFormatter
+{
+
+ private static class EcoreTitleSwitch extends EcoreSwitch<String>
+ {
+ @Override
+ public String caseENamedElement(ENamedElement object)
+ {
+ EPackage pkg = EcoreUtil2.getContainerOfType(object, EPackage.class);
+ StringBuilder result = new StringBuilder();
+ if (pkg != object)
+ {
+ result.append(pkg.getName());
+ result.append("::");
+ }
+ result.append(object.getName());
+ return result.toString();
+ }
+
+ @Override
+ public String caseEStructuralFeature(EStructuralFeature object)
+ {
+ StringBuilder result = new StringBuilder();
+ result.append(doSwitch(object.getEContainingClass()));
+ result.append("::");
+ result.append(object.getName());
+ return result.toString();
+ }
+ }
+
+ private static class GenModelTitleSwitch extends GenModelSwitch<String>
+ {
+ @Override
+ public String caseGenClass(GenClass object)
+ {
+ return object.getQualifiedInterfaceName();
+ }
+
+ @Override
+ public String caseGenDataType(GenDataType object)
+ {
+ return object.getQualifiedInstanceClassName();
+ }
+
+ @Override
+ public String caseGenFeature(GenFeature object)
+ {
+ StringBuilder result = new StringBuilder();
+ result.append(doSwitch(object.getGenClass()));
+ result.append(".");
+ result.append(object.getName());
+ return result.toString();
+ }
+
+ @Override
+ public String caseGenModel(GenModel object)
+ {
+ return object.getModelName();
+ }
+
+ @Override
+ public String caseGenPackage(GenPackage object)
+ {
+ return object.getQualifiedPackageInterfaceName();
+ }
+
+ }
+
+ @Override
+ protected String formatCrossRefValue(EObject object, EReference feature, EObject value)
+ {
+ if (value != null && !value.eIsProxy())
+ {
+ String title = null;
+ if (value.eClass().getEPackage() == EcorePackage.eINSTANCE)
+ title = new EcoreTitleSwitch().doSwitch(value);
+ else if (value.eClass().getEPackage() == GenModelPackage.eINSTANCE)
+ title = new GenModelTitleSwitch().doSwitch(value);
+ if (title != null)
+ return value.eClass().getName() + " " + title;
+ }
+ return super.formatCrossRefValue(object, feature, value);
+ }
+}
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 6795b2e..649c5cd 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
@@ -9,8 +9,8 @@ class X
notify = 'false'
createChild = 'false'
propertySortChoices = 'true'
- genClass -> GenClass /1/foo/X
- ecoreFeature -> EReference /2/X/x
+ genClass -> GenClass foo.X
+ ecoreFeature -> EReference foo::X::x
}
--- */
refers X x opposite y
@@ -20,8 +20,8 @@ class X
notify = 'false'
createChild = 'false'
propertySortChoices = 'true'
- genClass -> GenClass /1/foo/X
- ecoreFeature -> EReference /2/X/y
+ genClass -> GenClass foo.X
+ ecoreFeature -> EReference foo::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 b9497f1..1db8be8 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
@@ -4,16 +4,16 @@
GenPackage {
prefix = 'Foo'
disposableProviderFactory = 'true'
- ecorePackage -> EPackage /2
- genModel -> GenModel /1
+ ecorePackage -> EPackage foo
+ genModel -> GenModel Foo
genClasses = [
GenClass {
- genPackage -> GenPackage /1/foo
- ecoreClass -> EClass /2/Bar
+ genPackage -> GenPackage foo.FooPackage
+ ecoreClass -> EClass foo::Bar
}
]
genClassifiers -> [
- GenClass /1/foo/Bar
+ GenClass 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 cfed586..7351dd2 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
@@ -5,7 +5,7 @@ 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.EObjectFormatter;
+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;
@@ -32,7 +32,7 @@ public class XcoreGenModelTest extends AbstractParameterizedXtextTest
{
EcoreUtil.resolveAll(resource);
GenBase gen = mapper.getGen((XNamedElement) getEObjectAtOffset());
- return new EObjectFormatter().resolveCrossReferences().format(gen);
+ return new GenModelFormatter().resolveCrossReferences().format(gen);
}
}