Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwagelaar2013-12-30 06:18:07 -0500
committerdwagelaar2013-12-30 06:18:07 -0500
commit56a6f71d93be08b26232a114bb2858c018c53291 (patch)
treef39d12da470ddd2a37d992f7999e25c879e411f8 /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse
parent50dd2e610bfaf86a34bdd52dd1bfab27afc0575f (diff)
downloadorg.eclipse.atl-56a6f71d93be08b26232a114bb2858c018c53291.tar.gz
org.eclipse.atl-56a6f71d93be08b26232a114bb2858c018c53291.tar.xz
org.eclipse.atl-56a6f71d93be08b26232a114bb2858c018c53291.zip
Convert EEnum types to EnumLiteral.class for field/operation lookup.
Use '#literal' instead of 'EnumLiteral(literal)' as EnumLiteral String representation. 423597: Support for eEnum instances https://bugs.eclipse.org/bugs/show_bug.cgi?id=423597
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java59
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EnumLiteral.java7
2 files changed, 55 insertions, 11 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
index 0abd8106..2e84a56f 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
@@ -46,6 +46,7 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreSwitch;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.m2m.atl.common.ATLLogger;
@@ -70,6 +71,51 @@ import org.eclipse.m2m.atl.emftvm.trace.TracePackage;
public final class EMFTVMUtil {
/**
+ * Returns the registry type of the switched object.
+ *
+ * @author <a href="dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+ public static class RegistryTypeSwitch extends EcoreSwitch<Object> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object defaultCase(EObject object) {
+ throw new IllegalArgumentException("Unsupported type: " + object);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseEClass(EClass object) {
+ return object;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseEClassifier(EClassifier object) {
+ final Class<?> ic = object.getInstanceClass();
+ if (ic == null) {
+ throw new IllegalArgumentException(String.format("Primitive EMF type without instance class %s", object));
+ }
+ return ic;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseEEnum(EEnum object) {
+ return EnumLiteral.class;
+ }
+
+ }
+
+ /**
* Native type namespace.
*/
public static final String NATIVE = "#native";
@@ -111,6 +157,11 @@ public final class EMFTVMUtil {
*/
private static final Map<Class<?>, Map<Integer, Method>> METHOD_CACHE = new WeakHashMap<Class<?>, Map<Integer, Method>>();
+ /**
+ * Singleton {@link RegistryTypeSwitch} instance.
+ */
+ private static final RegistryTypeSwitch REGISTRY_TYPE_SWITCH = new RegistryTypeSwitch();
+
private static Metamodel ecoreMetamodel;
private static Metamodel emfTvmMetamodel;
private static Metamodel traceMetamodel;
@@ -177,12 +228,8 @@ public final class EMFTVMUtil {
* if type is a primitive EMF type without instance class
*/
public static Object getRegistryType(final Object type) throws IllegalArgumentException {
- if (type instanceof EClassifier && !(type instanceof EClass)) {
- final Class<?> ic = ((EClassifier) type).getInstanceClass();
- if (ic == null) {
- throw new IllegalArgumentException(String.format("Primitive EMF type without instance class %s", type));
- }
- return ic;
+ if (type instanceof EClassifier) {
+ return REGISTRY_TYPE_SWITCH.doSwitch((EClassifier) type);
}
return type;
}
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EnumLiteral.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EnumLiteral.java
index 5bf6a734..591eb306 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EnumLiteral.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EnumLiteral.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Vrije Universiteit Brussel.
+ * Copyright (c) 2011-2013 Dennis Wagelaar, Vrije Universiteit Brussel.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,11 +49,8 @@ public final class EnumLiteral implements Serializable {
*/
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getSimpleName());
- buf.append('(');
+ StringBuffer buf = new StringBuffer("#");
buf.append(getName());
- buf.append(')');
return buf.toString();
}

Back to the top