Top Description Inners Fields Constructors Methods
org.codehaus.groovy.runtime

public Class InvokerHelper

extends Object
Class Inheritance
Imports
groovy.lang.Binding, .Closure, .GString, .GroovyInterceptable, .GroovyObject, .GroovyRuntimeException, .GroovySystem, .MetaClass, .MetaClassRegistry, .MissingMethodException, .MissingPropertyException, .Range, .Script, .SpreadMap, .SpreadMapEvaluatingException, .Tuple, .Writable, org.apache.groovy.io.StringBuilderWriter, org.codehaus.groovy.control.ResolveVisitor, org.codehaus.groovy.reflection.ClassInfo, org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl, .MissingMethodExecutionFailed, org.codehaus.groovy.runtime.powerassert.PowerAssertionError, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, org.codehaus.groovy.runtime.wrappers.PojoWrapper, org.w3c.dom.Element, java.beans.Introspector, java.io.IOException, .InputStream, .InputStreamReader, .Reader, .Writer, java.lang.reflect.Constructor, .InvocationTargetException, .Method, java.math.BigDecimal, .BigInteger, java.util.ArrayList, .Arrays, .Collection, .Collections, .Enumeration, .HashSet, .Iterator, .LinkedHashMap, .List, .Map, .Set, java.util.regex.Matcher, .Pattern

A static helper class to make bytecode generation easier and act as a facade over the Invoker

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final Set<String>
private static final Set<String>
public static final Object[]
protected static final Object[]
protected static final Class<T>[]
private static final int
public static final String
public static final MetaClassRegistry
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
append(Appendable out, Object object)

Appends an object to an Appendable using Groovy's default representation for the object.

public 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

public static Iterator<Object>
public static List<E>
asList(Object value)

public static void
assertFailed(Object expression, Object message)

public static Object[]
public static Object
public static List<E>
createList(Object[] values)

public static Map<K, V>
createMap(Object[] values)

public static List<E>
createRange(Object from, Object to, boolean inclusive)

public static Script
createScript(final Class<T> scriptClass, final Binding context)

public static Tuple<E>
public static String
public static Matcher
findRegex(Object
string to compare
left
,
Object
regular expression to compare the string to
right
)

Find the right hand regex within the left hand string and return a matcher.

protected static String
format(Object arguments, boolean verbose)

public static String
format(Object arguments, boolean verbose, int maxSize)

public static String
format(Object arguments, boolean verbose, int maxSize, boolean safe)

private static String
formatCollection(Collection<E> collection, boolean verbose, int maxSize, boolean safe)

private static String
formatMap(Map<K, V> map, boolean verbose, int maxSize, boolean safe)

public static Object
getAttribute(Object object, String attribute)

public static Object
public static MetaClass
public static MetaClass
public static MetaClassRegistry
public static Closure<V>
getMethodPointer(Object object, String methodName)

Returns the method pointer for the given object name

public static Object
getProperty(Object object, String property)

public static Object
getPropertySafe(Object object, String property)

private static String
public static int

Returns:

the initial capacity
initialCapacity
(int
the initial entry count
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)

public static String
public static Object
invokeClosure(Object closure, Object arguments)

public static Object
invokeConstructorOf(String klass, Object arguments)

public static Object
invokeConstructorOf(Class<T> type, Object arguments)

public static Object
invokeMethod(Object object, String methodName, Object arguments)

Invokes the given method on the object.

public static Object
invokeMethodSafe(Object object, String methodName, Object arguments)

public static Object
pack-priv static Object
invokePogoMethod(Object object, String methodName, Object arguments)

pack-priv static Object
invokePojoMethod(Object object, String methodName, Object arguments)

public static Object
invokeStaticMethod(String klass, String methodName, Object arguments)

public static Object
invokeStaticMethod(Class<T> type, String method, Object arguments)

public static Object
public static Object
invokeSuperMethod(Object object, String methodName, Object arguments)

public static boolean
matchRegex(Object
string to compare
left
,
Object
regular expression to compare the string to
right
)

Find the right hand regex within the left hand string and return a matcher.

public static Script
newScript(Class<?> scriptClass, Binding context)

public static void
removeClass(Class<T> clazz)

public static Object
runScript(Class<T> scriptClass, String[] args)

