Package org.codehaus.groovy.runtime
Class InvokerHelper
- java.lang.Object
- 
- org.codehaus.groovy.runtime.InvokerHelper
 
- 
 public class InvokerHelper extends 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 Object[]EMPTY_ARGSprotected static Object[]EMPTY_ARGUMENTSprotected static Class[]EMPTY_TYPESstatic StringMAIN_METHOD_NAMEstatic MetaClassRegistrymetaRegistry
 - 
Constructor SummaryConstructors Constructor Description InvokerHelper()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappend(Appendable out, Object object)Appends an object to an Appendable using Groovy's default representation for the object.static Object[]asArray(Object arguments)Converts the given object into an array; if its an array then just cast otherwise wrap it in an arraystatic Iterator<Object>asIterator(Object o)static ListasList(Object value)static voidassertFailed(Object expression, Object message)static Object[]asUnwrappedArray(Object arguments)static ObjectbitwiseNegate(Object value)static ListcreateList(Object[] values)static MapcreateMap(Object[] values)static ListcreateRange(Object from, Object to, boolean inclusive)static ScriptcreateScript(Class scriptClass, Binding context)static TuplecreateTuple(Object[] array)static StringescapeBackslashes(String orig)static MatcherfindRegex(Object left, Object right)Find the right hand regex within the left hand string and return a matcher.protected static Stringformat(Object arguments, boolean verbose)static Stringformat(Object arguments, boolean verbose, int maxSize)static Stringformat(Object arguments, boolean verbose, int maxSize, boolean safe)static ObjectgetAttribute(Object object, String attribute)static ObjectgetGroovyObjectProperty(GroovyObject object, String property)static MetaClassgetMetaClass(Class cls)static MetaClassgetMetaClass(Object object)static MetaClassRegistrygetMetaRegistry()static ClosuregetMethodPointer(Object object, String methodName)Returns the method pointer for the given object namestatic ObjectgetProperty(Object object, String property)static ObjectgetPropertySafe(Object object, 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 Stringinspect(Object self)static ObjectinvokeClosure(Object closure, Object arguments)static ObjectinvokeConstructorOf(Class type, Object arguments)static ObjectinvokeConstructorOf(String klass, Object arguments)static ObjectinvokeMethod(Object object, String methodName, Object arguments)Invokes the given method on the object.static ObjectinvokeMethodSafe(Object object, String methodName, Object arguments)static ObjectinvokeNoArgumentsConstructorOf(Class type)static ObjectinvokeStaticMethod(Class type, String method, Object arguments)static ObjectinvokeStaticMethod(String klass, String methodName, Object arguments)static ObjectinvokeStaticNoArgumentsMethod(Class type, String methodName)static ObjectinvokeSuperMethod(Object object, String methodName, Object arguments)static booleanmatchRegex(Object left, Object right)Find the right hand regex within the left hand string and return a matcher.static ScriptnewScript(Class<?> scriptClass, Binding context)static voidremoveClass(Class clazz)static ObjectrunScript(Class scriptClass, String[] args)static voidsetAttribute(Object object, String attribute, Object newValue)static voidsetGroovyObjectProperty(Object newValue, GroovyObject object, String property)This is so we don't have to reorder the stack when we call this method.static voidsetProperties(Object object, Map map)Sets the properties on the given objectstatic voidsetProperty(Object object, String property, Object newValue)static voidsetProperty2(Object newValue, Object object, String property)This is so we don't have to reorder the stack when we call this method.static voidsetPropertySafe2(Object newValue, Object object, String property)This is so we don't have to reorder the stack when we call this method.static SpreadMapspreadMap(Object value)static StringtoArrayString(Object[] arguments)A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static StringtoArrayString(Object[] arguments, int maxSize, boolean safe)A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static StringtoListString(Collection arg)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoListString(Collection arg, int maxSize)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoListString(Collection arg, int maxSize, boolean safe)A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoMapString(Map arg)A helper method to return the string representation of a map with bracket boundaries "[" and "]".static StringtoMapString(Map arg, int maxSize)A helper method to return the string representation of a map with bracket boundaries "[" and "]".static StringtoString(Object arguments)static StringtoTypeString(Object[] arguments)A helper method to format the arguments types as a comma-separated list.static StringtoTypeString(Object[] arguments, int maxSize)A helper method to format the arguments types as a comma-separated list.static ObjectunaryMinus(Object value)static ObjectunaryPlus(Object value)static voidwrite(Writer out, Object object)Writes an object to a Writer using Groovy's default representation for the object.
 
- 
- 
- 
Field Detail- 
EMPTY_ARGSpublic static final Object[] EMPTY_ARGS 
 - 
EMPTY_ARGUMENTSprotected static final Object[] EMPTY_ARGUMENTS 
 - 
EMPTY_TYPESprotected static final Class[] EMPTY_TYPES 
 - 
metaRegistrypublic static final MetaClassRegistry metaRegistry 
 - 
MAIN_METHOD_NAMEpublic static final String MAIN_METHOD_NAME - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
removeClasspublic static void removeClass(Class clazz) 
 - 
invokeMethodSafepublic static Object invokeMethodSafe(Object object, String methodName, Object arguments) 
 - 
invokeStaticMethodpublic static Object invokeStaticMethod(String klass, String methodName, Object arguments) throws ClassNotFoundException - Throws:
- ClassNotFoundException
 
 - 
invokeStaticNoArgumentsMethodpublic static Object invokeStaticNoArgumentsMethod(Class type, String methodName) 
 - 
invokeConstructorOfpublic static Object invokeConstructorOf(String klass, Object arguments) throws ClassNotFoundException - Throws:
- ClassNotFoundException
 
 - 
setProperty2public static void setProperty2(Object newValue, Object object, 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(Object newValue, GroovyObject object, 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 Object getGroovyObjectProperty(GroovyObject object, String property) 
 - 
setPropertySafe2public static void setPropertySafe2(Object newValue, Object object, 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.
 - 
getMethodPointerpublic static Closure getMethodPointer(Object object, String methodName) Returns the method pointer for the given object name
 - 
findRegexpublic static Matcher findRegex(Object left, 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(Object left, 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
 
 - 
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
 
 - 
newScriptpublic static Script newScript(Class<?> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException 
 - 
setPropertiespublic static void setProperties(Object object, Map map) Sets the properties on the given object
 - 
writepublic static void write(Writer out, Object object) throws IOException Writes an object to a Writer using Groovy's default representation for the object.- Throws:
- IOException
 
 - 
appendpublic static void append(Appendable out, Object object) throws IOException Appends an object to an Appendable using Groovy's default representation for the object.- Throws:
- IOException
 
 - 
toTypeStringpublic static String toTypeString(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 String toTypeString(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 String toMapString(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 String toMapString(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 String toListString(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 String toListString(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 String toListString(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 String toArrayString(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 String toArrayString(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
 
 - 
getMetaRegistrypublic static MetaClassRegistry getMetaRegistry() 
 - 
invokeMethodpublic static Object invokeMethod(Object object, String methodName, Object arguments) Invokes the given method on the object.
 - 
invokeSuperMethodpublic static Object invokeSuperMethod(Object object, String methodName, Object arguments) 
 - 
invokeStaticMethodpublic static Object invokeStaticMethod(Class type, String method, Object arguments) 
 - 
asArraypublic static Object[] asArray(Object arguments) Converts the given object into an array; if its an array then just cast otherwise wrap it in an array
 
- 
 
-