org.codehaus.groovy.runtime
Class InvokerHelper

java.lang.Object
  extended byorg.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

Version:
$Revision: 1.62 $
Author:
James Strachan

Field Summary
static Object[] EMPTY_ARGS
           
 
Constructor Summary
InvokerHelper()
           
 
Method Summary
static boolean asBool(Object object)
           
static Collection asCollection(Object collection)
           
static int asInt(Object value)
           
static Iterator asIterator(Object collection)
           
static List asList(Object args)
           
static void assertFailed(Object expression, Object message)
           
static Object asType(Object object, Class type)
          Provides a hook for type coercion of the given object to the required type
static Object bitNegate(Object value)
           
static boolean booleanUnbox(Object value)
           
static Object box(boolean value)
           
static Object box(byte value)
           
static Object box(char value)
           
static Object box(double value)
           
static Object box(float value)
           
static Object box(int value)
           
static Object box(long value)
           
static Object box(short value)
           
static byte byteUnbox(Object value)
           
static char charUnbox(Object value)
           
static boolean compareEqual(Object left, Object right)
           
static boolean compareGreaterThan(Object left, Object right)
           
static boolean compareGreaterThanEqual(Object left, Object right)
           
static boolean compareIdentical(Object left, Object right)
           
static boolean compareLessThan(Object left, Object right)
           
static boolean compareLessThanEqual(Object left, Object right)
           
static boolean compareNotEqual(Object left, Object right)
           
static Integer compareTo(Object left, Object right)
           
static Object[] convertPrimitiveArray(Object a, Class type)
           
static boolean[] convertToBooleanArray(Object a)
           
static byte[] convertToByteArray(Object a)
           
static char[] convertToCharArray(Object a)
           
static double[] convertToDoubleArray(Object a)
           
static float[] convertToFloatArray(Object a)
           
static int[] convertToIntArray(Object a)
           
static long[] convertToLongArray(Object a)
           
static Object convertToPrimitiveArray(Object a, Class type)
           
static short[] convertToShortArray(Object a)
           
static List createList(Object[] values)
           
static Map createMap(Object[] values)
           
static List createRange(Object from, Object to, boolean inclusive)
           
static groovy.lang.Script createScript(Class scriptClass, groovy.lang.Binding context)
           
static groovy.lang.Tuple createTuple(Object[] array)
           
static double doubleUnbox(Object value)
           
static Matcher findRegex(Object left, Object right)
           
static float floatUnbox(Object value)
           
static Object getAttribute(Object object, String attribute)
           
static Object getGroovyObjectProperty(groovy.lang.GroovyObject object, String property)
           
static Invoker getInstance()
           
static groovy.lang.MetaClass getMetaClass(Object object)
           
static Object getProperty(Object object, String property)
           
static Object getPropertySafe(Object object, String property)
           
static String getVersion()
           
static String inspect(Object self)
           
static Integer integerValue(int v)
          get the Integer object from an int.
static int intUnbox(Object value)
           
static Object invokeClosure(Object closure, Object arguments)
           
static Object invokeConstructor(String type, Object arguments)
           
static Object invokeConstructorOf(Class type, Object arguments)
           
static Object invokeMethod(Object object, String methodName, Object arguments)
           
static Object invokeMethodSafe(Object object, String methodName, Object arguments)
           
static Object invokeNoArgumentsConstructorOf(Class type)
           
static Object invokeNoArgumentsMethod(Object object, String methodName)
           
static Object invokeStaticMethod(String type, String methodName, Object arguments)
           
static Object invokeStaticNoArgumentsMethod(String type, String methodName)
           
static Object invokeSuperMethod(Object object, String methodName, Object arguments)
           
static boolean isCase(Object switchValue, Object caseExpression)
           
static long longUnbox(Object value)
           
static boolean matchRegex(Object left, Object right)
           
static Object negate(Object value)
           
static boolean notBoolean(boolean bool)
           
static boolean notObject(Object object)
           
protected static List primitiveArrayToList(Object array)
          Allows conversion of arrays into a mutable List
static Pattern regexPattern(Object regex)
           
static void removeClass(Class clazz)
           
static Object runScript(Class scriptClass, String[] args)
           
static void setAttribute(Object object, String attribute, Object newValue)
           
static void setGroovyObjectProperty(Object newValue, groovy.lang.GroovyObject object, String property)
          This is so we don't have to reorder the stack when we call this method.
static void setProperties(Object object, Map map)
          Sets the properties on the given object
static void setProperty(Object object, String property, Object newValue)
           
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.
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.
static short shortUnbox(Object value)
           
static String toString(Object arguments)
           
static String toTypeString(Object[] arguments)
           
static void write(Writer out, Object object)
          Writes the given object to the given stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARGS

public static final Object[] EMPTY_ARGS
Constructor Detail

InvokerHelper

public InvokerHelper()
Method Detail

getMetaClass

public static groovy.lang.MetaClass getMetaClass(Object object)

removeClass

public static void removeClass(Class clazz)

getInstance

public static Invoker getInstance()

invokeNoArgumentsMethod

public static Object invokeNoArgumentsMethod(Object object,
                                             String methodName)

invokeMethod

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

invokeSuperMethod

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

invokeMethodSafe

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

invokeStaticMethod

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

invokeStaticNoArgumentsMethod

