org.codehaus.groovy.runtime
Class ScriptBytecodeAdapter

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

public class ScriptBytecodeAdapter
extends java.lang.Object

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

Version:
$Revision: 1.3 $
Author:
James Strachan

Field Summary
static java.lang.Object[] EMPTY_ARGS
           
 
Constructor Summary
ScriptBytecodeAdapter()
           
 
Method Summary
static boolean asBool(java.lang.Object object)
           
static int asInt(java.lang.Object value)
           
static java.util.Iterator asIterator(java.lang.Object collection)
           
static void assertFailed(java.lang.Object expression, java.lang.Object message)
           
static java.lang.Object asType(java.lang.Object object, java.lang.Class type)
          Provides a hook for type coercion of the given object to the required type
static java.lang.Object bitNegate(java.lang.Object value)
           
static boolean booleanUnbox(java.lang.Object value)
           
static java.lang.Object box(boolean value)
           
static java.lang.Object box(byte value)
           
static java.lang.Object box(char value)
           
static java.lang.Object box(double value)
           
static java.lang.Object box(float value)
           
static java.lang.Object box(int value)
           
static java.lang.Object box(long value)
           
static java.lang.Object box(short value)
           
static byte byteUnbox(java.lang.Object value)
           
static char charUnbox(java.lang.Object value)
           
static boolean compareEqual(java.lang.Object left, java.lang.Object right)
           
static boolean compareGreaterThan(java.lang.Object left, java.lang.Object right)
           
static boolean compareGreaterThanEqual(java.lang.Object left, java.lang.Object right)
           
static boolean compareIdentical(java.lang.Object left, java.lang.Object right)
           
static boolean compareLessThan(java.lang.Object left, java.lang.Object right)
           
static boolean compareLessThanEqual(java.lang.Object left, java.lang.Object right)
           
static boolean compareNotEqual(java.lang.Object left, java.lang.Object right)
           
static java.lang.Integer compareTo(java.lang.Object left, java.lang.Object right)
           
static java.lang.Object[] convertPrimitiveArray(java.lang.Object a, java.lang.Class type)
           
static java.lang.Object convertToPrimitiveArray(java.lang.Object a, java.lang.Class type)
           
static java.util.List createList(java.lang.Object[] values)
           
static java.util.Map createMap(java.lang.Object[] values)
           
static java.util.List createRange(java.lang.Object from, java.lang.Object to, boolean inclusive)
           
static Tuple createTuple(java.lang.Object[] array)
           
static double doubleUnbox(java.lang.Object value)
           
static java.util.regex.Matcher findRegex(java.lang.Object left, java.lang.Object right)
           
static float floatUnbox(java.lang.Object value)
           
static java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
           
static java.lang.Object getAttributeSafe(java.lang.Object object, java.lang.String attribute)
           
static java.lang.Object getGroovyObjectProperty(GroovyObject object, java.lang.String property)
           
static MetaClass getMetaClass(java.lang.Object object)
           
static java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
           
static java.lang.Object getPropertySafe(java.lang.Object object, java.lang.String property)
           
static java.lang.Integer integerValue(int v)
          get the Integer object from an int.
static int intUnbox(java.lang.Object value)
           
static java.lang.Object invokeClosure(java.lang.Object closure, java.lang.Object arguments)
           
static java.lang.Object invokeConstructor(java.lang.String type, java.lang.Object arguments)
           
static java.lang.Object invokeConstructorOf(java.lang.Class type, java.lang.Object arguments)
           
static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
           
