Class EMFTVMUtil

java.lang.Object
org.eclipse.m2m.atl.emftvm.util.EMFTVMUtil

public final class EMFTVMUtil extends Object
EMFTVM static utility methods.
  • Field Details

  • Method Details

    • getTypeName

      public static String getTypeName(ExecEnv env, Object type)
      Returns the name of type, for printing.
      Parameters:
      env - the current ExecEnv
      type - the type
      Returns:
      the name of type, for printing
    • getTypeNames

      public static String getTypeNames(ExecEnv env, Object[] types)
      Returns the names of types, for printing.
      Parameters:
      env - the current ExecEnv.
      types - the types
      Returns:
      the names of types, for printing
    • getRegistryType

      public static Object getRegistryType(Object type) throws IllegalArgumentException
      Returns the type object to use for the registry.
      Parameters:
      type - the type object
      Returns:
      the type object to use for the registry
      Throws:
      IllegalArgumentException - if type is a primitive EMF type without instance class
    • getEcoreMetamodel

      public static Metamodel getEcoreMetamodel()
      Returns the singleton instance of the Ecore metamodel.
      Returns:
      the singleton instance of the Ecore metamodel
    • getEmfTvmMetamodel

      public static Metamodel getEmfTvmMetamodel()
      Returns the singleton instance of the EMFTVM metamodel.
      Returns:
      the singleton instance of the EMFTVM metamodel
    • getTraceMetamodel

      public static Metamodel getTraceMetamodel()
      Returns the singleton instance of the Trace metamodel.
      Returns:
      the singleton instance of the Trace metamodel
    • findAllInstances

      public static LazyList<org.eclipse.emf.ecore.EObject> findAllInstances(org.eclipse.emf.ecore.EClass type, ExecEnv env)
      Finds all instances of type in the registered input/inout models.
      Parameters:
      type - the type
      env - the current ExecEnv
      Returns:
      all instances of type in the registered input/inout models
    • findAllInstIn

      public static LazyList<org.eclipse.emf.ecore.EObject> findAllInstIn(Object modelname, org.eclipse.emf.ecore.EClass type, ExecEnv env)
      Finds all instances of type in the given model.
      Parameters:
      modelname - the model name
      type - the type
      env - the current ExecEnv
      Returns:
      all instances of type in the given model
    • toPrettyString

      public static String toPrettyString(Object object, ExecEnv env)
      Offers an alternative to the default toString() method. Uses env to determine the containing model of types. Compensates for EObject's notoriously bad toString().
      Parameters:
      object -
      env -
      Returns:
      the string representation of object.
    • toPrettyString

      public static String toPrettyString(Collection<?> coll, ExecEnv env)
      Offers an alternative to the default toString() method. Uses env to determine the containing model of types. Compensates for EObject's notoriously bad toString().
      Parameters:
      coll -
      env -
      Returns:
      the string representation of coll.
    • toPrettyString

      public static <T> String toPrettyString(T[] array, ExecEnv env)
      Offers an alternative to the default toString() method. Uses env to determine the containing model of types. Compensates for EObject's notoriously bad toString().
      Parameters:
      array -
      env -
      Returns:
      the string representation of coll.
    • get

      public static Object get(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf)
      Retrieves the value of eo.sf. Checks that eo is not in an output model.
      Parameters:
      env - the current ExecEnv
      eo - the model element to retrieve the value from
      sf - the structural feature to retrieve the value from
      Returns:
      the value of eo.sf.
    • uncheckedGet

      public static Object uncheckedGet(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf)
      Retrieves the value of eo.sf.
      Parameters:
      env - the current ExecEnv
      eo - the model element to retrieve the value from
      sf - the structural feature to retrieve the value from
      Returns:
      the value of eo.sf.
    • emf2vm

      public static Object emf2vm(ExecEnv env, org.eclipse.emf.ecore.EObject eo, Object value)
      Converts value to an EMFTVM value.
      Parameters:
      env - the current ExecEnv
      eo - the EObject from which the value was obtained
      value - the EMF value to convert
      Returns:
      the EMFTVM value
    • set

      public static void set(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value)
      Sets the value of eo.sf.
      Parameters:
      env - the current ExecEnv
      eo - the model element to set the value for
      sf - the structural feature to set the value for
      value - the value to set
    • add

      public static void add(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value, int index)
      Adds the value of eo.sf.
      Parameters:
      env -
      eo -
      sf -
      value -
      index - the insertion index (-1 for end)
    • remove

      public static void remove(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value)
      Removes the value from eo.sf.
      Parameters:
      env -
      eo -
      sf -
      value -
    • getArgumentTypes

      public static Object[] getArgumentTypes(Object[] args)
      Retrieves the types of args.
      Parameters:
      args -
      Returns:
      the types of args
    • getArgumentType

      public static Object getArgumentType(Object arg)
      Retrieves the type of arg.
      Parameters:
      arg -
      Returns:
      the type of arg
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, String opname, Object[] args)
      Invokes native Java method opname on self with arguments args.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      opname - the method name
      args - the method arguments
      Returns:
      the method result
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, Method method, Object[] args)
      Invokes native Java method on self with arguments args.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      method - the method
      args - the method arguments
      Returns:
      the method result
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, String opname, Object arg)
      Invokes native Java method opname on self with argument arg.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      opname - the method name
      arg - the method argument
      Returns:
      the method result
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, Method method, Object arg)
      Invokes native Java method on self with argument arg.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      method - the method
      arg - the method argument
      Returns:
      the method result
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, String opname)
      Invokes native Java method opname on self without arguments.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      opname - the method name
      Returns:
      the method result
    • invokeNative

      public static Object invokeNative(StackFrame frame, Object self, Method method)
      Invokes native Java method on self without arguments.
      Parameters:
      frame - the current stack frame
      self - the object on which to invoke the method
      method - the method
      Returns:
      the method result
    • invokeNativeStatic

      public static Object invokeNativeStatic(StackFrame frame, Class<?> type, String opname, Object[] args)
      Invokes static native Java method opname with arguments args.
      Parameters:
      frame - the current stack frame
      type - the class in which the static method is defined
      opname - the method name
      args - the method arguments
      Returns:
      the method result
    • invokeNativeStatic

      public static Object invokeNativeStatic(StackFrame frame, Class<?> type, String opname, Object arg)
      Invokes static native Java method opname with argument arg.
      Parameters:
      frame - the current stack frame
      type - the class in which the static method is defined
      opname - the method name
      arg - the method arguments
      Returns:
      the method result
    • invokeNativeStatic

      public static Object invokeNativeStatic(StackFrame frame, Class<?> type, String opname)
      Invokes static native Java method opname without arguments.
      Parameters:
      frame - the current stack frame
      type - the class in which the static method is defined
      opname - the method name
      Returns:
      the method result
    • findNativeMethod

      public static Method findNativeMethod(Class<?> context, String opname, Class<?>[] argTypes, boolean isStatic)
      Looks for a native Java method.
      Parameters:
      context - The class of the method
      opname - The method name
      argTypes - The types of all arguments
      isStatic - Whether to look for a static method or not
      Returns:
      the method if found, null otherwise
    • findNativeMethod

      public static Method findNativeMethod(Class<?> context, String opname, Class<?> argType, boolean isStatic)
      Looks for a native Java method.
      Parameters:
      context - The class of the method
      opname - The method name
      argumentType - The type of the argument
      isStatic - Whether to look for a static method or not
      Returns:
      the method if found, null otherwise
    • findNativeMethod

      public static Method findNativeMethod(Class<?> context, String opname, boolean isStatic)
      Looks for a native Java method without arguments.
      Parameters:
      context - The class of the method
      opname - The method name
      isStatic - Whether to look for a static method or not
      Returns:
      the method if found, null otherwise
    • findNativeMethod

      public static Method findNativeMethod(Operation op, Object self, String opname)
      Looks for a native Java method without arguments.
      Parameters:
      op - the previously found EMFTVM Operation
      self - the object on which to invoke the method
      opname - the method name
      Returns:
      the method if found and more specific than op, null otherwise
    • findNativeMethod

      public static Method findNativeMethod(Operation op, Object self, String opname, Object arg)
      Looks for a native Java method with one argument.
      Parameters:
      op - the previously found EMFTVM Operation
      self - the object on which to invoke the method
      opname - the method name
      arg - the method argument
      Returns:
      the method if found and more specific than op, null otherwise
    • findNativeMethod

      public static Method findNativeMethod(Operation op, Object self, String opname, Object[] args)
      Looks for a native Java method with multiple arguments.
      Parameters:
      op - the previously found EMFTVM Operation
      self - the object on which to invoke the method
      opname - the method name
      args - the method arguments
      Returns:
      the method if found and more specific than op, null otherwise
    • findNativeSuperMethod

      public static Method findNativeSuperMethod(Operation op, Class<?> context, String opname)
      Looks for a native superclass Java method without arguments.
      Parameters:
      op - the previously found EMFTVM Operation
      context - the context for which to find the superclass method
      opname - the method name
      Returns:
      the method if found and more specific than op, null otherwise
    • findNativeSuperMethod

      public static Method findNativeSuperMethod(Operation op, Class<?> context, String opname, Object arg)
      Looks for a native superclass Java method with one argument.
      Parameters:
      op - the previously found EMFTVM Operation
      context - the context for which to find the superclass method
      name - the method name
      arg - the method argument
      Returns:
      the method if found and more specific than op, null otherwise
    • findNativeSuperMethod

      public static Method findNativeSuperMethod(Operation op, Class<?> context, String opname, Object[] args)
      Looks for a native superclass Java method with multiple arguments.
      Parameters:
      op - the previously found EMFTVM Operation
      context - the context for which to find the superclass method
      name - the method name
      args - the method arguments
      Returns:
      the method if found and more specific than op, null otherwise
    • findConstructor

      public static Constructor<?> findConstructor(Class<?> context, Class<?>[] argTypes)
      Looks for a native Java constructor.
      Parameters:
      context - The class of the method
      argumentTypes - The types of all arguments
      Returns:
      the constructor if found, null otherwise
    • getArgumentClasses

      public static Class<?>[] getArgumentClasses(Object[] args)
      Retrieves the classes of args.
      Parameters:
      args -
      Returns:
      the classes of args
    • writeToWithCharset

      public static boolean writeToWithCharset(String string, String path, String charset) throws IOException
      Writes string to path with the given charset.
      Parameters:
      string - the string to write
      path - the path of the file to write to
      charset - the character set to use, or use default when null
      Returns:
      true on success
      Throws:
      IOException - when writing fails
    • getFile

      public static File getFile(String path)
      Returns the file with the given path in the workspace, or the file in the filesystem if the workspace is not available.
      Parameters:
      path - the absolute or relative path to a file.
      Returns:
      the file in the workspace, or the file in the filesystem if the workspace is not available.
    • createOperation

      public static Operation createOperation(boolean isStatic, String name, String[] context, String[] returnType, String[][][] parameters, CodeBlock body)
      Creates a new Operation.
      Parameters:
      isStatic - whether the created operation is static
      name - operation name
      context - operation context [type model, type name]
      returnType - operation return [type model, type name]
      parameters - operations parameters: [[[name], [type model, type name]], ...]
      body - operation body
      Returns:
      a new Operation.
      See Also:
    • createField

      public static Field createField(String name, boolean isStatic, String[] context, String[] type, CodeBlock initialiser)
      Creates a new Field.
      Parameters:
      name - field name
      isStatic - whether the field is static
      context - field context [type model, type name]
      type - field [type model, type name]
      initialiser - field initialiser codeblock
      Returns:
      a new Field.
      See Also:
    • getTrans

      public static LazyList<Object> getTrans(Object object, Field field, StackFrame frame, LazyList<Object> result)
      Retrieves the transitive closure of field on object.
      Parameters:
      object - the object on which to retrieve field
      field - the field for which to retrieve the value
      frame - the current StackFrame
      result - the intermediate list of values
      Returns:
      the updated result
    • getTrans

      public static LazyList<Object> getTrans(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature sf, ExecEnv env, LazyList<Object> result)
      Retrieves the transitive closure of sf on object.
      Parameters:
      object - the object on which to retrieve sf
      sf - the structural feature for which to retrieve the value
      env - the current ExecEnv
      result - the intermediate list of values
      Returns:
      the updated result
    • getTrans

      public static LazyList<Object> getTrans(Object object, Field field, LazyList<Object> result) throws IllegalArgumentException, IllegalAccessException
      Retrieves the transitive closure of field on object.
      Parameters:
      object - the object on which to retrieve field
      field - the field for which to retrieve the value
      result - the intermediate list of values
      Returns:
      the updated result
      Throws:
      IllegalAccessException
      IllegalArgumentException
    • getLocale

      public static Locale getLocale(String locale)
      Returns the Locale for the given locale string.
      Parameters:
      locale - the locale string (e.g. "nl_BE", "es_ES_Traditional_WIN")
      Returns:
      the Locale for the given locale string
    • registerEPackages

      public static void registerEPackages(org.eclipse.emf.ecore.resource.ResourceSet rs)
      Registers all EPackage nsURIs in rs in the local rs EPackage.Registry. Sets the EPackage nsURI to the EPackage name if not set.
      Parameters:
      rs - the ResourceSet
    • findRootMethod

      public static Method findRootMethod(Method method)
      Finds the root Class declaration for the given method.
      Parameters:
      method - the method for which to find the root declaration
      Returns:
      the root Method
    • getMethodCacheHitRate

      public static double getMethodCacheHitRate()
      Returns the hit rate of the method cache.
      Returns:
      the hit rate of the method cache, or -1.0 if no hits were recorded yet
    • getRootMethodCacheHitRate

      public static double getRootMethodCacheHitRate()
      Returns the hit rate of the root method cache.
      Returns:
      the hit rate of the root method cache, or -1.0 if no hits were recorded yet