diff options
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
3 files changed, 556 insertions, 521 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 bcdbaa37..80468cc2 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 @@ -68,7 +68,7 @@ import org.eclipse.m2m.atl.emftvm.trace.TracePackage; /** * EMFTVM static utility methods. - * + * * @author <a href="mailto:dennis.wagelaar@vub.ac.be">Dennis Wagelaar</a> * @author <a href="mailto:william.piers@obeo.fr">William Piers</a> */ @@ -76,7 +76,7 @@ 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> { @@ -131,7 +131,7 @@ public final class EMFTVMUtil { /** * Type namespace matching pattern. - * + * * @see #NS_DELIM */ public static final Pattern DELIM_PATTERN = Pattern.compile(NS_DELIM); @@ -153,7 +153,7 @@ public final class EMFTVMUtil { /** * Cache used to store native Java methods. - * + * * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a> * @author <a href="mailto:william.piers@obeo.fr">William Piers</a> * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a> @@ -168,7 +168,7 @@ public final class EMFTVMUtil { /** * Cache used to store the found root methods for native Java methods. - * + * * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a> * @author <a href="mailto:william.piers@obeo.fr">William Piers</a> * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a> @@ -182,6 +182,11 @@ public final class EMFTVMUtil { */ private static final RegistryTypeSwitch REGISTRY_TYPE_SWITCH = new RegistryTypeSwitch(); + /** + * {@link Map#toString()} evaluation cut-off number. + */ + private static final int CUT_OFF = 31; + private static Metamodel ecoreMetamodel; private static Metamodel emfTvmMetamodel; private static Metamodel traceMetamodel; @@ -199,7 +204,7 @@ public final class EMFTVMUtil { /** * Returns the name of <code>type</code>, for printing. - * + * * @param env * the current {@link ExecEnv} * @param type @@ -225,7 +230,7 @@ public final class EMFTVMUtil { /** * Returns the names of <code>types</code>, for printing. - * + * * @param env * the current {@link ExecEnv}. * @param types @@ -235,7 +240,7 @@ public final class EMFTVMUtil { public static String getTypeNames(final ExecEnv env, final Object[] types) { final StringBuffer names = new StringBuffer(); boolean notFirst = false; - for (Object type : types) { + for (final Object type : types) { if (notFirst) { names.append(", "); } @@ -247,7 +252,7 @@ public final class EMFTVMUtil { /** * Returns the type object to use for the registry. - * + * * @param type * the type object * @return the type object to use for the registry @@ -263,7 +268,7 @@ public final class EMFTVMUtil { /** * Returns the singleton instance of the Ecore metamodel. - * + * * @return the singleton instance of the Ecore metamodel */ public static synchronized Metamodel getEcoreMetamodel() { @@ -276,7 +281,7 @@ public final class EMFTVMUtil { /** * Returns the singleton instance of the EMFTVM metamodel. - * + * * @return the singleton instance of the EMFTVM metamodel */ public static synchronized Metamodel getEmfTvmMetamodel() { @@ -289,7 +294,7 @@ public final class EMFTVMUtil { /** * Returns the singleton instance of the Trace metamodel. - * + * * @return the singleton instance of the Trace metamodel */ public static synchronized Metamodel getTraceMetamodel() { @@ -302,7 +307,7 @@ public final class EMFTVMUtil { /** * Finds all instances of type in the registered input/inout models. - * + * * @param type * the type * @param env @@ -311,10 +316,10 @@ public final class EMFTVMUtil { */ public static LazyList<EObject> findAllInstances(final EClass type, final ExecEnv env) { LazyList<EObject> allInst = new LazyList<EObject>(); - for (Model model : env.getInputModels().values()) { + for (final Model model : env.getInputModels().values()) { allInst = allInst.union(model.allInstancesOf(type)); } - for (Model model : env.getInoutModels().values()) { + for (final Model model : env.getInoutModels().values()) { allInst = allInst.union(model.allInstancesOf(type)); } return allInst; @@ -322,7 +327,7 @@ public final class EMFTVMUtil { /** * Finds all instances of type in the given model. - * + * * @param modelname * the model name * @param type @@ -345,7 +350,7 @@ public final class EMFTVMUtil { /** * Offers an alternative to the default <code>toString()</code> method. Uses <code>env</code> to determine the containing model of * types. Compensates for {@link EObject}'s notoriously bad <code>toString()</code>. - * + * * @param object * @param env * @return the string representation of <code>object</code>. @@ -383,6 +388,18 @@ public final class EMFTVMUtil { return new StringBuffer().append('\'').append(object.toString()).append('\'').toString(); } else if (object instanceof LazyCollection<?>) { return ((LazyCollection<?>) object).asString(env); + } else if (object instanceof Map<?,?>) { + final Map<?, ?> map = (Map<?, ?>) object; + final StringBuilder buf = new StringBuilder("Map{"); + appendMapEntries(env, map, buf); + buf.append('}'); + return buf.toString(); + } else if (object instanceof Tuple) { + final Tuple tuple = (Tuple) object; + final StringBuilder buf = new StringBuilder("Tuple{"); + appendMapEntries(env, tuple.asMap(), buf); + buf.append('}'); + return buf.toString(); } else if (object != null) { return object.toString(); } else { @@ -391,9 +408,35 @@ public final class EMFTVMUtil { } /** + * Appends the map entries to the string builder. + * + * @param env + * the current {@link ExecEnv} + * @param map + * the {@link Map} for which to append the entries + * @param buf + * the {@link StringBuilder} to append to + */ + private static void appendMapEntries(final ExecEnv env, final Map<?, ?> map, final StringBuilder buf) { + int index = 0; + for (final Map.Entry<?, ?> entry : map.entrySet()) { + if (index > CUT_OFF) { + buf.append(", ..."); + break; + } + if (index++ > 0) { + buf.append(", "); + } + buf.append(EMFTVMUtil.toPrettyString(entry.getKey(), env)); + buf.append('='); + buf.append(EMFTVMUtil.toPrettyString(entry.getValue(), env)); + } + } + + /** * Offers an alternative to the default <code>toString()</code> method. Uses <code>env</code> to determine the containing model of * types. Compensates for {@link EObject}'s notoriously bad <code>toString()</code>. - * + * * @param coll * @param env * @return the string representation of <code>coll</code>. @@ -402,7 +445,7 @@ public final class EMFTVMUtil { final StringBuffer sb = new StringBuffer(); sb.append('['); boolean first = true; - for (Object object : coll) { + for (final Object object : coll) { if (!first) { sb.append(", "); } @@ -416,7 +459,7 @@ public final class EMFTVMUtil { /** * Offers an alternative to the default <code>toString()</code> method. Uses <code>env</code> to determine the containing model of * types. Compensates for {@link EObject}'s notoriously bad <code>toString()</code>. - * + * * @param array * @param env * @return the string representation of <code>coll</code>. @@ -425,7 +468,7 @@ public final class EMFTVMUtil { final StringBuffer sb = new StringBuffer(); sb.append('['); boolean first = true; - for (Object object : array) { + for (final Object object : array) { if (!first) { sb.append(", "); } @@ -438,7 +481,7 @@ public final class EMFTVMUtil { /** * Retrieves the value of <code>eo.sf</code>. Checks that <code>eo</code> is not in an output model. - * + * * @param env * the current {@link ExecEnv} * @param eo @@ -457,7 +500,7 @@ public final class EMFTVMUtil { /** * Retrieves the value of <code>eo.sf</code>. - * + * * @param env * the current {@link ExecEnv} * @param eo @@ -504,7 +547,7 @@ public final class EMFTVMUtil { /** * Converts <code>value</code> to an EMFTVM value. - * + * * @param env * the current {@link ExecEnv} * @param eo @@ -556,7 +599,7 @@ public final class EMFTVMUtil { /** * Sets the <code>value</code> of <code>eo.sf</code>. - * + * * @param env * the current {@link ExecEnv} * @param eo @@ -589,7 +632,7 @@ public final class EMFTVMUtil { /** * Adds the <code>value</code> of <code>eo.sf</code>. - * + * * @param env * @param eo * @param sf @@ -624,7 +667,7 @@ public final class EMFTVMUtil { /** * Removes the <code>value</code> from <code>eo.sf</code>. - * + * * @param env * @param eo * @param sf @@ -664,7 +707,7 @@ public final class EMFTVMUtil { /** * Sets the <code>value</code> of <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity <= 1. - * + * * @param env * @param eo * @param sf @@ -714,7 +757,7 @@ public final class EMFTVMUtil { /** * Sets the <code>value</code> of <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity > 1. - * + * * @param env * @param eo * @param sf @@ -727,7 +770,7 @@ public final class EMFTVMUtil { if (!values.isEmpty()) { if (sf instanceof EReference) { final List<Object> vCopy = new ArrayList<Object>(values); - for (EObject v : (List<? extends EObject>) vCopy) { + for (final EObject v : (List<? extends EObject>) vCopy) { removeRefValue((EReference) sf, eo, values, v); } } else { @@ -739,7 +782,7 @@ public final class EMFTVMUtil { /** * Adds <code>value</code> to <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity > 1. - * + * * @param env * @param eo * @param sf @@ -768,7 +811,7 @@ public final class EMFTVMUtil { /** * Adds all <code>value</code> elements to <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity > 1. - * + * * @param env * @param eo * @param sf @@ -786,12 +829,12 @@ public final class EMFTVMUtil { final Collection<?> srcValues = ref.isContainment() ? new ArrayList<Object>(value) : value; if (index > -1) { int currentIndex = index; - for (Object v : srcValues) { + for (final Object v : srcValues) { checkValueTypeIsEObject(env, ref, v); addRefValue(env, ref, eo, values, (EObject) v, currentIndex++, allowInterModelReferences); } } else { - for (Object v : srcValues) { + for (final Object v : srcValues) { checkValueTypeIsEObject(env, ref, v); addRefValue(env, ref, eo, values, (EObject) v, -1, allowInterModelReferences); } @@ -802,11 +845,11 @@ public final class EMFTVMUtil { final EEnum eEnum = (EEnum) sfType; if (index > -1) { int currentIndex = index; - for (Object v : value) { + for (final Object v : value) { addEnumValue(eEnum, values, v, currentIndex++); } } else { - for (Object v : value) { + for (final Object v : value) { addEnumValue(eEnum, values, v, -1); } } @@ -820,7 +863,7 @@ public final class EMFTVMUtil { /** * Checks that the value is an instance of {@link EObject}. - * + * * @param env * the current {@link ExecEnv} * @param ref @@ -838,7 +881,7 @@ public final class EMFTVMUtil { /** * Removes the <code>value</code> from <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity > 1. - * + * * @param env * @param eo * @param sf @@ -864,7 +907,7 @@ public final class EMFTVMUtil { /** * Removes all elements of <code>value</code> from <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity > 1. - * + * * @param env * @param eo * @param sf @@ -877,7 +920,7 @@ public final class EMFTVMUtil { if (sf instanceof EReference) { final EReference ref = (EReference) sf; final Collection<?> srcValues = ref.isContainment() ? new ArrayList<Object>(value) : value; - for (Object v : srcValues) { + for (final Object v : srcValues) { checkValueTypeIsEObject(env, ref, v); removeRefValue(ref, eo, values, (EObject) v); } @@ -885,7 +928,7 @@ public final class EMFTVMUtil { final EClassifier sfType = sf.getEType(); if (sfType instanceof EEnum) { final EEnum eEnum = (EEnum) sfType; - for (Object v : value) { + for (final Object v : value) { removeEnumValue(eEnum, values, v); } } else { @@ -896,7 +939,7 @@ public final class EMFTVMUtil { /** * Adds <code>v</code> to <code>values</code>. Performs enumerator conversion. - * + * * @param eEnum * The enumeration type * @param values @@ -920,7 +963,7 @@ public final class EMFTVMUtil { /** * Removes <code>v</code> from <code>values</code>. Performs enumerator conversion. - * + * * @param eEnum * The enumeration type * @param values @@ -936,7 +979,7 @@ public final class EMFTVMUtil { /** * Adds <code>v</code> to <code>values</code>. Performs constraint checking on <code>v</code>. - * + * * @param env * @param ref * The reference type @@ -968,7 +1011,7 @@ public final class EMFTVMUtil { /** * Removes <code>v</code> from <code>values</code>. Performs constraint checking on <code>v</code>. - * + * * @param ref * The reference type * @param eo @@ -988,7 +1031,7 @@ public final class EMFTVMUtil { /** * Updates the eResource() for <code>eo</code> and <code>v</code> where necessary - * + * * @param eo * the {@link EObject} for which an {@link EReference} has just been modified * @param v @@ -1012,7 +1055,7 @@ public final class EMFTVMUtil { /** * Checks whether the model containing <code>eo</code> allows inter-model references. - * + * * @param env * the {@link ExecEnv} in which to find the model. * @param eo @@ -1030,7 +1073,7 @@ public final class EMFTVMUtil { /** * Checks whether <code>value</code> may be assigned to <code>eo.ref</code>. - * + * * @param env * the current {@link ExecEnv} * @param eo @@ -1054,16 +1097,16 @@ public final class EMFTVMUtil { assert ev.eResource() != null; if (!allowInterModelReferences) { ATLLogger - .warning(String.format("Cannot set %s::%s to %s for %s: inter-model references are not allowed for this model", - toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), - toPrettyString(eo, env))); + .warning(String.format("Cannot set %s::%s to %s for %s: inter-model references are not allowed for this model", + toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), + toPrettyString(eo, env))); return false; } if (ref.isContainer() || ref.isContainment()) { ATLLogger - .warning(String.format("Cannot set %s::%s to %s for %s: containment references cannot span across models", - toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), - toPrettyString(eo, env))); + .warning(String.format("Cannot set %s::%s to %s for %s: containment references cannot span across models", + toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), + toPrettyString(eo, env))); return false; } final EReference opposite = ref.getEOpposite(); @@ -1082,10 +1125,10 @@ public final class EMFTVMUtil { final Model oppositeModel = env.getInputModelOf((EObject) ev.eGet(opposite)); if (oppositeModel != null) { ATLLogger - .warning(String - .format("Cannot set %s::%s to %s for %s: inter-model reference with single-valued opposite causes changes in input model %s", - toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), - toPrettyString(eo, env), env.getModelID(oppositeModel))); + .warning(String + .format("Cannot set %s::%s to %s for %s: inter-model reference with single-valued opposite causes changes in input model %s", + toPrettyString(ref.getEContainingClass(), env), ref.getName(), toPrettyString(value, env), + toPrettyString(eo, env), env.getModelID(oppositeModel))); return false; } } @@ -1096,7 +1139,7 @@ public final class EMFTVMUtil { /** * Retrieves the types of <code>args</code>. - * + * * @param args * @return the types of <code>args</code> */ @@ -1111,7 +1154,7 @@ public final class EMFTVMUtil { /** * Retrieves the type of <code>arg</code>. - * + * * @param arg * @return the type of <code>arg</code> */ @@ -1127,7 +1170,7 @@ public final class EMFTVMUtil { /** * Invokes native Java method <code>opname</code> on <code>self</code> with arguments <code>args</code>. - * + * * @param frame * the current stack frame * @param self @@ -1150,7 +1193,7 @@ public final class EMFTVMUtil { /** * Invokes native Java <code>method</code> on <code>self</code> with arguments <code>args</code>. - * + * * @param frame * the current stack frame * @param self @@ -1167,23 +1210,23 @@ public final class EMFTVMUtil { final StackFrame subFrame = frame.prepareNativeArgs(method, self, args); try { return emf2vm(frame.getEnv(), self instanceof EObject ? (EObject) self : null, method.invoke(self, args)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, e); } } /** * Invokes native Java method <code>opname</code> on <code>self</code> with argument <code>arg</code>. - * + * * @param frame * the current stack frame * @param self @@ -1206,7 +1249,7 @@ public final class EMFTVMUtil { /** * Invokes native Java <code>method</code> on <code>self</code> with argument <code>arg</code>. - * + * * @param frame * the current stack frame * @param self @@ -1231,23 +1274,23 @@ public final class EMFTVMUtil { } try { return emf2vm(frame.getEnv(), self instanceof EObject ? (EObject) self : null, method.invoke(self, arg)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, e); } } /** * Invokes native Java method <code>opname</code> on <code>self</code> without arguments. - * + * * @param frame * the current stack frame * @param self @@ -1267,7 +1310,7 @@ public final class EMFTVMUtil { /** * Invokes native Java <code>method</code> on <code>self</code> without arguments. - * + * * @param frame * the current stack frame * @param self @@ -1282,23 +1325,23 @@ public final class EMFTVMUtil { final StackFrame subFrame = frame.prepareNativeContext(method, self); try { return emf2vm(frame.getEnv(), self instanceof EObject ? (EObject) self : null, method.invoke(self)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, e); } } /** * Invokes static native Java method <code>opname</code> with arguments <code>args</code>. - * + * * @param frame * the current stack frame * @param type @@ -1315,16 +1358,16 @@ public final class EMFTVMUtil { final StackFrame subFrame = frame.prepareNativeArgs(method, args); try { return emf2vm(frame.getEnv(), null, method.invoke(type, args)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, e); } } @@ -1334,7 +1377,7 @@ public final class EMFTVMUtil { /** * Invokes static native Java method <code>opname</code> with argument <code>arg</code>. - * + * * @param frame * the current stack frame * @param type @@ -1357,16 +1400,16 @@ public final class EMFTVMUtil { } try { return emf2vm(frame.getEnv(), null, method.invoke(type, arg)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(subFrame == null ? new StackFrame(frame, method) : subFrame, e); } } @@ -1376,7 +1419,7 @@ public final class EMFTVMUtil { /** * Invokes static native Java method <code>opname</code> without arguments. - * + * * @param frame * the current stack frame * @param type @@ -1390,16 +1433,16 @@ public final class EMFTVMUtil { if (method != null) { try { return emf2vm(frame.getEnv(), null, method.invoke(type)); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { final Throwable target = e.getTargetException(); if (target instanceof VMException) { throw (VMException) target; } else { throw new VMException(new StackFrame(frame, method), target); } - } catch (VMException e) { + } catch (final VMException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new VMException(new StackFrame(frame, method), e); } } @@ -1408,7 +1451,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method. - * + * * @param context * The class of the method * @param opname @@ -1442,7 +1485,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method. - * + * * @param context * The class of the method * @param opname @@ -1476,7 +1519,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method without arguments. - * + * * @param context * The class of the method * @param opname @@ -1497,7 +1540,7 @@ public final class EMFTVMUtil { final MethodSignature sig = getMethodSignature(context, opname, isStatic); MethodCacheAccesses++; final WeakReference<Method> methodRef = METHOD_CACHE.get(sig); - Method ret = methodRef != null ? methodRef.get() : null; + final Method ret = methodRef != null ? methodRef.get() : null; if (ret != null || methodRef == NULL_METHOD_REFERENCE) { MethodCacheHits++; return ret; @@ -1508,7 +1551,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method. - * + * * @param context * The class of the method * @param opname @@ -1524,12 +1567,12 @@ public final class EMFTVMUtil { private static Method findNativeMethodInternal(final Class<?> context, final String opname, final Class<?>[] argTypes, final boolean isStatic, final MethodSignature sig) { Method ret = null; - + final Method[] methods = context.getDeclaredMethods(); METHODS: for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + final Method method = methods[i]; if ((Modifier.isStatic(method.getModifiers()) == isStatic) && method.getName().equals(opname)) { - Class<?>[] pts = method.getParameterTypes(); + final Class<?>[] pts = method.getParameterTypes(); if (pts.length == argTypes.length) { boolean ok = true; for (int j = 0; (j < pts.length) && ok; j++) { @@ -1545,19 +1588,19 @@ public final class EMFTVMUtil { } } } - + if ((ret == null) && !isStatic && (context.getSuperclass() != null)) { ret = findNativeMethodInternal(context.getSuperclass(), opname, argTypes, isStatic, sig); } else { METHOD_CACHE.put(sig, ret != null ? new WeakReference<Method>(ret) : NULL_METHOD_REFERENCE); } - + return ret; } /** * Looks for a native Java method. - * + * * @param context * The class of the method * @param opname @@ -1573,12 +1616,12 @@ public final class EMFTVMUtil { private static Method findNativeMethodInternal(final Class<?> context, final String opname, final Class<?> argType, final boolean isStatic, final MethodSignature sig) { Method ret = null; - + final Method[] methods = context.getDeclaredMethods(); METHODS: for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + final Method method = methods[i]; if ((Modifier.isStatic(method.getModifiers()) == isStatic) && method.getName().equals(opname)) { - Class<?>[] pts = method.getParameterTypes(); + final Class<?>[] pts = method.getParameterTypes(); if (pts.length == 1) { if (checkParameterType(argType, pts[0])) { ret = method; @@ -1587,19 +1630,19 @@ public final class EMFTVMUtil { } } } - + if ((ret == null) && !isStatic && (context.getSuperclass() != null)) { ret = findNativeMethodInternal(context.getSuperclass(), opname, argType, isStatic, sig); } else { METHOD_CACHE.put(sig, ret != null ? new WeakReference<Method>(ret) : NULL_METHOD_REFERENCE); } - + return ret; } /** * Looks for a native Java method without arguments. - * + * * @param context * The class of the method * @param opname @@ -1616,7 +1659,7 @@ public final class EMFTVMUtil { final Method[] methods = context.getDeclaredMethods(); METHODS: for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + final Method method = methods[i]; if ((Modifier.isStatic(method.getModifiers()) == isStatic) && method.getName().equals(opname)) { if (method.getParameterTypes().length == 0) { ret = method; @@ -1636,7 +1679,7 @@ public final class EMFTVMUtil { /** * Checks whether the parameter type is compatible with the argument type - * + * * @param argType * the invocation argument type * @param pt @@ -1674,7 +1717,7 @@ public final class EMFTVMUtil { /** * Compares 0-parameter <code>op</code> to <code>method</code>. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param method @@ -1694,7 +1737,7 @@ public final class EMFTVMUtil { /** * Compares 1-parameter <code>op</code> to <code>method</code>. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param method @@ -1724,7 +1767,7 @@ public final class EMFTVMUtil { /** * Compares N-parameter <code>op</code> to <code>method</code>. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param method @@ -1759,7 +1802,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method without arguments. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param self @@ -1774,7 +1817,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method with one argument. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param self @@ -1792,7 +1835,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java method with multiple arguments. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param self @@ -1810,7 +1853,7 @@ public final class EMFTVMUtil { /** * Returns the superclass as well as super-interfaces for <code>type</code>. - * + * * @param type * the type for which to return supertypes * @return the superclass as well as super-interfaces for <code>type</code> @@ -1835,7 +1878,7 @@ public final class EMFTVMUtil { /** * Compares 0-parameter <code>method1</code> to <code>method2</code>. - * + * * @param method1 * the previously found method * @param method2 @@ -1858,7 +1901,7 @@ public final class EMFTVMUtil { /** * Compares 1-parameter <code>method1</code> to <code>method2</code>. - * + * * @param method1 * the previously found method * @param method2 @@ -1888,7 +1931,7 @@ public final class EMFTVMUtil { /** * Compares N-parameter <code>op</code> to <code>method</code>. - * + * * @param method1 * the previously found EMFTVM {@link Operation} * @param method2 @@ -1920,7 +1963,7 @@ public final class EMFTVMUtil { /** * Looks for a native superclass Java method without arguments. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param context @@ -1931,7 +1974,7 @@ public final class EMFTVMUtil { */ public static Method findNativeSuperMethod(final Operation op, final Class<?> context, final String opname) { Method method = null; - for (Class<?> superCtx : getSuperTypes(context)) { + for (final Class<?> superCtx : getSuperTypes(context)) { method = compareNativeMethod0(method, findNativeMethod(superCtx, opname, false)); } return compareNativeMethod0(op, method); @@ -1939,7 +1982,7 @@ public final class EMFTVMUtil { /** * Looks for a native superclass Java method with one argument. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param context @@ -1953,7 +1996,7 @@ public final class EMFTVMUtil { public static Method findNativeSuperMethod(final Operation op, final Class<?> context, final String opname, final Object arg) { final Class<?> argType = arg == null ? Void.TYPE : arg.getClass(); Method method = null; - for (Class<?> superCtx : getSuperTypes(context)) { + for (final Class<?> superCtx : getSuperTypes(context)) { method = compareNativeMethod1(method, findNativeMethod(superCtx, opname, argType, false)); } return compareNativeMethod1(op, method); @@ -1961,7 +2004,7 @@ public final class EMFTVMUtil { /** * Looks for a native superclass Java method with multiple arguments. - * + * * @param op * the previously found EMFTVM {@link Operation} * @param context @@ -1975,7 +2018,7 @@ public final class EMFTVMUtil { public static Method findNativeSuperMethod(final Operation op, final Class<?> context, final String opname, final Object[] args) { final Class<?>[] argTypes = getArgumentClasses(args); Method method = null; - for (Class<?> superCtx : getSuperTypes(context)) { + for (final Class<?> superCtx : getSuperTypes(context)) { method = compareNativeMethodN(method, findNativeMethod(superCtx, opname, argTypes, false)); } return compareNativeMethodN(op, method); @@ -1983,7 +2026,7 @@ public final class EMFTVMUtil { /** * Looks for a native Java constructor. - * + * * @param context * The class of the method * @param argumentTypes @@ -2000,8 +2043,8 @@ public final class EMFTVMUtil { final Constructor<?>[] constructors = context.getConstructors(); CONSTRUCTOR: for (int i = 0; i < constructors.length; i++) { - Constructor<?> constructor = constructors[i]; - Class<?>[] pts = constructor.getParameterTypes(); + final Constructor<?> constructor = constructors[i]; + final Class<?>[] pts = constructor.getParameterTypes(); if (pts.length == argTypes.length) { boolean ok = true; for (int j = 0; (j < pts.length) && ok; j++) { @@ -2037,7 +2080,7 @@ public final class EMFTVMUtil { /** * Generates a signature to store methods. - * + * * @param context * the method declaring class * @param name @@ -2060,7 +2103,7 @@ public final class EMFTVMUtil { /** * Generates a signature to store methods. - * + * * @param context * the method declaring class * @param name @@ -2084,7 +2127,7 @@ public final class EMFTVMUtil { /** * Generates a signature to store methods. - * + * * @param context * the method declaring class * @param name @@ -2105,7 +2148,7 @@ public final class EMFTVMUtil { /** * Retrieves the classes of <code>args</code>. - * + * * @param args * @return the classes of <code>args</code> */ @@ -2120,7 +2163,7 @@ public final class EMFTVMUtil { /** * Writes <code>string</code> to <code>path</code> with the given <code>charset</code>. - * + * * @param string * the string to write * @param path @@ -2151,7 +2194,7 @@ public final class EMFTVMUtil { /** * Returns the file with the given <code>path</code> in the workspace, or the file in the filesystem if the workspace is not available. - * + * * @param path * the absolute or relative path to a file. * @return the file in the workspace, or the file in the filesystem if the workspace is not available. @@ -2165,11 +2208,11 @@ public final class EMFTVMUtil { if (wsPath != null) { return new File(wsPath); } - } catch (InstantiationException e) { + } catch (final InstantiationException e) { ATLLogger.fine(e.getMessage()); - } catch (IllegalAccessException e) { + } catch (final IllegalAccessException e) { ATLLogger.fine(e.getMessage()); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { ATLLogger.fine(e.getMessage()); } ATLLogger.info("Could not find workspace root; falling back to native java.io.File path resolution"); @@ -2178,7 +2221,7 @@ public final class EMFTVMUtil { /** * Creates a new {@link Operation}. - * + * * @param isStatic * whether the created operation is static * @param name @@ -2207,19 +2250,19 @@ public final class EMFTVMUtil { final EList<Parameter> pars = op.getParameters(); final EList<LocalVariable> locals = body.getLocalVariables(); if (!isStatic) { - LocalVariable self = factory.createLocalVariable(); + final LocalVariable self = factory.createLocalVariable(); self.setName("self"); self.setTypeModel(context[0]); self.setType(context[1]); locals.add(self); } - for (String[][] par : parameters) { - Parameter p = factory.createParameter(); + for (final String[][] par : parameters) { + final Parameter p = factory.createParameter(); p.setName(par[0][0]); p.setTypeModel(par[1][0]); p.setType(par[1][1]); pars.add(p); - LocalVariable lv = factory.createLocalVariable(); + final LocalVariable lv = factory.createLocalVariable(); lv.setName(par[0][0]); lv.setTypeModel(par[1][0]); lv.setType(par[1][1]); @@ -2231,7 +2274,7 @@ public final class EMFTVMUtil { /** * Creates a new {@link Field}. - * + * * @param name * field name * @param isStatic @@ -2260,7 +2303,7 @@ public final class EMFTVMUtil { /** * Retrieves the transitive closure of <code>field</code> on <code>object</code>. - * + * * @param object * the object on which to retrieve <code>field</code> * @param field @@ -2278,13 +2321,13 @@ public final class EMFTVMUtil { if (value instanceof List<?>) { final List<Object> cvalue = (List<Object>) value; newResult = newResult.union(new LazyListOnList<Object>(cvalue)); - for (Object v : cvalue) { + for (final Object v : cvalue) { newResult = getTrans(v, field, frame, newResult); } } else if (value instanceof Collection<?>) { final Collection<Object> cvalue = (Collection<Object>) value; newResult = newResult.union(new LazyListOnCollection<Object>(cvalue)); - for (Object v : cvalue) { + for (final Object v : cvalue) { newResult = getTrans(v, field, frame, newResult); } } else if (value != null) { @@ -2296,7 +2339,7 @@ public final class EMFTVMUtil { /** * Retrieves the transitive closure of <code>sf</code> on <code>object</code>. - * + * * @param object * the object on which to retrieve <code>sf</code> * @param sf @@ -2318,7 +2361,7 @@ public final class EMFTVMUtil { if (value instanceof LazyList<?>) { final LazyList<Object> cvalue = (LazyList<Object>) value; newResult = newResult.union(cvalue); - for (Object v : cvalue) { + for (final Object v : cvalue) { if (v instanceof EObject) { newResult = getTrans((EObject) v, sf, env, newResult); } @@ -2339,7 +2382,7 @@ public final class EMFTVMUtil { /** * Retrieves the transitive closure of <code>field</code> on <code>object</code>. - * + * * @param object * the object on which to retrieve <code>field</code> * @param field @@ -2361,19 +2404,19 @@ public final class EMFTVMUtil { if (value instanceof LazyList<?>) { final LazyList<Object> cvalue = (LazyList<Object>) value; newResult = newResult.union(cvalue); - for (Object v : cvalue) { + for (final Object v : cvalue) { newResult = getTrans(v, field, newResult); } } else if (value instanceof List<?>) { final List<Object> cvalue = (List<Object>) value; newResult = newResult.union(new LazyListOnList<Object>(cvalue)); - for (Object v : cvalue) { + for (final Object v : cvalue) { newResult = getTrans(v, field, newResult); } } else if (value instanceof Collection<?>) { final Collection<Object> cvalue = (Collection<Object>) value; newResult = newResult.union(new LazyListOnCollection<Object>(cvalue)); - for (Object v : cvalue) { + for (final Object v : cvalue) { newResult = getTrans(v, field, newResult); } } else if (value != null) { @@ -2385,7 +2428,7 @@ public final class EMFTVMUtil { /** * Tries to convert literal to an instance of type. - * + * * @param literal * the enum literal to convert * @param type @@ -2399,7 +2442,7 @@ public final class EMFTVMUtil { final java.lang.reflect.Field valuesField = type.getDeclaredField("VALUES"); final Object values = valuesField.get(null); if (values instanceof Collection<?>) { - for (Object value : (Collection<?>) values) { + for (final Object value : (Collection<?>) values) { if (value instanceof Enumerator) { if (litName.equals(((Enumerator) value).getName()) || litName.equals(value.toString())) { return value; @@ -2408,13 +2451,13 @@ public final class EMFTVMUtil { } } // Ignore exceptions; just don't convert here - } catch (SecurityException e) { + } catch (final SecurityException e) { // do nothing - } catch (NoSuchFieldException e) { + } catch (final NoSuchFieldException e) { // do nothing - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { // do nothing - } catch (IllegalAccessException e) { + } catch (final IllegalAccessException e) { // do nothing } } @@ -2423,7 +2466,7 @@ public final class EMFTVMUtil { /** * Returns the {@link Locale} for the given <code>locale</code> string. - * + * * @param locale * the locale string (e.g. "nl_BE", "es_ES_Traditional_WIN") * @return the {@link Locale} for the given <code>locale</code> string @@ -2445,16 +2488,16 @@ public final class EMFTVMUtil { /** * Registers all {@link EPackage} nsURIs in <code>rs</code> in the local <code>rs</code> {@link EPackage.Registry}. Sets the * {@link EPackage} nsURI to the {@link EPackage} name if not set. - * + * * @param rs * the {@link ResourceSet} */ public static void registerEPackages(final ResourceSet rs) { final EPackage.Registry registry = rs.getPackageRegistry(); - for (Iterator<Object> i = EcoreUtil.getAllContents(rs, true); i.hasNext();) { - Object object = i.next(); + for (final Iterator<Object> i = EcoreUtil.getAllContents(rs, true); i.hasNext();) { + final Object object = i.next(); if (object instanceof EPackage) { - EPackage p = (EPackage) object; + final EPackage p = (EPackage) object; // force existence of nsURI String nsURI = p.getNsURI(); if (nsURI == null) { @@ -2527,27 +2570,27 @@ public final class EMFTVMUtil { Arrays.<Class<?>> asList(dc.getInterfaces())); while ((dc = dc.getSuperclass()) != null) { try { - Method superMethod = dc.getDeclaredMethod(method.getName(), method.getParameterTypes()); + final Method superMethod = dc.getDeclaredMethod(method.getName(), method.getParameterTypes()); if (getRelevantModifiers(superMethod) == methodModifiers) { method = superMethod; } else { break; } - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { + } catch (final SecurityException e) { + } catch (final NoSuchMethodException e) { } dis.addAll(Arrays.<Class<?>> asList(dc.getInterfaces())); } while (!dis.isEmpty()) { - java.util.Set<Class<?>> newDis = new LinkedHashSet<Class<?>>(); - for (Class<?> di : dis) { + final java.util.Set<Class<?>> newDis = new LinkedHashSet<Class<?>>(); + for (final Class<?> di : dis) { try { // Only replace by method declared in a super-interface if (di.isAssignableFrom(method.getDeclaringClass())) { method = di.getDeclaredMethod(method.getName(), method.getParameterTypes()); } - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { + } catch (final SecurityException e) { + } catch (final NoSuchMethodException e) { } newDis.addAll(Arrays.<Class<?>> asList(di.getInterfaces())); } @@ -2569,7 +2612,7 @@ public final class EMFTVMUtil { /** * Returns the hit rate of the method cache. - * + * * @return the hit rate of the method cache, or <code>-1.0</code> if no hits * were recorded yet */ @@ -2579,7 +2622,7 @@ public final class EMFTVMUtil { /** * Returns the hit rate of the root method cache. - * + * * @return the hit rate of the root method cache, or <code>-1.0</code> if no * hits were recorded yet */ diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/OCLOperations.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/OCLOperations.java index 087bf8a4..67dc025d 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/OCLOperations.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/OCLOperations.java @@ -1,5 +1,6 @@ /******************************************************************************* * Copyright (c) 2011 Vrije Universiteit Brussel. + * Copyright (c) 2017 Dennis Wagelaar. * 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 @@ -45,7 +46,6 @@ import org.eclipse.m2m.atl.emftvm.trace.TargetElement; import org.eclipse.m2m.atl.emftvm.trace.TraceLinkSet; import org.eclipse.m2m.atl.emftvm.trace.TracedRule; - /** * Provides native operations on simple OCL types. * @author <a href="mailto:dennis.wagelaar@vub.ac.be">Dennis Wagelaar</a> @@ -68,7 +68,7 @@ public final class OCLOperations { public ResolveIterator() { super(dataSource.iterator()); } - + /** * {@inheritDoc} */ @@ -82,7 +82,7 @@ public final class OCLOperations { assert seMapsTo.get(0).getObject().eResource() != null; next = seMapsTo.get(0).getObject(); } else { - for (TargetElement te : se.getSourceOf().getTargetElements()) { + for (final TargetElement te : se.getSourceOf().getTargetElements()) { if (te.getMapsTo().isEmpty()) { // default mapping assert te.getObject().eResource() != null; next = te.getObject(); @@ -107,7 +107,7 @@ public final class OCLOperations { super(dataSource); this.tls = frame.getEnv().getTraces(); } - + /** * {@inheritDoc} */ @@ -118,7 +118,7 @@ public final class OCLOperations { } return new ResolveIterator(); // extends CachingIterator } - + /** * {@inheritDoc} */ @@ -129,7 +129,7 @@ public final class OCLOperations { } return ((Collection<Object>)dataSource).size(); } - + } /** @@ -155,7 +155,7 @@ public final class OCLOperations { assert seMapsTo.get(0).getObject().eResource() != null; next = seMapsTo.get(0).getObject(); } else { - for (TargetElement te : se.getSourceOf().getTargetElements()) { + for (final TargetElement te : se.getSourceOf().getTargetElements()) { if (te.getMapsTo().isEmpty()) { // default mapping assert te.getObject().eResource() != null; next = te.getObject(); @@ -197,7 +197,7 @@ public final class OCLOperations { return new UniqueResolveIterator(); // extends CachingIterator } } - + } private static OCLOperations instance; @@ -233,7 +233,7 @@ public final class OCLOperations { // OclAny ///////////////////////////////////////////////////////////////////// createOperation(false, "debug", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -251,9 +251,9 @@ public final class OCLOperations { ATLLogger.info(buf.toString()); return object; } - }); + }); createOperation(false, "debug", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"message"}, Types.STRING_TYPE}}, + new String[][][]{{{"message"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -272,18 +272,18 @@ public final class OCLOperations { ATLLogger.info(buf.toString()); return object; } - }); + }); createOperation(false, "toString", Types.OCL_ANY_TYPE, Types.STRING_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { final Object object = frame.getLocal(0, 0); return EMFTVMUtil.toPrettyString(object, frame.getEnv()); } - }); + }); createOperation(false, "oclAsType", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, + new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -297,9 +297,9 @@ public final class OCLOperations { return object; } - }); + }); createOperation(false, "oclAsType", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -313,9 +313,9 @@ public final class OCLOperations { return object; } - }); + }); createOperation(false, "oclIsTypeOf", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, + new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -324,7 +324,7 @@ public final class OCLOperations { if (type instanceof EClass) { return o instanceof EObject && ((EObject) o).eClass() == type; } else if (o != null) { - final Class<?> ic = ((EClassifier)type).getInstanceClass(); + final Class<?> ic = type.getInstanceClass(); if (ic == null) { throw new IllegalArgumentException(String.format("EClassifier %s must have an instance class", type)); } @@ -333,9 +333,9 @@ public final class OCLOperations { return false; } } - }); + }); createOperation(false, "oclIsTypeOf", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -343,9 +343,9 @@ public final class OCLOperations { final Class<?> type = (Class<?>)frame.getLocal(0, 1); return o != null ? o.getClass() == type : false; } - }); + }); createOperation(false, "oclIsKindOf", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, + new String[][][]{{{"type"}, Types.CLASSIFIER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -353,9 +353,9 @@ public final class OCLOperations { final EClassifier type = (EClassifier)frame.getLocal(0, 1); return type.isInstance(o); } - }); + }); createOperation(false, "oclIsKindOf", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -363,9 +363,9 @@ public final class OCLOperations { final Class<?> type = (Class<?>)frame.getLocal(0, 1); return type.isInstance(o); } - }); + }); createOperation(false, "oclType", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -378,9 +378,9 @@ public final class OCLOperations { return Void.TYPE; } } - }); + }); createOperation(false, "=", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -388,9 +388,9 @@ public final class OCLOperations { final Object o2 = frame.getLocal(0, 1); return o == null ? o2 == null : o.equals(o2); } - }); + }); createOperation(false, "=~", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -398,9 +398,9 @@ public final class OCLOperations { final Object o2 = frame.getLocal(0, 1); return o == null ? o2 == null : o.equals(o2); } - }); + }); createOperation(false, "=~|", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -408,9 +408,9 @@ public final class OCLOperations { final Object o2 = frame.getLocal(0, 1); return o == null ? o2 == null : o.equals(o2); } - }); + }); createOperation(false, "<>", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -418,9 +418,9 @@ public final class OCLOperations { final Object o2 = frame.getLocal(0, 1); return !(o == null ? o2 == null : o.equals(o2)); } - }); + }); createOperation(false, "isInModel", Types.OCL_ANY_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"model"}, Types.STRING_TYPE}}, + new String[][][]{{{"model"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -444,9 +444,9 @@ public final class OCLOperations { return false; } } - }); + }); createOperation(false, "refImmediateComposite", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -458,9 +458,9 @@ public final class OCLOperations { "Cannot retrieve immediate composite for regular objects: %s", object)); } - }); + }); createOperation(false, "refGetValue", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"propname"}, Types.STRING_TYPE}}, + new String[][][]{{{"propname"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -480,9 +480,9 @@ public final class OCLOperations { "Cannot retrieve properties for regular objects: %s", object)); } - }); + }); createOperation(false, "refSetValue", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"propname"}, Types.STRING_TYPE}, {{"value"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"propname"}, Types.STRING_TYPE}, {{"value"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -504,9 +504,9 @@ public final class OCLOperations { "Cannot set properties for regular objects: %s", object)); } - }); + }); createOperation(false, "refUnsetValue", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"propname"}, Types.STRING_TYPE}}, + new String[][][]{{{"propname"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -527,7 +527,7 @@ public final class OCLOperations { "Cannot unset properties for regular objects: %s", object)); } - }); + }); createOperation(false, "refInvokeOperation", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"opname"}, Types.STRING_TYPE}, {{"arguments"}, Types.SEQUENCE_TYPE}}, new NativeCodeBlock() { @@ -538,9 +538,9 @@ public final class OCLOperations { final List<?> args = (List<?>)frame.getLocal(0, 2); return EMFTVMUtil.invokeNative(frame, object, opname, args.toArray()); } - }); + }); createOperation(false, "resolve", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -552,7 +552,7 @@ public final class OCLOperations { assert seMapsTo.get(0).getObject().eResource() != null; return seMapsTo.get(0).getObject(); } - for (TargetElement te : se.getSourceOf().getTargetElements()) { + for (final TargetElement te : se.getSourceOf().getTargetElements()) { if (te.getMapsTo().isEmpty()) { // default mapping assert te.getObject().eResource() != null; return te.getObject(); @@ -561,9 +561,9 @@ public final class OCLOperations { } return object; } - }); + }); createOperation(false, "resolve", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"rule"}, Types.STRING_TYPE}}, + new String[][][]{{{"rule"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -578,7 +578,7 @@ public final class OCLOperations { assert seMapsTo.get(0).getObject().eResource() != null; return seMapsTo.get(0).getObject(); } - for (TargetElement te : se.getSourceOf().getTargetElements()) { + for (final TargetElement te : se.getSourceOf().getTargetElements()) { if (te.getMapsTo().isEmpty()) { // default mapping assert te.getObject().eResource() != null; return te.getObject(); @@ -588,8 +588,8 @@ public final class OCLOperations { } return object; } - }); - createOperation(false, "remap", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, + }); + createOperation(false, "remap", Types.OCL_ANY_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"to"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override @@ -601,12 +601,12 @@ public final class OCLOperations { } return target; } - }); + }); ///////////////////////////////////////////////////////////////////// // Collection ///////////////////////////////////////////////////////////////////// createOperation(false, "toString", Types.COLLECTION_TYPE, Types.STRING_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @SuppressWarnings("unchecked") @Override @@ -614,12 +614,12 @@ public final class OCLOperations { final LazyCollection<Object> coll = (LazyCollection<Object>)frame.getLocal(0, 0); return coll.asString(frame.getEnv()); } - }); + }); ///////////////////////////////////////////////////////////////////// // JavaCollection ///////////////////////////////////////////////////////////////////// createOperation(false, "resolve", Types.JAVA_COLLECTION_TYPE, Types.SEQUENCE_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @SuppressWarnings("unchecked") @Override @@ -627,9 +627,9 @@ public final class OCLOperations { final Collection<Object> object = (Collection<Object>)frame.getLocal(0, 0); return new ResolveList(object, frame); } - }); + }); createOperation(false, "resolve", Types.JAVA_COLLECTION_TYPE, Types.SEQUENCE_TYPE, - new String[][][]{{{"rule"}, Types.STRING_TYPE}}, + new String[][][]{{{"rule"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @SuppressWarnings("unchecked") @Override @@ -638,9 +638,9 @@ public final class OCLOperations { final String rule = (String)frame.getLocal(0, 1); return new UniqueResolveList(object, frame, rule); } - }); + }); createOperation(false, "=~", Types.JAVA_COLLECTION_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -652,9 +652,9 @@ public final class OCLOperations { return o.contains(o2); } } - }); + }); createOperation(false, "=~|", Types.JAVA_COLLECTION_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -666,12 +666,12 @@ public final class OCLOperations { return o.contains(o2); } } - }); + }); ///////////////////////////////////////////////////////////////////// // JavaList ///////////////////////////////////////////////////////////////////// createOperation(false, "=~|", Types.JAVA_LIST_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, + new String[][][]{{{"o"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -692,58 +692,58 @@ public final class OCLOperations { return false; } } - }); + }); ///////////////////////////////////////////////////////////////////// // Map ///////////////////////////////////////////////////////////////////// createOperation(false, "including", Types.MAP_TYPE, Types.SET_TYPE, new String[][][]{{{"key"}, Types.OCL_ANY_TYPE}, {{"value"}, Types.OCL_ANY_TYPE}}, new NativeCodeBlock() { - @Override - public Object execute(final StackFrame frame) { - final Map<Object, Object> o = new HashMap<Object, Object>((Map<?, ?>)frame.getLocal(0, 0)); - final Object key = frame.getLocal(0, 1); - final Object value = frame.getLocal(0, 2); - o.put(key, value); - return o; - } - }); + @Override + public Object execute(final StackFrame frame) { + final Map<Object, Object> o = new HashMap<Object, Object>((Map<?, ?>)frame.getLocal(0, 0)); + final Object key = frame.getLocal(0, 1); + final Object value = frame.getLocal(0, 2); + o.put(key, value); + return o; + } + }); createOperation(false, "getKeys", Types.MAP_TYPE, Types.SET_TYPE, new String[][][]{}, new NativeCodeBlock() { - @SuppressWarnings("unchecked") - @Override - public Object execute(final StackFrame frame) { - final Map<?, ?> o = (Map<?, ?>)frame.getLocal(0, 0); - return new LazySetOnSet<Object>((Set<Object>)o.keySet()); - } - }); + @SuppressWarnings("unchecked") + @Override + public Object execute(final StackFrame frame) { + final Map<?, ?> o = (Map<?, ?>)frame.getLocal(0, 0); + return new LazySetOnSet<Object>((Set<Object>)o.keySet()); + } + }); createOperation(false, "getValues", Types.MAP_TYPE, Types.SET_TYPE, new String[][][]{}, new NativeCodeBlock() { - @SuppressWarnings("unchecked") - @Override - public Object execute(final StackFrame frame) { - final Map<?, ?> o = (Map<?, ?>)frame.getLocal(0, 0); - return new LazyBagOnCollection<Object>((Collection<Object>)o.values()); - } - }); + @SuppressWarnings("unchecked") + @Override + public Object execute(final StackFrame frame) { + final Map<?, ?> o = (Map<?, ?>)frame.getLocal(0, 0); + return new LazyBagOnCollection<Object>((Collection<Object>)o.values()); + } + }); createOperation(false, "union", Types.MAP_TYPE, Types.SET_TYPE, new String[][][]{{{"m"}, Types.MAP_TYPE}}, new NativeCodeBlock() { - @Override - public Object execute(final StackFrame frame) { - final Map<Object, Object> o = new HashMap<Object, Object>((Map<?, ?>)frame.getLocal(0, 0)); - final Map<?, ?> m = (Map<?, ?>)frame.getLocal(0, 1); - o.putAll(m); - return o; - } - }); + @Override + public Object execute(final StackFrame frame) { + final Map<Object, Object> o = new HashMap<Object, Object>((Map<?, ?>)frame.getLocal(0, 0)); + final Map<?, ?> m = (Map<?, ?>)frame.getLocal(0, 1); + o.putAll(m); + return o; + } + }); ///////////////////////////////////////////////////////////////////// // ExecEnv ///////////////////////////////////////////////////////////////////// createOperation(true, "resolveTemp", Types.EXEC_ENV_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"var"}, Types.OCL_ANY_TYPE}, {{"target_pattern_name"}, Types.STRING_TYPE}}, + new String[][][]{{{"var"}, Types.OCL_ANY_TYPE}, {{"target_pattern_name"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -768,63 +768,63 @@ public final class OCLOperations { } } throw new VMException(frame, String.format( - "Cannot resolve default trace target '%s' for %s", + "Cannot resolve default trace target '%s' for %s", name, EMFTVMUtil.toPrettyString(object, frame.getEnv()))); } - }); + }); createOperation(true, "resolveTemp", Types.EXEC_ENV_TYPE, Types.OCL_ANY_TYPE, - new String[][][]{{{"var"}, Types.OCL_ANY_TYPE}, - {{"rule_name"}, Types.STRING_TYPE}, - {{"target_pattern_name"}, Types.STRING_TYPE}}, - new NativeCodeBlock() { - @Override - public Object execute(final StackFrame frame) { - final Object object = frame.getLocal(0, 0); - final String rule = (String)frame.getLocal(0, 1); - final String name = (String)frame.getLocal(0, 2); - if (object instanceof List<?>) { - final TracedRule tr = frame.getEnv().getTraces().getLinksByRule(rule, false); - if (tr != null) { - final SourceElementList sel = tr.getUniqueSourceElements((List<?>)object); - if (sel != null) { - assert !sel.getSourceElements().isEmpty(); - final TargetElement te = sel.getSourceElements().get(0).getSourceOf().getTargetElement(name); - if (te != null) { - return te.getObject(); - } + new String[][][]{{{"var"}, Types.OCL_ANY_TYPE}, + {{"rule_name"}, Types.STRING_TYPE}, + {{"target_pattern_name"}, Types.STRING_TYPE}}, + new NativeCodeBlock() { + @Override + public Object execute(final StackFrame frame) { + final Object object = frame.getLocal(0, 0); + final String rule = (String)frame.getLocal(0, 1); + final String name = (String)frame.getLocal(0, 2); + if (object instanceof List<?>) { + final TracedRule tr = frame.getEnv().getTraces().getLinksByRule(rule, false); + if (tr != null) { + final SourceElementList sel = tr.getUniqueSourceElements((List<?>)object); + if (sel != null) { + assert !sel.getSourceElements().isEmpty(); + final TargetElement te = sel.getSourceElements().get(0).getSourceOf().getTargetElement(name); + if (te != null) { + return te.getObject(); } } - } else { - final TracedRule tr = frame.getEnv().getTraces().getLinksByRule(rule, false); - if (tr != null) { - final SourceElement se = tr.getUniqueSourceElement(object); - if (se != null) { - final TargetElement te = se.getSourceOf().getTargetElement(name); - if (te != null) { - return te.getObject(); - } + } + } else { + final TracedRule tr = frame.getEnv().getTraces().getLinksByRule(rule, false); + if (tr != null) { + final SourceElement se = tr.getUniqueSourceElement(object); + if (se != null) { + final TargetElement te = se.getSourceOf().getTargetElement(name); + if (te != null) { + return te.getObject(); } } } - throw new VMException(frame, String.format( - "Cannot resolve unique trace target '%s::%s' for %s", - rule, name, EMFTVMUtil.toPrettyString(object, frame.getEnv()))); } - }); + throw new VMException(frame, String.format( + "Cannot resolve unique trace target '%s::%s' for %s", + rule, name, EMFTVMUtil.toPrettyString(object, frame.getEnv()))); + } + }); ///////////////////////////////////////////////////////////////////// // Class ///////////////////////////////////////////////////////////////////// createOperation(false, "allInstances", Types.CLASS_TYPE, Types.SEQUENCE_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { final EClass c = (EClass)frame.getLocal(0, 0); return EMFTVMUtil.findAllInstances(c, frame.getEnv()); } - }); + }); createOperation(false, "allInstancesFrom", Types.CLASS_TYPE, Types.SEQUENCE_TYPE, - new String[][][]{{{"metamodel"}, Types.STRING_TYPE}}, + new String[][][]{{{"metamodel"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -832,9 +832,9 @@ public final class OCLOperations { final String mm = (String)frame.getLocal(0, 1); return EMFTVMUtil.findAllInstIn(mm, c, frame.getEnv()); } - }); + }); createOperation(false, "conformsTo", Types.CLASS_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -842,9 +842,9 @@ public final class OCLOperations { final EClass c2 = (EClass)frame.getLocal(0, 1); return c2.isSuperTypeOf(c); } - }); + }); createOperation(false, "conformsTo", Types.CLASS_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -857,7 +857,7 @@ public final class OCLOperations { return c2 == Object.class; // everything is an Object } } - }); + }); createOperation(false, "newInstance", Types.CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][]{}, new NativeCodeBlock() { @@ -866,7 +866,7 @@ public final class OCLOperations { final EClass type = (EClass)frame.getLocal(0, 0); return type.getEPackage().getEFactoryInstance().create(type); } - }); + }); createOperation(false, "newInstanceIn", Types.CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"modelname"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @@ -884,7 +884,7 @@ public final class OCLOperations { } return model.newElement(type); } - }); + }); createOperation(false, "getInstanceById", Types.CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"id"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @@ -896,7 +896,7 @@ public final class OCLOperations { final List<Model> models = new LazyListOnCollection<Model>( env.getInputModels().values()).union(new LazyListOnCollection<Model>( env.getInoutModels().values())); - for (Model model : models) { + for (final Model model : models) { final EObject instance = model.getResource().getEObject(id); if (type.isInstance(instance)) { return instance; @@ -904,7 +904,7 @@ public final class OCLOperations { } return null; } - }); + }); createOperation(false, "getInstanceById", Types.CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"modelname"}, Types.STRING_TYPE}, {{"id"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @@ -928,12 +928,12 @@ public final class OCLOperations { return null; } } - }); + }); ///////////////////////////////////////////////////////////////////// // JavaClass ///////////////////////////////////////////////////////////////////// createOperation(false, "conformsTo", Types.JAVA_CLASS_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -946,9 +946,9 @@ public final class OCLOperations { return false; } } - }); + }); createOperation(false, "conformsTo", Types.JAVA_CLASS_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, + new String[][][]{{{"type"}, Types.JAVA_CLASS_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -956,16 +956,16 @@ public final class OCLOperations { final Class<?> c2 = (Class<?>)frame.getLocal(0, 1); return c2.isAssignableFrom(c); } - }); + }); createOperation(false, "getName", Types.JAVA_CLASS_TYPE, Types.STRING_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { final Class<?> c = (Class<?>)frame.getLocal(0, 0); return NativeTypes.typeName(c); } - }); + }); createOperation(false, "refInvokeStaticOperation", Types.JAVA_CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][]{{{"opname"}, Types.STRING_TYPE}, {{"arguments"}, Types.SEQUENCE_TYPE}}, new NativeCodeBlock() { @@ -976,476 +976,476 @@ public final class OCLOperations { final List<?> args = (List<?>)frame.getLocal(0, 2); return EMFTVMUtil.invokeNativeStatic(frame, c, opname, args.toArray()); } - }); + }); createOperation(false, "refNewInstance", Types.JAVA_CLASS_TYPE, Types.OCL_ANY_TYPE, new String[][][] { { { "arguments" }, - Types.SEQUENCE_TYPE } }, new NativeCodeBlock() { - @Override - public Object execute(final StackFrame frame) { - final Class<?> c = (Class<?>) frame.getLocal(0, 0); - final Object[] args = ((List<?>) frame.getLocal(0, 1)).toArray(); - final Constructor<?> constructor = EMFTVMUtil.findConstructor(c, EMFTVMUtil.getArgumentClasses(args)); - if (constructor != null) { - try { - return EMFTVMUtil.emf2vm(frame.getEnv(), null, constructor.newInstance(args)); - } catch (InvocationTargetException e) { - final Throwable target = e.getTargetException(); - if (target instanceof VMException) { - throw (VMException) target; - } else { - throw new VMException(frame, target); + Types.SEQUENCE_TYPE } }, new NativeCodeBlock() { + @Override + public Object execute(final StackFrame frame) { + final Class<?> c = (Class<?>) frame.getLocal(0, 0); + final Object[] args = ((List<?>) frame.getLocal(0, 1)).toArray(); + final Constructor<?> constructor = EMFTVMUtil.findConstructor(c, EMFTVMUtil.getArgumentClasses(args)); + if (constructor != null) { + try { + return EMFTVMUtil.emf2vm(frame.getEnv(), null, constructor.newInstance(args)); + } catch (final InvocationTargetException e) { + final Throwable target = e.getTargetException(); + if (target instanceof VMException) { + throw (VMException) target; + } else { + throw new VMException(frame, target); + } + } catch (final VMException e) { + throw e; + } catch (final Exception e) { + throw new VMException(frame, e); } - } catch (VMException e) { - throw e; - } catch (Exception e) { - throw new VMException(frame, e); } + throw new UnsupportedOperationException(String.format("%s::<init>(%s)", EMFTVMUtil.getTypeName(frame.getEnv(), c), + EMFTVMUtil.getTypeNames(frame.getEnv(), EMFTVMUtil.getArgumentTypes(args)))); } - throw new UnsupportedOperationException(String.format("%s::<init>(%s)", EMFTVMUtil.getTypeName(frame.getEnv(), c), - EMFTVMUtil.getTypeNames(frame.getEnv(), EMFTVMUtil.getArgumentTypes(args)))); - } - }); + }); ///////////////////////////////////////////////////////////////////// // Real ///////////////////////////////////////////////////////////////////// createOperation(false, "+", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) + (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "+", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) + (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "-", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return -(Double)frame.getLocal(0, 0); } - }); + }); createOperation(false, "-", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) - (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "-", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) - (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "*", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) * (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "*", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) * (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "neg", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return -(Double)frame.getLocal(0, 0); } - }); + }); createOperation(false, "/", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) / (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "/", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) / (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "abs", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.abs((Double)frame.getLocal(0, 0)); } - }); + }); createOperation(false, "floor", Types.REAL_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Double.valueOf(Math.floor((Double)frame.getLocal(0, 0))).intValue(); } - }); + }); createOperation(false, "round", Types.REAL_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Double.valueOf(Math.round((Double)frame.getLocal(0, 0))).intValue(); } - }); + }); createOperation(false, "max", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.max((Double)frame.getLocal(0, 0), (Double)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "max", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.max((Double)frame.getLocal(0, 0), (Integer)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "min", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.min((Double)frame.getLocal(0, 0), (Double)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "min", Types.REAL_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.min((Double)frame.getLocal(0, 0), (Integer)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "<", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) < (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) < (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) > (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) > (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<=", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) <= (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<=", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) <= (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">=", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) >= (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">=", Types.REAL_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Double)frame.getLocal(0, 0) >= (Integer)frame.getLocal(0, 1); } - }); + }); ///////////////////////////////////////////////////////////////////// // Integer ///////////////////////////////////////////////////////////////////// createOperation(false, "neg", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return -(Integer)frame.getLocal(0, 0); } - }); + }); createOperation(false, "+", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) + (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "+", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) + (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "-", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return -(Integer)frame.getLocal(0, 0); } - }); + }); createOperation(false, "-", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) - (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "-", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) - (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "*", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) * (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "*", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) * (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "/", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) / (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "/", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((Integer)frame.getLocal(0, 0)).doubleValue() / (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "abs", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.abs((Integer)frame.getLocal(0, 0)); } - }); + }); createOperation(false, "div", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) / (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "mod", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) % (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "max", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.max((Integer)frame.getLocal(0, 0), (Double)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "max", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.max((Integer)frame.getLocal(0, 0), (Integer)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "min", Types.INTEGER_TYPE, Types.REAL_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.min((Integer)frame.getLocal(0, 0), (Double)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "min", Types.INTEGER_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Math.min((Integer)frame.getLocal(0, 0), (Integer)frame.getLocal(0, 1)); } - }); + }); createOperation(false, "<", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) < (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) < (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) > (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) > (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<=", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) <= (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, "<=", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) <= (Integer)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">=", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"r"}, Types.REAL_TYPE}}, + new String[][][]{{{"r"}, Types.REAL_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) >= (Double)frame.getLocal(0, 1); } - }); + }); createOperation(false, ">=", Types.INTEGER_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (Integer)frame.getLocal(0, 0) >= (Integer)frame.getLocal(0, 1); } - }); + }); ///////////////////////////////////////////////////////////////////// // String ///////////////////////////////////////////////////////////////////// createOperation(false, "+", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{{{"s"}, Types.STRING_TYPE}}, + new String[][][]{{{"s"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return (String)frame.getLocal(0, 0) + (String)frame.getLocal(0, 1); } - }); + }); createOperation(false, "size", Types.STRING_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((String)frame.getLocal(0, 0)).length(); } - }); + }); createOperation(false, "substring", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{{{"lower"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"lower"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return ((String)frame.getLocal(0, 0)).substring( (Integer)frame.getLocal(0, 1) - 1); - } catch (IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "substring", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{{{"lower"}, Types.INTEGER_TYPE}, {{"upper"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"lower"}, Types.INTEGER_TYPE}, {{"upper"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { @@ -1453,145 +1453,145 @@ public final class OCLOperations { return ((String)frame.getLocal(0, 0)).substring( (Integer)frame.getLocal(0, 1) - 1, (Integer)frame.getLocal(0, 2)); - } catch (IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "toInteger", Types.STRING_TYPE, Types.INTEGER_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return Integer.parseInt((String)frame.getLocal(0, 0)); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "toReal", Types.STRING_TYPE, Types.REAL_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return Double.parseDouble((String)frame.getLocal(0, 0)); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "indexOf", Types.STRING_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"s"}, Types.STRING_TYPE}}, + new String[][][]{{{"s"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((String)frame.getLocal(0, 0)).indexOf((String)frame.getLocal(0, 1)) + 1; } - }); + }); createOperation(false, "lastIndexOf", Types.STRING_TYPE, Types.INTEGER_TYPE, - new String[][][]{{{"s"}, Types.STRING_TYPE}}, + new String[][][]{{{"s"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((String)frame.getLocal(0, 0)).lastIndexOf((String)frame.getLocal(0, 1)) + 1; } - }); + }); createOperation(false, "at", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, + new String[][][]{{{"i"}, Types.INTEGER_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return String.valueOf(((String)frame.getLocal(0, 0)) .charAt((Integer)frame.getLocal(0, 1) - 1)); - } catch (IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "characters", Types.STRING_TYPE, Types.SEQUENCE_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { LazyList<String> seq = new LazyList<String>(); - for (char c : ((String)frame.getLocal(0, 0)).toCharArray()) { + for (final char c : ((String)frame.getLocal(0, 0)).toCharArray()) { seq = seq.append(String.valueOf(c)); } return seq; } - }); + }); createOperation(false, "toBoolean", Types.STRING_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return Boolean.parseBoolean((String)frame.getLocal(0, 0)); } - }); + }); createOperation(false, "toUpper", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((String)frame.getLocal(0, 0)).toUpperCase(); } - }); + }); createOperation(false, "toLower", Types.STRING_TYPE, Types.STRING_TYPE, - new String[][][]{}, + new String[][][]{}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { return ((String)frame.getLocal(0, 0)).toLowerCase(); } - }); + }); createOperation(false, "writeTo", Types.STRING_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"path"}, Types.STRING_TYPE}}, + new String[][][]{{{"path"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return EMFTVMUtil.writeToWithCharset( - (String)frame.getLocal(0, 0), + (String)frame.getLocal(0, 0), (String)frame.getLocal(0, 1), null); - } catch (IOException e) { + } catch (final IOException e) { throw new VMException(frame, e); } } - }); + }); createOperation(false, "writeToWithCharset", Types.STRING_TYPE, Types.BOOLEAN_TYPE, - new String[][][]{{{"path"}, Types.STRING_TYPE}, {{"charset"}, Types.STRING_TYPE}}, + new String[][][]{{{"path"}, Types.STRING_TYPE}, {{"charset"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return EMFTVMUtil.writeToWithCharset( - (String)frame.getLocal(0, 0), + (String)frame.getLocal(0, 0), (String)frame.getLocal(0, 1), (String)frame.getLocal(0, 2)); - } catch (IOException e) { + } catch (final IOException e) { throw new VMException(frame, e); } } - }); - createOperation(false, "toDate", Types.STRING_TYPE, Types.JAVA_DATE_TYPE, + }); + createOperation(false, "toDate", Types.STRING_TYPE, Types.JAVA_DATE_TYPE, new String[][][]{{{"format"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override public Object execute(final StackFrame frame) { try { return new SimpleDateFormat((String) frame.getLocal(1)).parse((String) frame.getLocal(0)); - } catch (ParseException e) { + } catch (final ParseException e) { throw new VMException(frame, e); } } }); - createOperation(false, "toDate", Types.STRING_TYPE, Types.JAVA_DATE_TYPE, + createOperation(false, "toDate", Types.STRING_TYPE, Types.JAVA_DATE_TYPE, new String[][][]{{{"format"}, Types.STRING_TYPE}, {{"locale"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override @@ -1599,7 +1599,7 @@ public final class OCLOperations { try { return new SimpleDateFormat((String) frame.getLocal(1), EMFTVMUtil.getLocale((String) frame.getLocal(2))) .parse((String) frame.getLocal(0)); - } catch (ParseException e) { + } catch (final ParseException e) { throw new VMException(frame, e); } } @@ -1607,7 +1607,7 @@ public final class OCLOperations { ///////////////////////////////////////////////////////////////////// // Date ///////////////////////////////////////////////////////////////////// - createOperation(false, "toString", Types.JAVA_DATE_TYPE, Types.STRING_TYPE, + createOperation(false, "toString", Types.JAVA_DATE_TYPE, Types.STRING_TYPE, new String[][][]{{{"format"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override @@ -1615,7 +1615,7 @@ public final class OCLOperations { return new SimpleDateFormat((String) frame.getLocal(1)).format((Date) frame.getLocal(0)); } }); - createOperation(false, "toString", Types.JAVA_DATE_TYPE, Types.STRING_TYPE, + createOperation(false, "toString", Types.JAVA_DATE_TYPE, Types.STRING_TYPE, new String[][][]{{{"format"}, Types.STRING_TYPE}, {{"locale"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override @@ -1626,14 +1626,14 @@ public final class OCLOperations { }); createOperation(false, "toTuple", Types.JAVA_DATE_TYPE, Types.TUPLE_TYPE, new String[][][]{}, new NativeCodeBlock() { - @Override - public Object execute(final StackFrame frame) { - final Calendar cal = Calendar.getInstance(); - cal.setTime((Date) frame.getLocal(0)); - return Tuple.fromCalendar(cal); - } - }); - createOperation(false, "toTuple", Types.JAVA_DATE_TYPE, Types.TUPLE_TYPE, + @Override + public Object execute(final StackFrame frame) { + final Calendar cal = Calendar.getInstance(); + cal.setTime((Date) frame.getLocal(0)); + return Tuple.fromCalendar(cal); + } + }); + createOperation(false, "toTuple", Types.JAVA_DATE_TYPE, Types.TUPLE_TYPE, new String[][][]{{{"timezone"}, Types.STRING_TYPE}}, new NativeCodeBlock() { @Override @@ -1656,7 +1656,7 @@ public final class OCLOperations { * @return a new {@link Operation}. * @see Types */ - private Operation createOperation(final boolean isStatic, final String name, final String[] context, + private Operation createOperation(final boolean isStatic, final String name, final String[] context, final String[] returnType, final String[][][] parameters, final CodeBlock body) { final Operation op = EMFTVMUtil.createOperation(isStatic, name, context, returnType, parameters, body); oclModule.getFeatures().add(op); diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java index e1fe1df3..eb4ebaf6 100755 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011-2015 Dennis Wagelaar, Vrije Universiteit Brussel. + * Copyright (c) 2011-2017 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 @@ -21,26 +21,26 @@ import java.util.TimeZone; /** * Reflective, immutable implementation of OCL Tuples. - * + * * @author <a href="mailto:dennis.wagelaar@vub.ac.be">Dennis Wagelaar</a> */ public final class Tuple { /** * Creates a new {@link Tuple} from <code>map</code>. - * + * * @param map * the {@link Map} with tuple data * @return a new {@link Tuple} from <code>map</code> */ - public static Tuple fromMap(final Map<String, Object> map) { + public static Tuple fromMap(final Map<String, ? extends Object> map) { return new Tuple(map); } /** * Returns a new {@link Tuple} from <code>cal</code>. Supported fields: timezone, year, month, day_of_month, day_of_week, day_of_week_in_month, * day_of_year, era, hour, hour_of_day, minute, second, millisecond, am_pm, week_of_month, week_of_year. - * + * * @param cal * the input {@link Calendar} * @return a new {@link Tuple} from <code>cal</code> @@ -66,7 +66,7 @@ public final class Tuple { return new Tuple(values); } - private final Map<String, Object> values; + private final Map<String, ? extends Object> values; /** * Creates a new empty {@link Tuple}. @@ -77,17 +77,17 @@ public final class Tuple { /** * Creates a new {@link Tuple} initialized with the given <code>map</code>. - * + * * @param map * the map with tuple key-value pairs */ - public Tuple(Map<String, Object> map) { + public Tuple(Map<String, ? extends Object> map) { values = map; } /** * Returns the value for <code>name</code>. - * + * * @param name * the element name * @return the value for <code>name</code> @@ -100,14 +100,6 @@ public final class Tuple { * {@inheritDoc} */ @Override - public String toString() { - return "Tuple " + values.toString(); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - */ - @Override public boolean equals(Object o) { return (o instanceof Tuple) ? values.equals(((Tuple) o).values) : false; } @@ -122,10 +114,10 @@ public final class Tuple { /** * Returns this {@link Tuple}'s value map. - * + * * @return this {@link Tuple}'s value map */ - public Map<String, Object> asMap() { + public Map<String, ? extends Object> asMap() { return values; } @@ -133,7 +125,7 @@ public final class Tuple { * Returns a {@link Date} instance using the fields of this tuple. Supported fields: timezone, locale, year, month, * day_of_month, day_of_week, day_of_week_in_month, day_of_year, era, hour, hour_of_day, minute, second, millisecond, am_pm, * week_of_month, week_of_year. - * + * * @return a {@link Date} instance using the fields of this tuple * @see Calendar */ |