Package org.eclipse.m2m.atl.emftvm.util
Class EMFTVMUtil
java.lang.Object
org.eclipse.m2m.atl.emftvm.util.EMFTVMUtil
EMFTVM static utility methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classReturns the registry type of the switched object. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternType namespace matching pattern.static final StringName of the "init" static parameterless operation.static final StringName of the "main" static parameterless operation.static final StringNative type namespace.static final StringType namespace delimiter.static final StringName if the XMI ID feature forEObjects contained inXMIResources. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadd(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value, int index) Adds thevalueofeo.sf.static voidcheckRuleArgCount(StackFrame frame, Rule rule, int argcount) Checks the rule argument count.static FieldcreateField(String name, boolean isStatic, String[] context, String[] type, CodeBlock initialiser) Creates a newField.static OperationcreateOperation(boolean isStatic, String name, String[] context, String[] returnType, String[][][] parameters, CodeBlock body) Creates a newOperation.static ObjectConvertsvalueto an EMFTVM value.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.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.static Constructor<?> findConstructor(Class<?> context, Class<?>[] argTypes) Looks for a native Java constructor.static MethodfindNativeMethod(Class<?> context, String opname, boolean isStatic) Looks for a native Java method without arguments.static MethodfindNativeMethod(Class<?> context, String opname, Class<?>[] argTypes, boolean isStatic) Looks for a native Java method.static MethodfindNativeMethod(Class<?> context, String opname, Class<?> argType, boolean isStatic) Looks for a native Java method.static MethodfindNativeMethod(Operation op, Object self, String opname) Looks for a native Java method without arguments.static MethodfindNativeMethod(Operation op, Object self, String opname, Object arg) Looks for a native Java method with one argument.static MethodfindNativeMethod(Operation op, Object self, String opname, Object[] args) Looks for a native Java method with multiple arguments.static MethodfindNativeSuperMethod(Operation op, Class<?> context, String opname) Looks for a native superclass Java method without arguments.static MethodfindNativeSuperMethod(Operation op, Class<?> context, String opname, Object arg) Looks for a native superclass Java method with one argument.static MethodfindNativeSuperMethod(Operation op, Class<?> context, String opname, Object[] args) Looks for a native superclass Java method with multiple arguments.static MethodfindRootMethod(Method method) Finds the rootClassdeclaration for the givenmethod.static ObjectRetrieves the value ofeo.sf.static Class<?>[]getArgumentClasses(Object[] args) Retrieves the classes ofargs.static ObjectgetArgumentType(Object arg) Retrieves the type ofarg.static Object[]getArgumentTypes(Object[] args) Retrieves the types ofargs.static MetamodelReturns the singleton instance of the Ecore metamodel.static MetamodelReturns the singleton instance of the EMFTVM metamodel.static FileReturns the file with the givenpathin the workspace, or the file in the filesystem if the workspace is not available.static LocaleReturns theLocalefor the givenlocalestring.static doubleReturns the hit rate of the method cache.static ObjectgetRegistryType(Object type) Returns the type object to use for the registry.static doubleReturns the hit rate of the root method cache.static MetamodelReturns the singleton instance of the Trace metamodel.Retrieves the transitive closure offieldonobject.Retrieves the transitive closure offieldonobject.getTrans(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature sf, ExecEnv env, LazyList<Object> result) Retrieves the transitive closure ofsfonobject.static StringgetTypeName(ExecEnv env, Object type) Returns the name oftype, for printing.static StringgetTypeNames(ExecEnv env, Object[] types) Returns the names oftypes, for printing.static ObjectinvokeNative(StackFrame frame, Object self, Method method) Invokes native Javamethodonselfwithout arguments.static ObjectinvokeNative(StackFrame frame, Object self, Method method, Object arg) Invokes native Javamethodonselfwith argumentarg.static ObjectinvokeNative(StackFrame frame, Object self, Method method, Object[] args) Invokes native Javamethodonselfwith argumentsargs.static ObjectinvokeNative(StackFrame frame, Object self, String opname) Invokes native Java methodopnameonselfwithout arguments.static ObjectinvokeNative(StackFrame frame, Object self, String opname, Object arg) Invokes native Java methodopnameonselfwith argumentarg.static ObjectinvokeNative(StackFrame frame, Object self, String opname, Object[] args) Invokes native Java methodopnameonselfwith argumentsargs.static ObjectinvokeNativeStatic(StackFrame frame, Class<?> type, String opname) Invokes static native Java methodopnamewithout arguments.static ObjectinvokeNativeStatic(StackFrame frame, Class<?> type, String opname, Object arg) Invokes static native Java methodopnamewith argumentarg.static ObjectinvokeNativeStatic(StackFrame frame, Class<?> type, String opname, Object[] args) Invokes static native Java methodopnamewith argumentsargs.static voidregisterEPackages(org.eclipse.emf.ecore.resource.ResourceSet rs) Registers allEPackagensURIs inrsin the localrsEPackage.Registry.static voidremove(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value) Removes thevaluefromeo.sf.static voidset(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value) Sets thevalueofeo.sf.static StringtoPrettyString(Object object, ExecEnv env) Offers an alternative to the defaulttoString()method.static StringtoPrettyString(Collection<?> coll, ExecEnv env) Offers an alternative to the defaulttoString()method.static <T> StringtoPrettyString(T[] array, ExecEnv env) Offers an alternative to the defaulttoString()method.static ObjectuncheckedGet(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf) Retrieves the value ofeo.sf.static booleanwriteToWithCharset(String string, String path, String charset) Writesstringtopathwith the givencharset.
-
Field Details
-
NATIVE
Native type namespace.- See Also:
-
NS_DELIM
Type namespace delimiter.- See Also:
-
DELIM_PATTERN
Type namespace matching pattern.- See Also:
-
MAIN_OP_NAME
Name of the "main" static parameterless operation.- See Also:
-
INIT_OP_NAME
Name of the "init" static parameterless operation.- See Also:
-
XMI_ID_FEATURE
Name if the XMI ID feature forEObjects contained inXMIResources.- See Also:
-
-
Method Details
-
getTypeName
Returns the name oftype, for printing.- Parameters:
env- the currentExecEnvtype- the type- Returns:
- the name of
type, for printing
-
getTypeNames
Returns the names oftypes, for printing.- Parameters:
env- the currentExecEnv.types- the types- Returns:
- the names of
types, for printing
-
getRegistryType
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
Returns the singleton instance of the Ecore metamodel.- Returns:
- the singleton instance of the Ecore metamodel
-
getEmfTvmMetamodel
Returns the singleton instance of the EMFTVM metamodel.- Returns:
- the singleton instance of the EMFTVM 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 typeenv- the currentExecEnv- 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 nametype- the typeenv- the currentExecEnv- Returns:
- all instances of type in the given model
-
toPrettyString
Offers an alternative to the defaulttoString()method. Usesenvto determine the containing model of types. Compensates forEObject's notoriously badtoString().- Parameters:
object-env-- Returns:
- the string representation of
object.
-
toPrettyString
Offers an alternative to the defaulttoString()method. Usesenvto determine the containing model of types. Compensates forEObject's notoriously badtoString().- Parameters:
coll-env-- Returns:
- the string representation of
coll.
-
toPrettyString
Offers an alternative to the defaulttoString()method. Usesenvto determine the containing model of types. Compensates forEObject's notoriously badtoString().- 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 ofeo.sf. Checks thateois not in an output model.- Parameters:
env- the currentExecEnveo- the model element to retrieve the value fromsf- 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 ofeo.sf.- Parameters:
env- the currentExecEnveo- the model element to retrieve the value fromsf- the structural feature to retrieve the value from- Returns:
- the value of
eo.sf.
-
emf2vm
Convertsvalueto an EMFTVM value.- Parameters:
env- the currentExecEnveo- theEObjectfrom which the value was obtainedvalue- 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 thevalueofeo.sf.- Parameters:
env- the currentExecEnveo- the model element to set the value forsf- the structural feature to set the value forvalue- 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 thevalueofeo.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 thevaluefromeo.sf.- Parameters:
env-eo-sf-value-
-
getArgumentTypes
Retrieves the types ofargs.- Parameters:
args-- Returns:
- the types of
args
-
getArgumentType
Retrieves the type ofarg.- Parameters:
arg-- Returns:
- the type of
arg
-
invokeNative
Invokes native Java methodopnameonselfwith argumentsargs.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodopname- the method nameargs- the method arguments- Returns:
- the method result
-
invokeNative
Invokes native Javamethodonselfwith argumentsargs.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodmethod- the methodargs- the method arguments- Returns:
- the method result
-
invokeNative
Invokes native Java methodopnameonselfwith argumentarg.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodopname- the method namearg- the method argument- Returns:
- the method result
-
invokeNative
Invokes native Javamethodonselfwith argumentarg.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodmethod- the methodarg- the method argument- Returns:
- the method result
-
invokeNative
Invokes native Java methodopnameonselfwithout arguments.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodopname- the method name- Returns:
- the method result
-
invokeNative
Invokes native Javamethodonselfwithout arguments.- Parameters:
frame- the current stack frameself- the object on which to invoke the methodmethod- the method- Returns:
- the method result
-
invokeNativeStatic
public static Object invokeNativeStatic(StackFrame frame, Class<?> type, String opname, Object[] args) Invokes static native Java methodopnamewith argumentsargs.- Parameters:
frame- the current stack frametype- the class in which the static method is definedopname- the method nameargs- the method arguments- Returns:
- the method result
-
invokeNativeStatic
Invokes static native Java methodopnamewith argumentarg.- Parameters:
frame- the current stack frametype- the class in which the static method is definedopname- the method namearg- the method arguments- Returns:
- the method result
-
invokeNativeStatic
Invokes static native Java methodopnamewithout arguments.- Parameters:
frame- the current stack frametype- the class in which the static method is definedopname- 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 methodopname- The method nameargTypes- The types of all argumentsisStatic- 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 methodopname- The method nameisStatic- Whether to look for a static method or notargumentType- The type of the argument- Returns:
- the method if found, null otherwise
-
findNativeMethod
Looks for a native Java method without arguments.- Parameters:
context- The class of the methodopname- The method nameisStatic- Whether to look for a static method or not- Returns:
- the method if found, null otherwise
-
findNativeMethod
Looks for a native Java method without arguments.- Parameters:
op- the previously found EMFTVMOperationself- the object on which to invoke the methodopname- the method name- Returns:
- the method if found and more specific than
op,nullotherwise
-
findNativeMethod
Looks for a native Java method with one argument.- Parameters:
op- the previously found EMFTVMOperationself- the object on which to invoke the methodopname- the method namearg- the method argument- Returns:
- the method if found and more specific than
op,nullotherwise
-
findNativeMethod
Looks for a native Java method with multiple arguments.- Parameters:
op- the previously found EMFTVMOperationself- the object on which to invoke the methodopname- the method nameargs- the method arguments- Returns:
- the method if found and more specific than
op,nullotherwise
-
findNativeSuperMethod
Looks for a native superclass Java method without arguments.- Parameters:
op- the previously found EMFTVMOperationcontext- the context for which to find the superclass methodopname- the method name- Returns:
- the method if found and more specific than
op,nullotherwise
-
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 EMFTVMOperationcontext- the context for which to find the superclass methodarg- the method argumentname- the method name- Returns:
- the method if found and more specific than
op,nullotherwise
-
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 EMFTVMOperationcontext- the context for which to find the superclass methodargs- the method argumentsname- the method name- Returns:
- the method if found and more specific than
op,nullotherwise
-
findConstructor
Looks for a native Java constructor.- Parameters:
context- The class of the methodargumentTypes- The types of all arguments- Returns:
- the constructor if found,
nullotherwise
-
getArgumentClasses
Retrieves the classes ofargs.- Parameters:
args-- Returns:
- the classes of
args
-
writeToWithCharset
public static boolean writeToWithCharset(String string, String path, String charset) throws IOException Writesstringtopathwith the givencharset.- Parameters:
string- the string to writepath- the path of the file to write tocharset- the character set to use, or use default when null- Returns:
- true on success
- Throws:
IOException- when writing fails
-
getFile
Returns the file with the givenpathin 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 newOperation.- Parameters:
isStatic- whether the created operation is staticname- operation namecontext- 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 newField.- Parameters:
name- field nameisStatic- whether the field is staticcontext- 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 offieldonobject.- Parameters:
object- the object on which to retrievefieldfield- the field for which to retrieve the valueframe- the currentStackFrameresult- 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 ofsfonobject.- Parameters:
object- the object on which to retrievesfsf- the structural feature for which to retrieve the valueenv- the currentExecEnvresult- 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 offieldonobject.- Parameters:
object- the object on which to retrievefieldfield- the field for which to retrieve the valueresult- the intermediate list of values- Returns:
- the updated result
- Throws:
IllegalAccessExceptionIllegalArgumentException
-
getLocale
Returns theLocalefor the givenlocalestring.- Parameters:
locale- the locale string (e.g. "nl_BE", "es_ES_Traditional_WIN")- Returns:
- the
Localefor the givenlocalestring
-
registerEPackages
public static void registerEPackages(org.eclipse.emf.ecore.resource.ResourceSet rs) Registers allEPackagensURIs inrsin the localrsEPackage.Registry. Sets theEPackagensURI to theEPackagename if not set.- Parameters:
rs- theResourceSet
-
findRootMethod
Finds the rootClassdeclaration for the givenmethod.- 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.0if 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.0if no hits were recorded yet
-
checkRuleArgCount
Checks the rule argument count.- Parameters:
frame- the current stack framerule- the rule for which to checkargs- the arguments to check against the rule- Throws:
VMException- if the argument count does not match the rule's input elements count
-