public static void
setAttribute(Object object, String attribute, Object newValue)

public 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.

public static void
setProperties(Object object, Map<K, V> map)

Sets the properties on the given object

public static void
setProperty(Object object, String property, Object newValue)

public 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.

private static void
setPropertySafe(Object object, MetaClass mc, String key, Object value)

public 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.

private static int
sizeLeft(int maxSize, StringBuilder buffer)

public static SpreadMap
public static String

Returns:

the string representation of the array
toArrayString
(Object[]
the array to process
arguments
)

A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".

private static String
toArrayString(Object[] array, boolean verbose, int maxSize, boolean safe)

public static String

Returns:

the string representation of the array
toArrayString
(Object[]
the array to process
arguments
,
int
stop after approximately this many characters and append '...'
maxSize
,
boolean
whether to use a default object representation for any item in the array if an exception occurs when generating its toString
safe
)

A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".

public static String

Returns:

the string representation of the collection
toListString
(Collection<E>
the collection to process
arg
)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

public static String

Returns:

the string representation of the collection
toListString
(Collection<E>
the collection to process
arg
,
int
stop after approximately this many characters and append '...'
maxSize
)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

public static String

Returns:

the string representation of the collection
toListString
(Collection<E>
the collection to process
arg
,
int
stop after approximately this many characters and append '...', -1 means don't stop
maxSize
,
boolean
whether to use a default object representation for any item in the collection if an exception occurs when generating its toString
safe
)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

public static String

Returns:

the string representation of the map
toMapString
(Map<K, V>
the map to process
arg
)

A helper method to return the string representation of a map with bracket boundaries "[" and "]".

public static String

Returns:

the string representation of the map
toMapString
(Map<K, V>
the map to process
arg
,
int
stop after approximately this many characters and append '...', -1 means don't stop
maxSize
)

A helper method to return the string representation of a map with bracket boundaries "[" and "]".

public static String
toString(Object arguments)

public static String

Returns:

the string representation of the type
toTypeString
(Object[]
the type to process
arguments
)

A helper method to format the arguments types as a comma-separated list.

public static String

Returns:

the string representation of the type
toTypeString
(Object[]
the type to process
arguments
,
int
stop after approximately this many characters and append '...', -1 means don't stop
maxSize
)

A helper method to format the arguments types as a comma-separated list.

private static String

Returns:

the type name (slightly pretty format taking into account default imports)
typeName
(Object
the object to find the type for
argument
)

Gets the type name

public static Object
public static Object
public static void
write(Writer out, Object object)

Writes an object to a Writer using Groovy's default representation for the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_IMPORT_CLASSESback to summary
private static final Set<String> DEFAULT_IMPORT_CLASSES
DEFAULT_IMPORT_PKGSback to summary
private static final Set<String> DEFAULT_IMPORT_PKGS
EMPTY_ARGSback to summary
public static final Object[] EMPTY_ARGS
EMPTY_ARGUMENTSback to summary
protected static final Object[] EMPTY_ARGUMENTS
EMPTY_TYPESback to summary
protected static final Class<T>[] EMPTY_TYPES
ITEM_ALLOCATE_SIZEback to summary
private static final int ITEM_ALLOCATE_SIZE
MAIN_METHOD_NAMEback to summary
public static final String MAIN_METHOD_NAME
metaRegistryback to summary
public static final MetaClassRegistry metaRegistry
SERIALIZE_METHOD_NAMEback to summary
private static final String SERIALIZE_METHOD_NAME
XMLUTIL_CLASS_FULL_NAMEback to summary
private static final String XMLUTIL_CLASS_FULL_NAME

Constructor Detail

InvokerHelperback to summary
public InvokerHelper()

Method Detail

appendback to summary
public static void append(Appendable out, Object object) throws IOException

Appends an object to an Appendable using Groovy's default representation for the object.

asArrayback to summary
public 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

