Package org.codehaus.groovy.runtime
Class InvokerHelper
java.lang.Object
org.codehaus.groovy.runtime.InvokerHelper
public class InvokerHelper
extends java.lang.Object
A static helper class to make bytecode generation easier and act as a facade over the Invoker
- 
Field SummaryFields 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 SummaryConstructors Constructor Description InvokerHelper()
- 
Method SummaryModifier 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 intinitialCapacity(int initialEntryCnt)According to the initial entry count, calculate the initial capacity of hash map, which is power of 2 (SEE https://stackoverflow.com/questions/8352378/why-does-hashmap-require-that-the-initial-capacity-be-a-power-of-two)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.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Field Details- 
EMPTY_ARGSpublic static final java.lang.Object[] EMPTY_ARGS
- 
EMPTY_ARGUMENTSprotected static final java.lang.Object[] EMPTY_ARGUMENTS
- 
EMPTY_TYPESprotected static final java.lang.Class[] EMPTY_TYPES
- 
metaRegistry
- 
MAIN_METHOD_NAMEpublic static final java.lang.String MAIN_METHOD_NAME- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
InvokerHelperpublic InvokerHelper()
 
- 
- 
Method Details- 
removeClasspublic static void removeClass(java.lang.Class clazz)
- 
invokeMethodSafepublic static java.lang.Object invokeMethodSafe(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
- 
invokeStaticMethodpublic 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
 
- 
invokeStaticNoArgumentsMethodpublic static java.lang.Object invokeStaticNoArgumentsMethod(java.lang.Class type, java.lang.String methodName)
- 
invokeConstructorOfpublic static java.lang.Object invokeConstructorOf(java.lang.String klass, java.lang.Object arguments) throws java.lang.ClassNotFoundException- Throws:
- java.lang.ClassNotFoundException
 
- 
invokeNoArgumentsConstructorOfpublic static java.lang.Object invokeNoArgumentsConstructorOf(java.lang.Class type)
- 
invokeClosurepublic static java.lang.Object invokeClosure(java.lang.Object closure, java.lang.Object arguments)
- 
asListpublic static java.util.List asList(java.lang.Object value)
- 
toStringpublic static java.lang.String toString(java.lang.Object arguments)
- 
inspectpublic static java.lang.String inspect(java.lang.Object self)
- 
getAttributepublic static java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
- 
setAttributepublic static void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
- 
getPropertypublic static java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
- 
getPropertySafepublic static java.lang.Object getPropertySafe(java.lang.Object object, java.lang.String property)
- 
setPropertypublic static void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
- 
setProperty2public 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.
- 
setGroovyObjectPropertypublic 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.
- 
getGroovyObjectPropertypublic static java.lang.Object getGroovyObjectProperty(GroovyObject object, java.lang.String property)
- 
setPropertySafe2public 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.
- 
getMethodPointerReturns the method pointer for the given object name
- 
unaryMinuspublic static java.lang.Object unaryMinus(java.lang.Object value)
- 
unaryPluspublic static java.lang.Object unaryPlus(java.lang.Object value)
- 
findRegexpublic 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 compare
- right- regular expression to compare the string to
 
- 
matchRegexpublic 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 compare
- right- regular expression to compare the string to
 
- 
createTuple
- 
spreadMap
- 
createListpublic static java.util.List createList(java.lang.Object[] values)
- 
initialCapacitypublic static int initialCapacity(int initialEntryCnt)According to the initial entry count, calculate the initial capacity of hash map, which is power of 2 (SEE https://stackoverflow.com/questions/8352378/why-does-hashmap-require-that-the-initial-capacity-be-a-power-of-two)- Parameters:
- initialEntryCnt- the initial entry count
- Returns:
- the initial capacity
 
- 
createMappublic static java.util.Map createMap(java.lang.Object[] values)
- 
assertFailedpublic static void assertFailed(java.lang.Object expression, java.lang.Object message)
- 
runScriptpublic static java.lang.Object runScript(java.lang.Class scriptClass, java.lang.String[] args)
- 
createScript
- 
newScriptpublic static Script newScript(java.lang.Class<?> scriptClass, Binding context) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException- Throws:
- java.lang.InstantiationException
- java.lang.IllegalAccessException
- java.lang.reflect.InvocationTargetException
 
- 
setPropertiespublic static void setProperties(java.lang.Object object, java.util.Map map)Sets the properties on the given object
- 
writepublic 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
 
- 
appendpublic 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
 
- 
asIteratorpublic static java.util.Iterator<java.lang.Object> asIterator(java.lang.Object o)
- 
formatprotected static java.lang.String format(java.lang.Object arguments, boolean verbose)
- 
formatpublic static java.lang.String format(java.lang.Object arguments, boolean verbose, int maxSize)
- 
formatpublic static java.lang.String format(java.lang.Object arguments, boolean verbose, int maxSize, boolean safe)
- 
escapeBackslashespublic static java.lang.String escapeBackslashes(java.lang.String orig)
- 
toTypeStringpublic 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
 
- 
toTypeStringpublic 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 process
- maxSize- stop after approximately this many characters and append '...', -1 means don't stop
- Returns:
- the string representation of the type
 
- 
toMapStringpublic 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
 
- 
toMapStringpublic 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 process
- maxSize- stop after approximately this many characters and append '...', -1 means don't stop
- Returns:
- the string representation of the map
 
- 
toListStringpublic 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
 
- 
toListStringpublic 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 process
- maxSize- stop after approximately this many characters and append '...'
- Returns:
- the string representation of the collection
 
- 
toListStringpublic 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 process
- maxSize- stop after approximately this many characters and append '...', -1 means don't stop
- safe- 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
 
- 
toArrayStringpublic 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
 
- 
toArrayStringpublic 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 process
- maxSize- 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
 
- 
createRangepublic static java.util.List createRange(java.lang.Object from, java.lang.Object to, boolean inclusive)
- 
bitwiseNegatepublic static java.lang.Object bitwiseNegate(java.lang.Object value)
- 
getMetaRegistry
- 
getMetaClass
- 
getMetaClass
- 
invokeMethodpublic static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Invokes the given method on the object.
- 
invokeSuperMethodpublic static java.lang.Object invokeSuperMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
- 
invokeStaticMethodpublic static java.lang.Object invokeStaticMethod(java.lang.Class type, java.lang.String method, java.lang.Object arguments)
- 
invokeConstructorOfpublic static java.lang.Object invokeConstructorOf(java.lang.Class type, java.lang.Object arguments)
- 
asArraypublic 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
- 
asUnwrappedArraypublic static java.lang.Object[] asUnwrappedArray(java.lang.Object arguments)
 
-