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
Modifier and TypeClassDescriptionstatic class
Returns the registry type of the switched object. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
Type namespace matching pattern.static final String
Name of the "init" static parameterless operation.static final String
Name of the "main" static parameterless operation.static final String
Native type namespace.static final String
Type namespace delimiter.static final String
Name if the XMI ID feature forEObject
s contained inXMIResource
s. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
add
(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value, int index) Adds thevalue
ofeo.sf
.static Field
createField
(String name, boolean isStatic, String[] context, String[] type, CodeBlock initialiser) Creates a newField
.static Operation
createOperation
(boolean isStatic, String name, String[] context, String[] returnType, String[][][] parameters, CodeBlock body) Creates a newOperation
.static Object
Convertsvalue
to 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 Method
findNativeMethod
(Class<?> context, String opname, boolean isStatic) Looks for a native Java method without arguments.static Method
findNativeMethod
(Class<?> context, String opname, Class<?>[] argTypes, boolean isStatic) Looks for a native Java method.static Method
findNativeMethod
(Class<?> context, String opname, Class<?> argType, boolean isStatic) Looks for a native Java method.static Method
findNativeMethod
(Operation op, Object self, String opname) Looks for a native Java method without arguments.static Method
findNativeMethod
(Operation op, Object self, String opname, Object arg) Looks for a native Java method with one argument.static Method
findNativeMethod
(Operation op, Object self, String opname, Object[] args) Looks for a native Java method with multiple arguments.static Method
findNativeSuperMethod
(Operation op, Class<?> context, String opname) Looks for a native superclass Java method without arguments.static Method
findNativeSuperMethod
(Operation op, Class<?> context, String opname, Object arg) Looks for a native superclass Java method with one argument.static Method
findNativeSuperMethod
(Operation op, Class<?> context, String opname, Object[] args) Looks for a native superclass Java method with multiple arguments.static Method
findRootMethod
(Method method) Finds the rootClass
declaration for the givenmethod
.static Object
Retrieves the value ofeo.sf
.static Class<?>[]
getArgumentClasses
(Object[] args) Retrieves the classes ofargs
.static Object
getArgumentType
(Object arg) Retrieves the type ofarg
.static Object[]
getArgumentTypes
(Object[] args) Retrieves the types ofargs
.static Metamodel
Returns the singleton instance of the Ecore metamodel.static Metamodel
Returns the singleton instance of the EMFTVM metamodel.static File
Returns the file with the givenpath
in the workspace, or the file in the filesystem if the workspace is not available.static Locale
Returns theLocale
for the givenlocale
string.static double
Returns the hit rate of the method cache.static Object
getRegistryType
(Object type) Returns the type object to use for the registry.static double
Returns the hit rate of the root method cache.static Metamodel
Returns the singleton instance of the Trace metamodel.Retrieves the transitive closure offield
onobject
.Retrieves the transitive closure offield
onobject
.getTrans
(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature sf, ExecEnv env, LazyList<Object> result) Retrieves the transitive closure ofsf
onobject
.static String
getTypeName
(ExecEnv env, Object type) Returns the name oftype
, for printing.static String
getTypeNames
(ExecEnv env, Object[] types) Returns the names oftypes
, for printing.static Object
invokeNative
(StackFrame frame, Object self, Method method) Invokes native Javamethod
onself
without arguments.static Object
invokeNative
(StackFrame frame, Object self, Method method, Object arg) Invokes native Javamethod
onself
with argumentarg
.static Object
invokeNative
(StackFrame frame, Object self, Method method, Object[] args) Invokes native Javamethod
onself
with argumentsargs
.static Object
invokeNative
(StackFrame frame, Object self, String opname) Invokes native Java methodopname
onself
without arguments.static Object
invokeNative
(StackFrame frame, Object self, String opname, Object arg) Invokes native Java methodopname
onself
with argumentarg
.static Object
invokeNative
(StackFrame frame, Object self, String opname, Object[] args) Invokes native Java methodopname
onself
with argumentsargs
.static Object
invokeNativeStatic
(StackFrame frame, Class<?> type, String opname) Invokes static native Java methodopname
without arguments.static Object
invokeNativeStatic
(StackFrame frame, Class<?> type, String opname, Object arg) Invokes static native Java methodopname
with argumentarg
.static Object
invokeNativeStatic
(StackFrame frame, Class<?> type, String opname, Object[] args) Invokes static native Java methodopname
with argumentsargs
.static void
registerEPackages
(org.eclipse.emf.ecore.resource.ResourceSet rs) Registers allEPackage
nsURIs inrs
in the localrs
EPackage.Registry
.static void
remove
(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value) Removes thevalue
fromeo.sf
.static void
set
(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf, Object value) Sets thevalue
ofeo.sf
.static String
toPrettyString
(Object object, ExecEnv env) Offers an alternative to the defaulttoString()
method.static String
toPrettyString
(Collection<?> coll, ExecEnv env) Offers an alternative to the defaulttoString()
method.static <T> String
toPrettyString
(T[] array, ExecEnv env) Offers an alternative to the defaulttoString()
method.static Object
uncheckedGet
(ExecEnv env, org.eclipse.emf.ecore.EObject eo, org.eclipse.emf.ecore.EStructuralFeature sf) Retrieves the value ofeo.sf
.static boolean
writeToWithCharset
(String string, String path, String charset) Writesstring
topath
with 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 forEObject
s contained inXMIResource
s.- See Also:
-
-
Method Details
-
getTypeName
Returns the name oftype
, for printing.- Parameters:
env
- the currentExecEnv
type
- 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. Usesenv
to 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. Usesenv
to 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. Usesenv
to 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 thateo
is not in an output model.- Parameters:
env
- the currentExecEnv
eo
- 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 currentExecEnv
eo
- the model element to retrieve the value fromsf
- the structural feature to retrieve the value from- Returns:
- the value of
eo.sf
.
-
emf2vm
Convertsvalue
to an EMFTVM value.- Parameters:
env
- the currentExecEnv
eo
- theEObject
from 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 thevalue
ofeo.sf
.- Parameters:
env
- the currentExecEnv
eo
- 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 thevalue
ofeo.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 thevalue
fromeo.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 methodopname
onself
with 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 Javamethod
onself
with 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 methodopname
onself
with 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 Javamethod
onself
with 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 methodopname
onself
without 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 Javamethod
onself
without 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 methodopname
with 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 methodopname
with 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 methodopname
without 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 nameargumentType
- The type of the argumentisStatic
- 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:
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 EMFTVMOperation
self
- the object on which to invoke the methodopname
- the method name- Returns:
- the method if found and more specific than
op
,null
otherwise
-
findNativeMethod
Looks for a native Java method with one argument.- Parameters:
op
- the previously found EMFTVMOperation
self
- the object on which to invoke the methodopname
- the method namearg
- the method argument- Returns:
- the method if found and more specific than
op
,null
otherwise
-
findNativeMethod
Looks for a native Java method with multiple arguments.- Parameters:
op
- the previously found EMFTVMOperation
self
- the object on which to invoke the methodopname
- the method nameargs
- the method arguments- Returns:
- the method if found and more specific than
op
,null
otherwise
-
findNativeSuperMethod
Looks for a native superclass Java method without arguments.- Parameters:
op
- the previously found EMFTVMOperation
context
- the context for which to find the superclass methodopname
- 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 EMFTVMOperation
context
- the context for which to find the superclass methodname
- the method namearg
- 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 EMFTVMOperation
context
- the context for which to find the superclass methodname
- the method nameargs
- the method arguments- Returns:
- the method if found and more specific than
op
,null
otherwise
-
findConstructor
Looks for a native Java constructor.- Parameters:
context
- The class of the methodargumentTypes
- The types of all arguments- Returns:
- the constructor if found,
null
otherwise
-
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 Writesstring
topath
with 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 givenpath
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 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
. -
getTrans
public static LazyList<Object> getTrans(Object object, Field field, StackFrame frame, LazyList<Object> result) Retrieves the transitive closure offield
onobject
.- Parameters:
object
- the object on which to retrievefield
field
- the field for which to retrieve the valueframe
- the currentStackFrame
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 ofsf
onobject
.- Parameters:
object
- the object on which to retrievesf
sf
- the structural feature for which to retrieve the valueenv
- the currentExecEnv
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 offield
onobject
.- Parameters:
object
- the object on which to retrievefield
field
- the field for which to retrieve the valueresult
- the intermediate list of values- Returns:
- the updated result
- Throws:
IllegalAccessException
IllegalArgumentException
-
getLocale
Returns theLocale
for the givenlocale
string.- Parameters:
locale
- the locale string (e.g. "nl_BE", "es_ES_Traditional_WIN")- Returns:
- the
Locale
for the givenlocale
string
-
registerEPackages
public static void registerEPackages(org.eclipse.emf.ecore.resource.ResourceSet rs) Registers allEPackage
nsURIs inrs
in the localrs
EPackage.Registry
. Sets theEPackage
nsURI to theEPackage
name if not set.- Parameters:
rs
- theResourceSet
-
findRootMethod
Finds the rootClass
declaration 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.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
-