asIteratorback to summary
public static Iterator<Object> asIterator(Object o)
Annotations
@SuppressWarnings:unchecked
asListback to summary
public static List<E> asList(Object value)
assertFailedback to summary
public static void assertFailed(Object expression, Object message)
asUnwrappedArrayback to summary
public static Object[] asUnwrappedArray(Object arguments)
bitwiseNegateback to summary
public static Object bitwiseNegate(Object value)
createListback to summary
public static List<E> createList(Object[] values)
createMapback to summary
public static Map<K, V> createMap(Object[] values)
createRangeback to summary
public static List<E> createRange(Object from, Object to, boolean inclusive)
createScriptback to summary
public static Script createScript(final Class<T> scriptClass, final Binding context)
Annotations
@SuppressWarnings:unchecked
createTupleback to summary
public static Tuple<E> createTuple(Object[] array)
escapeBackslashesback to summary
public static String escapeBackslashes(String orig)
findRegexback to summary
public static Matcher findRegex(Object left, Object right)

Find the right hand regex within the left hand string and return a matcher.

Parameters
left:Object

string to compare

right:Object

regular expression to compare the string to

formatback to summary
protected static String format(Object arguments, boolean verbose)
formatback to summary
public static String format(Object arguments, boolean verbose, int maxSize)
formatback to summary
public static String format(Object arguments, boolean verbose, int maxSize, boolean safe)
formatCollectionback to summary
private static String formatCollection(Collection<E> collection, boolean verbose, int maxSize, boolean safe)
formatMapback to summary
private static String formatMap(Map<K, V> map, boolean verbose, int maxSize, boolean safe)
getAttributeback to summary
public static Object getAttribute(Object object, String attribute)
getGroovyObjectPropertyback to summary
public static Object getGroovyObjectProperty(GroovyObject object, String property)
getMetaClassback to summary
public static MetaClass getMetaClass(Object object)
getMetaClassback to summary
public static MetaClass getMetaClass(Class<T> cls)
getMetaRegistryback to summary
public static MetaClassRegistry getMetaRegistry()
getMethodPointerback to summary
public static Closure<V> getMethodPointer(Object object, String methodName)

Returns the method pointer for the given object name

getPropertyback to summary
public static Object getProperty(Object object, String property)
getPropertySafeback to summary
public static Object getPropertySafe(Object object, String property)
handleFormattingExceptionback to summary
private static String handleFormattingException(Object item, Exception ex)
initialCapacityback to summary
public 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:int

the initial entry count

Returns:int

the initial capacity

inspectback to summary
public static String inspect(Object self)
invokeClosureback to summary
public static Object invokeClosure(Object closure, Object arguments)
invokeConstructorOfback to summary
public static Object invokeConstructorOf(String klass, Object arguments) throws ClassNotFoundException
invokeConstructorOfback to summary
public static Object invokeConstructorOf(Class<T> type, Object arguments)
invokeMethodback to summary
public static Object invokeMethod(Object object, String methodName, Object arguments)

Invokes the given method on the object.

invokeMethodSafeback to summary
public static Object invokeMethodSafe(Object object, String methodName, Object arguments)
invokeNoArgumentsConstructorOfback to summary
public static Object invokeNoArgumentsConstructorOf(Class<T> type)
invokePogoMethodback to summary
pack-priv static Object invokePogoMethod(Object object, String methodName, Object arguments)
invokePojoMethodback to summary
pack-priv static Object invokePojoMethod(Object object, String methodName, Object arguments)
invokeStaticMethodback to summary
public static Object invokeStaticMethod(String klass, String methodName, Object arguments) throws ClassNotFoundException
invokeStaticMethodback to summary
public static Object invokeStaticMethod(Class<T> type, String method, Object arguments)
invokeStaticNoArgumentsMethodback to summary
public static Object invokeStaticNoArgumentsMethod(Class<T> type, String methodName)
invokeSuperMethodback to summary
public static Object invokeSuperMethod(Object object, String methodName, Object arguments)
matchRegexback to summary
public static boolean matchRegex(Object left, Object right)

Find the right hand regex within the left hand string and return a matcher.

Parameters
left:Object

string to compare

right:Object

regular expression to compare the string to

