Package org.codehaus.groovy.runtime
Class InvokerHelper
- java.lang.Object
-
- org.codehaus.groovy.runtime.InvokerHelper
-
public class InvokerHelper extends java.lang.ObjectA static helper class to make bytecode generation easier and act as a facade over the Invoker
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object[]EMPTY_ARGSprotected static java.lang.Object[]EMPTY_ARGUMENTSprotected static java.lang.Class[]EMPTY_TYPESstatic java.lang.StringMAIN_METHOD_NAMEstatic MetaClassRegistrymetaRegistry
-
Constructor Summary
Constructors Constructor Description InvokerHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappend(java.lang.Appendable out, java.lang.Object object)Appends an object to an Appendable using Groovy's default representation for the object.static java.lang.Object[]asArray(java.lang.Object arguments)Converts the given object into an array; if its an array then just cast otherwise wrap it in an arraystatic java.util.Iterator<java.lang.Object>asIterator(java.lang.Object o)static java.util.ListasList(java.lang.Object value)static voidassertFailed(java.lang.Object expression, java.lang.Object message)static java.lang.Object[]asUnwrappedArray(java.lang.Object arguments)static java.lang.ObjectbitwiseNegate(java.lang.Object value)static java.util.ListcreateList(java.lang.Object[] values)static java.util.MapcreateMap(java.lang.Object[] values)static java.util.ListcreateRange(java.lang.Object from, java.lang.Object to, boolean inclusive)static ScriptcreateScript(java.lang.Class scriptClass, Binding context)static TuplecreateTuple(java.lang.Object[] array)static java.lang.StringescapeBackslashes(java.lang.String orig)static java.util.regex.MatcherfindRegex(java.lang.Object left, java.lang.Object right)Find the right hand regex within the left hand string and return a matcher.protected static java.lang.Stringformat(java.lang.Object arguments, boolean verbose)static java.lang.Stringformat(java.lang.Object arguments, boolean verbose, int maxSize)static java.lang.Stringformat(java.lang.Object arguments, boolean verbose, int maxSize, boolean safe)static java.lang.ObjectgetAttribute(java.lang.Object object, java.lang.String attribute)static java.lang.ObjectgetGroovyObjectProperty(GroovyObject object, java.lang.String property)static MetaClassgetMetaClass(java.lang.Class cls)static MetaClassgetMetaClass(java.lang.Object object)static MetaClassRegistrygetMetaRegistry()static ClosuregetMethodPointer(java.lang.Object object, java.lang.String methodName)Returns the method pointer for the given object namestatic java.lang.ObjectgetProperty(java.lang.Object object, java.lang.String property)static java.lang.ObjectgetPropertySafe(java.lang.Object object, java.lang.String property)static java.lang.Stringinspect(java.lang.Object self)static java.lang.ObjectinvokeClosure(java.lang.Object closure, java.lang.Object arguments)static java.lang.ObjectinvokeConstructorOf(java.lang.Class type, java.lang.Object arguments)static java.lang.ObjectinvokeConstructorOf(java.lang.String klass, java.lang.Object arguments)static java.lang.ObjectinvokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Invokes the given method on the object.static java.lang.ObjectinvokeMethodSafe(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)static java.lang.ObjectinvokeNoArgumentsConstructorOf(java.lang.Class type)static java.lang.ObjectinvokeStaticMethod(java.lang.Class type, java.lang.String method, java.lang.Object arguments)static java.lang.ObjectinvokeStaticMethod(java.lang.String klass, java.lang.String methodName, java.lang.Object arguments)static java.lang.ObjectinvokeStaticNoArgumentsMethod(java.lang.Class type, java.lang.String methodName)static java.lang.ObjectinvokeSuperMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)static booleanmatchRegex(java.lang.Object left, java.lang.Object right)Find the right hand regex within the left hand string and return a matcher.static ScriptnewScript(java.lang.Class<?> scriptClass, Binding context)static voidremoveClass(java.lang.Class clazz)static java.lang.ObjectrunScript(java.lang.Class scriptClass, java.lang.String[] args)static voidsetAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)static voidsetGroovyObjectProperty(java.lang.Object newValue, GroovyObject object, java.lang.String property)This is so we don't have to reorder the stack when we call this method.static voidsetProperties(java.lang.Object object, java.util.Map map)Sets the properties on the given objectstatic voidsetProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)static voidsetProperty2(java.lang.Object newValue, java.lang.Object object, java.lang.String property)This is so we don't have to reorder the stack when we call this method.static voidsetPropertySafe2(java.lang.Object newValue, java.lang.Object object, java.lang.String property)This is so we don't have to reorder the stack when we call this method.static SpreadMapspreadMap(java.lang.Object value)static java.lang.StringtoArrayString(java.lang.Object[] arguments)A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static java.lang.StringtoArrayString(java.lang.Object[] arguments, int maxSize, boolean safe)A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static java.lang.StringtoListString(java.util.Collection arg)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static java.lang.StringtoListString(java.util.Collection arg, int maxSize)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static java.lang.StringtoListString(java.util.Collection arg, int maxSize, boolean safe)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static java.lang.StringtoMapString(java.util.Map arg)A helper method to return the string representation of a map with bracket boundaries "[" and "]".static java.lang.StringtoMapString(java.util.Map arg, int maxSize)A helper method to return the string representation of a map with bracket boundaries "[" and "]".static java.lang.StringtoString(java.lang.Object arguments)static java.lang.StringtoTypeString(java.lang.Object[] arguments)A helper method to format the arguments types as a comma-separated list.static java.lang.StringtoTypeString(java.lang.Object[] arguments, int maxSize)A helper method to format the arguments types as a comma-separated list.static java.lang.ObjectunaryMinus(java.lang.Object value)static java.lang.ObjectunaryPlus(java.lang.Object value)static voidwrite(java.io.Writer out, java.lang.Object object)Writes an object to a Writer using Groovy's default representation for the object.
-
-
-
Field Detail
-
EMPTY_ARGS
public static final java.lang.Object[] EMPTY_ARGS
-
EMPTY_ARGUMENTS
protected static final java.lang.Object[] EMPTY_ARGUMENTS
-
EMPTY_TYPES
protected static final java.lang.Class[] EMPTY_TYPES
-
metaRegistry
public static final MetaClassRegistry metaRegistry
-
MAIN_METHOD_NAME
public static final java.lang.String MAIN_METHOD_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
removeClass
public static void removeClass(java.lang.Class clazz)
-
invokeMethodSafe
public static java.lang.Object invokeMethodSafe(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
-
invokeStaticMethod
public static java.lang.Object invokeStaticMethod(java.lang.String klass, java.lang.String methodName, java.lang.Object arguments) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
invokeStaticNoArgumentsMethod
public static java.lang.Object invokeStaticNoArgumentsMethod(java.lang.Class type, java.lang.String methodName)
-
invokeConstructorOf
public static java.lang.Object invokeConstructorOf(java.lang.String klass, java.lang.Object arguments) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
invokeNoArgumentsConstructorOf
public static java.lang.Object invokeNoArgumentsConstructorOf(java.lang.Class type)
-
invokeClosure
public static java.lang.Object invokeClosure(java.lang.Object closure, java.lang.Object arguments)
-
asList
public static java.util.List asList(java.lang.Object value)
-
toString
public static java.lang.String toString(java.lang.Object arguments)
-
inspect
public static java.lang.String inspect(java.lang.Object self)
-
getAttribute
public static java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
-
setAttribute
public static void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
-
getProperty
public static java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
-
getPropertySafe
public static java.lang.Object getPropertySafe(java.lang.Object object, java.lang.String property)
-
setProperty
public static void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
-
setProperty2
public static void setProperty2(java.lang.Object newValue, java.lang.Object object, java.lang.String property)This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
-
setGroovyObjectProperty
public static void setGroovyObjectProperty(java.lang.Object newValue, GroovyObject object, java.lang.String property)This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
-
getGroovyObjectProperty
public static java.lang.Object getGroovyObjectProperty(GroovyObject object, java.lang.String property)
-
setPropertySafe2
public static void setPropertySafe2(java.lang.Object newValue, java.lang.Object object, java.lang.String property)This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
-
getMethodPointer
public static Closure getMethodPointer(java.lang.Object object, java.lang.String methodName)
Returns the method pointer for the given object name
-
unaryMinus
public static java.lang.Object unaryMinus(java.lang.Object value)
-
unaryPlus
public static java.lang.Object unaryPlus(java.lang.Object value)
-
findRegex
public static java.util.regex.Matcher findRegex(java.lang.Object left, java.lang.Object right)Find the right hand regex within the left hand string and return a matcher.- Parameters:
left- string to compareright- regular expression to compare the string to
-
matchRegex
public static boolean matchRegex(java.lang.Object left, java.lang.Object right)Find the right hand regex within the left hand string and return a matcher.- Parameters:
left- string to compareright- regular expression to compare the string to
-
createTuple
public static Tuple createTuple(java.lang.Object[] array)
-
spreadMap
public static SpreadMap spreadMap(java.lang.Object value)
-
createList
public static java.util.List createList(java.lang.Object[] values)
-
createMap
public static java.util.Map createMap(java.lang.Object[] values)
-
assertFailed
public static void assertFailed(java.lang.Object expression, java.lang.Object message)
-
runScript
public static java.lang.Object runScript(java.lang.Class scriptClass, java.lang.String[] args)
-
newScript
public static Script newScript(java.lang.Class<?> scriptClass, Binding context) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
setProperties
public static void setProperties(java.lang.Object object, java.util.Map map)Sets the properties on the given object
-
write
public static void write(java.io.Writer out, java.lang.Object object) throws java.io.IOExceptionWrites an object to a Writer using Groovy's default representation for the object.- Throws:
java.io.IOException
-
append
public static void append(java.lang.Appendable out, java.lang.Object object) throws java.io.IOExceptionAppends an object to an Appendable using Groovy's default representation for the object.- Throws:
java.io.IOException
-
asIterator
public static java.util.Iterator<java.lang.Object> asIterator(java.lang.Object o)
-
format
protected static java.lang.String format(java.lang.Object arguments, boolean verbose)
-
format
public static java.lang.String format(java.lang.Object arguments, boolean verbose, int maxSize)
-
format
public static java.lang.String format(java.lang.Object arguments, boolean verbose, int maxSize, boolean safe)
-
escapeBackslashes
public static java.lang.String escapeBackslashes(java.lang.String orig)
-
toTypeString
public static java.lang.String toTypeString(java.lang.Object[] arguments)
A helper method to format the arguments types as a comma-separated list.- Parameters:
arguments- the type to process- Returns:
- the string representation of the type
-
toTypeString
public static java.lang.String toTypeString(java.lang.Object[] arguments, int maxSize)A helper method to format the arguments types as a comma-separated list.- Parameters:
arguments- the type to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stop- Returns:
- the string representation of the type
-
toMapString
public static java.lang.String toMapString(java.util.Map arg)
A helper method to return the string representation of a map with bracket boundaries "[" and "]".- Parameters:
arg- the map to process- Returns:
- the string representation of the map
-
toMapString
public static java.lang.String toMapString(java.util.Map arg, int maxSize)A helper method to return the string representation of a map with bracket boundaries "[" and "]".- Parameters:
arg- the map to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stop- Returns:
- the string representation of the map
-
toListString
public static java.lang.String toListString(java.util.Collection arg)
A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to process- Returns:
- the string representation of the collection
-
toListString
public static java.lang.String toListString(java.util.Collection arg, int maxSize)A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to processmaxSize- stop after approximately this many characters and append '...'- Returns:
- the string representation of the collection
-
toListString
public static java.lang.String toListString(java.util.Collection arg, int maxSize, boolean safe)A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stopsafe- whether to use a default object representation for any item in the collection if an exception occurs when generating its toString- Returns:
- the string representation of the collection
-
toArrayString
public static java.lang.String toArrayString(java.lang.Object[] arguments)
A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".- Parameters:
arguments- the array to process- Returns:
- the string representation of the array
-
toArrayString
public static java.lang.String toArrayString(java.lang.Object[] arguments, int maxSize, boolean safe)A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".- Parameters:
arguments- the array to processmaxSize- stop after approximately this many characters and append '...'safe- whether to use a default object representation for any item in the array if an exception occurs when generating its toString- Returns:
- the string representation of the array
-
createRange
public static java.util.List createRange(java.lang.Object from, java.lang.Object to, boolean inclusive)
-
bitwiseNegate
public static java.lang.Object bitwiseNegate(java.lang.Object value)
-
getMetaRegistry
public static MetaClassRegistry getMetaRegistry()
-
getMetaClass
public static MetaClass getMetaClass(java.lang.Object object)
-
getMetaClass
public static MetaClass getMetaClass(java.lang.Class cls)
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Invokes the given method on the object.
-
invokeSuperMethod
public static java.lang.Object invokeSuperMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
-
invokeStaticMethod
public static java.lang.Object invokeStaticMethod(java.lang.Class type, java.lang.String method, java.lang.Object arguments)
-
invokeConstructorOf
public static java.lang.Object invokeConstructorOf(java.lang.Class type, java.lang.Object arguments)
-
asArray
public static java.lang.Object[] asArray(java.lang.Object arguments)
Converts the given object into an array; if its an array then just cast otherwise wrap it in an array
-
asUnwrappedArray
public static java.lang.Object[] asUnwrappedArray(java.lang.Object arguments)
-
-