org.codehaus.groovy.runtime
Class ScriptBytecodeAdapter

java.lang.Object
  extended byorg.codehaus.groovy.runtime.ScriptBytecodeAdapter

public class ScriptBytecodeAdapter
extends Object

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

Version:
$Revision: 1.11 $
Author:
James Strachan

Field Summary
static Object[] EMPTY_ARGS
           
 
Constructor Summary
ScriptBytecodeAdapter()
           
 
Method Summary
static boolean asBool(Object object)
           
static int asInt(Object value)
           
static Iterator asIterator(Object collection)
           
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 Object convertToPrimitiveArray(Object a, Class type)
           
static List createList(Object[] values)
           
static Map createMap(Object[] values)
           
static List createRange(Object from, Object to, boolean inclusive)
           
static 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 getAttributeSafe(Object object, String attribute)
           
static Object getAttributeSpreadSafe(Object object, String attribute)
           
static Object getGroovyObjectProperty(GroovyObject object, String property)
           
static MetaClass getMetaClass(Object object)
           
static Closure getMethodPointer(Object object, String methodName)
          Returns the method pointer for the given object name
static Object getProperty(Object object, String property)
           
static Object getPropertySafe(Object object, String property)
           
static Object getPropertySpreadSafe(Object object, String property)
           
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 invokeConstructorAt(Class at, Class 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 invokeMethodSpreadSafe(Object object, String methodName, Object arguments)
           
static Object invokeNoArgumentsConstructorAt(Class at, Class type)
           
static Object invokeNoArgumentsConstructorOf(Class type)
           
static Object invokeNoArgumentsMethod(Object object, String methodName)
           
static Object invokeNoArgumentsMethodSafe(Object object, String methodName)
           
static Object invokeNoArgumentsMethodSpreadSafe(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)
           
static Pattern regexPattern(Object regex)
           
static void setAttribute(Object object, String attribute, Object newValue)
           
static void setAttribute2(Object newValue, Object object, String property)
          This is so we don't have to reorder the stack when we call this method.
static void setAttributeSafe2(Object newValue, Object object, String property)
          This is so we don't have to reorder the stack when we call this method.
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.
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 Object spreadList(Object value)
           
static Object spreadMap(Object value)
           
 
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

ScriptBytecodeAdapter

public ScriptBytecodeAdapter()
Method Detail

invokeMethod

public static Object invokeMethod(Object object,
                                  String methodName,
                                  Object arguments)
                           throws Throwable
Throws:
Throwable

invokeMethodSafe

public static Object invokeMethodSafe(Object object,
                                      String methodName,
                                      Object arguments)
                               throws Throwable
Throws:
Throwable

invokeMethodSpreadSafe

public static Object invokeMethodSpreadSafe(Object object,
                                            String methodName,
                                            Object arguments)
                                     throws Throwable
Throws:
Throwable

invokeStaticMethod

public static Object invokeStaticMethod(String type,
                                        String methodName,
                                        Object arguments)
                                 throws Throwable
Throws:
Throwable

invokeConstructorAt

public static Object invokeConstructorAt(Class at,
                                         Class type,
                                         Object arguments)
                                  throws Throwable
Throws:
Throwable

invokeNoArgumentsConstructorAt

public static Object invokeNoArgumentsConstructorAt(Class at,
                                                    Class type)
                                             throws Throwable
Throws:
Throwable

invokeConstructorOf

public static Object invokeConstructorOf(Class type,
                                         Object arguments)
                                  throws Throwable
Throws:
Throwable

invokeNoArgumentsConstructorOf

public static Object invokeNoArgumentsConstructorOf(Class type)
                                             throws Throwable
Throws:
Throwable

invokeClosure

public static Object invokeClosure(Object closure,
                                   Object arguments)
                            throws Throwable
Throws:
Throwable

invokeSuperMethod

public static Object invokeSuperMethod(Object object,
                                       String methodName,
                                       Object arguments)
                                throws Throwable
Throws:
Throwable

invokeNoArgumentsMethod

public static Object invokeNoArgumentsMethod(Object object,
                                             String methodName)
                                      throws Throwable
Throws:
Throwable

invokeNoArgumentsMethodSafe

public static Object invokeNoArgumentsMethodSafe(Object object,
                                                 String methodName)
                                          throws Throwable
Throws:
Throwable

invokeNoArgumentsMethodSpreadSafe

public static Object invokeNoArgumentsMethodSpreadSafe(Object object,
                                                       String methodName)
                                                throws Throwable
Throws:
Throwable

invokeStaticNoArgumentsMethod

public static Object invokeStaticNoArgumentsMethod(String type,
                                                   String methodName)
                                            throws Throwable
Throws:
Throwable

asInt

public static int asInt(Object value)
                 throws Throwable
Throws:
Throwable

asType

public static Object asType(Object object,
                            Class type)
                     throws Throwable
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
Throws:
Throwable

getAttribute

public static Object getAttribute(Object object,
                                  String attribute)
                           throws Throwable
Throws:
Throwable

getAttributeSafe

public static Object getAttributeSafe(Object object,
                                      String attribute)
                               throws Throwable
Throws:
Throwable

getAttributeSpreadSafe

public static Object getAttributeSpreadSafe(Object object,
                                            String attribute)
                                     throws Throwable
Throws:
Throwable

setAttribute

public static void setAttribute(Object object,
                                String attribute,
                                Object newValue)
                         throws Throwable
Throws:
Throwable

setAttribute2

public static void setAttribute2(Object newValue,
                                 Object object,
                                 String property)
                          throws Throwable
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.

Throws:
Throwable

setAttributeSafe2

public static void setAttributeSafe2(Object newValue,
                                     Object object,
                                     String property)
                              throws Throwable
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.

Throws:
Throwable

getProperty

public static Object getProperty(Object object,
                                 String property)
                          throws Throwable
Throws:
Throwable

getPropertySafe

public static Object getPropertySafe(Object object,
                                     String property)
                              throws Throwable
Throws:
Throwable

getPropertySpreadSafe

public static Object getPropertySpreadSafe(Object object,
                                           String property)
                                    throws Throwable
Throws:
Throwable

setProperty

public static void setProperty(Object object,
                               String property,
                               Object newValue)
                        throws Throwable
Throws:
Throwable

setProperty2

public static void setProperty2(Object newValue,
                                Object object,
                                String property)
                         throws Throwable
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.

Throws:
Throwable

setPropertySafe2

public static void setPropertySafe2(Object newValue,
                                    Object object,
                                    String property)
                             throws Throwable
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.

Throws:
Throwable

setGroovyObjectProperty

public static void setGroovyObjectProperty(Object newValue,
                                           GroovyObject object,
                                           String property)
                                    throws Throwable
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.

Throws:
Throwable

getGroovyObjectProperty

public static Object getGroovyObjectProperty(GroovyObject object,
                                             String property)
                                      throws Throwable
Throws:
Throwable

getMethodPointer

public static Closure getMethodPointer(Object object,
                                       String methodName)
Returns the method pointer for the given object name


asIterator

public static Iterator asIterator(Object collection)
                           throws Throwable
Throws:
Throwable

asBool

public static boolean asBool(Object object)
                      throws Throwable
Throws:
Throwable

notBoolean

public static boolean notBoolean(boolean bool)

notObject

public static boolean notObject(Object object)
                         throws Throwable
Throws:
Throwable

regexPattern

public static Pattern regexPattern(Object regex)
                            throws Throwable
Throws:
Throwable

spreadList

public static Object spreadList(Object value)
                         throws Throwable
Throws:
Throwable

spreadMap

public static Object spreadMap(Object value)
                        throws Throwable
Throws:
Throwable

negate

public static Object negate(Object value)
                     throws Throwable
Throws:
Throwable

bitNegate

public static Object bitNegate(Object value)
                        throws Throwable
Throws:
Throwable

convertPrimitiveArray

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

convertToPrimitiveArray

public static Object convertToPrimitiveArray(Object a,
                                             Class type)
                                      throws Throwable
Throws:
Throwable

compareIdentical

public static boolean compareIdentical(Object left,
                                       Object right)

compareEqual

public static boolean compareEqual(Object left,
                                   Object right)
                            throws Throwable
Throws:
Throwable

compareNotEqual

public static boolean compareNotEqual(Object left,
                                      Object right)
                               throws Throwable
Throws:
Throwable

compareTo

public static Integer compareTo(Object left,
                                Object right)
                         throws Throwable
Throws:
Throwable

findRegex

public static Matcher findRegex(Object left,
                                Object right)
                         throws Throwable
Throws:
Throwable

matchRegex

public static boolean matchRegex(Object left,
                                 Object right)
                          throws Throwable
Throws:
Throwable

compareLessThan

public static boolean compareLessThan(Object left,
                                      Object right)
                               throws Throwable
Throws:
Throwable

compareLessThanEqual

public static boolean compareLessThanEqual(Object left,
                                           Object right)
                                    throws Throwable
Throws:
Throwable

compareGreaterThan

public static boolean compareGreaterThan(Object left,
                                         Object right)
                                  throws Throwable
Throws:
Throwable

compareGreaterThanEqual

public static boolean compareGreaterThanEqual(Object left,
                                              Object right)
                                       throws Throwable
Throws:
Throwable

isCase

public static boolean isCase(Object switchValue,
                             Object caseExpression)
                      throws Throwable
Throws:
Throwable

createTuple

public static Tuple createTuple(Object[] array)
                         throws Throwable
Throws:
Throwable

createList

public static List createList(Object[] values)
                       throws Throwable
Throws:
Throwable

createMap

public static Map createMap(Object[] values)
                     throws Throwable
Throws:
Throwable

createRange

public static List createRange(Object from,
                               Object to,
                               boolean inclusive)
                        throws Throwable
Throws:
Throwable

assertFailed

public static void assertFailed(Object expression,
                                Object message)

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)

integerValue

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

Parameters:
v -
Returns:

byteUnbox

public static byte byteUnbox(Object value)
                      throws Throwable
Throws:
Throwable

charUnbox

public static char charUnbox(Object value)
                      throws Throwable
Throws:
Throwable

shortUnbox

public static short shortUnbox(Object value)
                        throws Throwable
Throws:
Throwable

intUnbox

public static int intUnbox(Object value)
                    throws Throwable
Throws:
Throwable

booleanUnbox

public static boolean booleanUnbox(Object value)
                            throws Throwable
Throws:
Throwable

longUnbox

public static long longUnbox(Object value)
                      throws Throwable
Throws:
Throwable

floatUnbox

public static float floatUnbox(Object value)
                        throws Throwable
Throws:
Throwable

doubleUnbox

public static double doubleUnbox(Object value)
                          throws Throwable
Throws:
Throwable

getMetaClass

public static MetaClass getMetaClass(Object object)


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