newScriptback to summary
public static Script newScript(Class<?> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException
removeClassback to summary
public static void removeClass(Class<T> clazz)
runScriptback to summary
public static Object runScript(Class<T> scriptClass, String[] args)
setAttributeback to summary
public static void setAttribute(Object object, String attribute, Object newValue)
setGroovyObjectPropertyback to summary
public 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.

setPropertiesback to summary
public static void setProperties(Object object, Map<K, V> map)

Sets the properties on the given object

setPropertyback to summary
public static void setProperty(Object object, String property, Object newValue)
setProperty2back to summary
public 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.

setPropertySafeback to summary
private static void setPropertySafe(Object object, MetaClass mc, String key, Object value)
setPropertySafe2back to summary
public 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.

sizeLeftback to summary
private static int sizeLeft(int maxSize, StringBuilder buffer)
spreadMapback to summary
public static SpreadMap spreadMap(Object value)
toArrayStringback to summary
public static String toArrayString(Object[] arguments)

A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".

Parameters
arguments:Object[]

the array to process

Returns:String

the string representation of the array

toArrayStringback to summary
private static String toArrayString(Object[] array, boolean verbose, int maxSize, boolean safe)
toArrayStringback to summary
public 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:Object[]

the array to process

maxSize:int

stop after approximately this many characters and append '...'

safe:boolean

whether to use a default object representation for any item in the array if an exception occurs when generating its toString

Returns:String

the string representation of the array

toListStringback to summary
public static String toListString(Collection<E> arg)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

Parameters
arg:Collection<E>

the collection to process

Returns:String

the string representation of the collection

toListStringback to summary
public static String toListString(Collection<E> arg, int maxSize)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

Parameters
arg:Collection<E>

the collection to process

maxSize:int

stop after approximately this many characters and append '...'

Returns:String

the string representation of the collection

toListStringback to summary
public static String toListString(Collection<E> arg, int maxSize, boolean safe)

A helper method to return the string representation of a list with bracket boundaries "[" and "]".

Parameters
arg:Collection<E>

the collection to process

maxSize:int

stop after approximately this many characters and append '...', -1 means don't stop

safe:boolean

whether to use a default object representation for any item in the collection if an exception occurs when generating its toString

Returns:String

the string representation of the collection

toMapStringback to summary
public static String toMapString(Map<K, V> arg)

A helper method to return the string representation of a map with bracket boundaries "[" and "]".

Parameters
arg:Map<K, V>

the map to process

Returns:String

the string representation of the map

toMapStringback to summary
public static String toMapString(Map<K, V> arg, int maxSize)

A helper method to return the string representation of a map with bracket boundaries "[" and "]".

Parameters
arg:Map<K, V>

the map to process

maxSize:int

stop after approximately this many characters and append '...', -1 means don't stop

Returns:String

the string representation of the map

toStringback to summary
public static String toString(Object arguments)
toTypeStringback to summary
public static String toTypeString(Object[] arguments)

A helper method to format the arguments types as a comma-separated list.

Parameters
arguments:Object[]

the type to process

Returns:String

the string representation of the type

toTypeStringback to summary
public static String toTypeString(Object[] arguments, int maxSize)

A helper method to format the arguments types as a comma-separated list.

Parameters
arguments:Object[]

the type to process

maxSize:int

stop after approximately this many characters and append '...', -1 means don't stop

Returns:String

the string representation of the type

typeNameback to summary
private static String typeName(Object argument)

Gets the type name

Parameters
argument:Object

the object to find the type for

Returns:String

the type name (slightly pretty format taking into account default imports)

unaryMinusback to summary
public static Object unaryMinus(Object value)
unaryPlusback to summary
public static Object unaryPlus(Object value)
writeback to summary
public static void write(Writer out, Object object) throws IOException

Writes an object to a Writer using Groovy's default representation for the object.

org.codehaus.groovy.runtime back to summary

pack-priv Class InvokerHelper.NullScript

extends Script
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Object
run()

Implements abstract groovy.lang.Script.run.

The main instance method of a script which has variables in scope as defined by the current Binding instance.
Inherited from groovy.lang.Script:
evaluateevaluategetBindinggetPropertyinvokeMethodprintprintfprintfprintlnprintlnrunsetBindingsetProperty

Constructor Detail

NullScriptback to summary
public NullScript(Binding context)
NullScriptback to summary
public NullScript()

Method Detail

runback to summary
public Object run()

Implements abstract groovy.lang.Script.run.

Doc from groovy.lang.Script.run.

The main instance method of a script which has variables in scope as defined by the current Binding instance.