public static Object invokeStaticNoArgumentsMethod(String type,
                                                   String methodName)

invokeConstructor

public static Object invokeConstructor(String type,
                                       Object arguments)

invokeConstructorOf

public static Object invokeConstructorOf(Class type,
                                         Object arguments)

invokeNoArgumentsConstructorOf

public static Object invokeNoArgumentsConstructorOf(Class type)

invokeClosure

public static Object invokeClosure(Object closure,
                                   Object arguments)

asIterator

public static Iterator asIterator(Object collection)

asCollection

public static Collection asCollection(Object collection)

asList

public static List asList(Object args)

toString

public static String toString(Object arguments)

toTypeString

public static String toTypeString(Object[] arguments)

inspect

public static String inspect(Object self)

getAttribute

public static Object getAttribute(Object object,
                                  String attribute)

setAttribute

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

getProperty

public static Object getProperty(Object object,
                                 String property)

getPropertySafe

public static Object getPropertySafe(Object object,
                                     String property)

setProperty

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

setProperty2

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.


setGroovyObjectProperty

public static void setGroovyObjectProperty(Object newValue,
                                           groovy.lang.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.


getGroovyObjectProperty

public static Object getGroovyObjectProperty(groovy.lang.GroovyObject object,
                                             String property)

setPropertySafe2

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.


asType

public static Object asType(Object object,
                            Class type)
Provides a hook for type coercion of the given object to the required type

Parameters:
type - of object to convert the given object to
object - the object to be converted
Returns:
the original object or a new converted value

asBool

public static boolean asBool(Object object)

notObject

public static boolean notObject(Object object)

notBoolean

public static boolean notBoolean(boolean bool)

negate

public static Object negate(Object value)

bitNegate

public static Object bitNegate(Object value)

isCase

public static boolean isCase(Object switchValue,
                             Object caseExpression)

compareIdentical

public static boolean compareIdentical(Object left,
                                       Object right)

compareEqual

public static boolean compareEqual(Object left,
                                   Object right)

findRegex

public static Matcher findRegex(Object left,
                                Object right)

matchRegex

public static boolean matchRegex(Object left,
                                 Object right)

regexPattern

public static Pattern regexPattern(Object regex)

compareNotEqual

public static boolean compareNotEqual(Object left,
                                      Object right)

compareLessThan

public static boolean compareLessThan(Object left,
                                      Object right)

compareLessThanEqual

public static boolean compareLessThanEqual(Object left,
                                           Object right)

compareGreaterThan

public static boolean compareGreaterThan(Object left,
                                         Object right)

compareGreaterThanEqual

public static boolean compareGreaterThanEqual(Object left,
                                              Object right)

compareTo

public static Integer compareTo(Object left,
                                Object right)

createTuple

public static groovy.lang.Tuple createTuple(Object[] array)

createList

public static List createList(Object[] values)

createMap

public static Map createMap(Object[] values)

createRange

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

asInt

public static int asInt(Object value)

assertFailed

public static void assertFailed(Object expression,
                                Object message)

runScript

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

createScript

public static groovy.lang.Script createScript(Class scriptClass,
                                              groovy.lang.Binding context)

setProperties

public static void setProperties(Object object,
                                 Map map)
Sets the properties on the given object

Parameters:
object -
map -

getVersion

public static String getVersion()

primitiveArrayToList

protected static List primitiveArrayToList(Object array)
Allows conversion of arrays into a mutable List

Returns:
the array as a List

write

public static void write(Writer out,
                         Object object)
                  throws IOException
Writes the given object to the given stream

Throws:
IOException

box

public static Object box(boolean value)

box

public static Object box(byte value)

box

public static Object box(char value)

box

public static Object box(short value)

box

public static Object box(int value)

box

public static Object box(long value)

box

public static Object box(float value)

box

public static Object box(double value)

byteUnbox

public static byte byteUnbox(Object value)

charUnbox

public static char charUnbox(Object value)

shortUnbox

public static short shortUnbox(Object value)

intUnbox

public static int intUnbox(Object value)

booleanUnbox

public static boolean booleanUnbox(Object value)

longUnbox

public static long longUnbox(Object value)

floatUnbox

public static float floatUnbox(Object value)

doubleUnbox

public static double doubleUnbox(Object value)

convertPrimitiveArray

public static Object[] convertPrimitiveArray(Object a,
                                             Class type)
Parameters:
a - array of primitives
type - component type of the array
Returns:

convertToIntArray

public static int[] convertToIntArray(Object a)

convertToBooleanArray

public static boolean[] convertToBooleanArray(Object a)

convertToByteArray

public static byte[] convertToByteArray(Object a)

convertToShortArray

public static short[] convertToShortArray(Object a)

convertToCharArray

public static char[] convertToCharArray(Object a)

convertToLongArray

public static long[] convertToLongArray(Object a)

convertToFloatArray

public static float[] convertToFloatArray(Object a)

convertToDoubleArray

public static double[] convertToDoubleArray(Object a)

convertToPrimitiveArray

public static Object convertToPrimitiveArray(Object a,
                                             Class type)

integerValue

public static Integer integerValue(int v)
get the Integer object from an int. Cached version is used for small ints.

Parameters:
v -
Returns:


Copyright © 2003-2005 The Codehaus. All Rights Reserved.