static java.lang.Object invokeMethodSafe(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
           
static java.lang.Object invokeNoArgumentsConstructorOf(java.lang.Class type)
           
static java.lang.Object invokeNoArgumentsMethod(java.lang.Object object, java.lang.String methodName)
           
static java.lang.Object invokeStaticMethod(java.lang.String type, java.lang.String methodName, java.lang.Object arguments)
           
static java.lang.Object invokeStaticNoArgumentsMethod(java.lang.String type, java.lang.String methodName)
           
static java.lang.Object invokeSuperMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
           
static boolean isCase(java.lang.Object switchValue, java.lang.Object caseExpression)
           
static long longUnbox(java.lang.Object value)
           
static boolean matchRegex(java.lang.Object left, java.lang.Object right)
           
static java.lang.Object negate(java.lang.Object value)
           
static boolean notBoolean(boolean bool)
           
static boolean notObject(java.lang.Object object)
           
static java.util.regex.Pattern regexPattern(java.lang.Object regex)
           
static void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
           
static void setAttribute2(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 void setAttributeSafe2(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 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.
static void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
           
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.
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.
static short shortUnbox(java.lang.Object value)
           
private static java.lang.Object unwrap(GroovyRuntimeException gre)
           
 
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 java.lang.Object[] EMPTY_ARGS
Constructor Detail

ScriptBytecodeAdapter

public ScriptBytecodeAdapter()
Method Detail

unwrap

private static java.lang.Object unwrap(GroovyRuntimeException gre)
                                throws java.lang.Throwable
Throws:
java.lang.Throwable

invokeMethod

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

invokeMethodSafe

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

invokeStaticMethod

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

invokeConstructor

public static java.lang.Object invokeConstructor(java.lang.String type,
                                                 java.lang.Object arguments)
                                          throws java.lang.Throwable
Throws:
java.lang.Throwable

invokeConstructorOf

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

invokeNoArgumentsConstructorOf

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

invokeClosure

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

invokeSuperMethod

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

invokeNoArgumentsMethod

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

invokeStaticNoArgumentsMethod

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

asInt

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

asType

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

getAttribute

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

getAttributeSafe

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

setAttribute

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

setAttribute2

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

setAttributeSafe2

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

getProperty

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

getPropertySafe

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

setProperty

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

setProperty2

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

setPropertySafe2

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

setGroovyObjectProperty

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

getGroovyObjectProperty

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

asIterator

public static java.util.Iterator asIterator(java.lang.Object collection)
                                     throws java.lang.Throwable
Throws:
java.lang.Throwable

asBool

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

notBoolean

public static boolean notBoolean(boolean bool)

notObject

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

regexPattern

public static java.util.regex.Pattern regexPattern(java.lang.Object regex)
                                            throws java.lang.Throwable
Throws:
java.lang.Throwable

negate

public static java.lang.Object negate(java.lang.Object value)
                               throws java.lang.Throwable
Throws:
java.lang.Throwable

bitNegate

public static java.lang.Object bitNegate(java.lang.Object value)
                                  throws java.lang.Throwable
Throws:
java.lang.Throwable

convertPrimitiveArray

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

convertToPrimitiveArray

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

compareIdentical

public static boolean compareIdentical(java.lang.Object left,
                                       java.lang.Object right)

compareEqual

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

compareNotEqual

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

compareTo

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

findRegex

public static java.util.regex.Matcher findRegex(java.lang.Object left,
                                                java.lang.Object right)
                                         throws java.lang.Throwable
Throws:
java.lang.Throwable

matchRegex

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

compareLessThan

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

compareLessThanEqual

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

compareGreaterThan

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

compareGreaterThanEqual

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

isCase

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

createTuple

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

createList

public static java.util.List createList(java.lang.Object[] values)
                                 throws java.lang.Throwable
Throws:
java.lang.Throwable

createMap

public static java.util.Map createMap(java.lang.Object[] values)
                               throws java.lang.Throwable
Throws:
java.lang.Throwable

createRange

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

assertFailed

public static void assertFailed(java.lang.Object expression,
                                java.lang.Object message)

box

public static java.lang.Object box(boolean value)

box

public static java.lang.Object box(byte value)

box

public static java.lang.Object box(char value)

box

public static java.lang.Object box(short value)

box

public static java.lang.Object box(int value)

box

public static java.lang.Object box(long value)

box

public static java.lang.Object box(float value)

box

public static java.lang.Object box(double value)

integerValue

public static java.lang.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(java.lang.Object value)
                      throws java.lang.Throwable
Throws:
java.lang.Throwable

charUnbox

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

shortUnbox

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

intUnbox

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

booleanUnbox

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

longUnbox

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

floatUnbox

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

doubleUnbox

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

getMetaClass

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


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