org.codehaus.groovy.runtime
Class MetaClassHelper

java.lang.Object
  extended by org.codehaus.groovy.runtime.MetaClassHelper

public class MetaClassHelper
extends java.lang.Object

Author:
John Wilson, Jochen Theodorou

Field Summary
static java.lang.Object[] ARRAY_WITH_NULL
           
static java.lang.Object[] EMPTY_ARRAY
           
static java.lang.Class[] EMPTY_TYPE_ARRAY
           
protected static java.util.logging.Logger LOG
           
private static int MAX_ARG_LEN
           
private static int[][] PRIMITIVE_DISTANCE_TABLE
           
private static java.lang.Class[] PRIMITIVES
           
private static int VARGS_SHIFT
           
 
Constructor Summary
MetaClassHelper()
           
 
Method Summary
static boolean accessibleToConstructor(java.lang.Class at, java.lang.reflect.Constructor constructor)
           
static java.lang.Object asPrimitiveArray(java.util.List list, java.lang.Class parameterType)
           
static java.lang.Object[] asWrapperArray(java.lang.Object parameters, java.lang.Class componentType)
           
static long calculateParameterDistance(java.lang.Class[] arguments, ParameterTypes pt)
           
private static long calculateParameterDistance(java.lang.Class argument, CachedClass parameter)
           
private static int calculateSimplifiedClassDistanceToObject(java.lang.Class clazz)
           
static java.lang.String capitalize(java.lang.String property)
           
private static java.lang.Boolean checkCompatiblePackages(java.lang.Class at, java.lang.reflect.Constructor constructor)
           
static java.lang.Object chooseEmptyMethodParams(FastArray methods)
           
static java.lang.Object chooseMostGeneralMethodWith1NullParam(FastArray methods)
           
static boolean containsMatchingMethod(java.util.List list, MetaMethod method)
           
static java.lang.Class[] convertToTypeArray(java.lang.Object[] args)
          param instance array to the type array
private static GroovyRuntimeException createExceptionText(java.lang.String init, java.lang.reflect.Constructor constructor, java.lang.Object[] argumentArray, java.lang.Throwable e, boolean setReason)
           
static GroovyRuntimeException createExceptionText(java.lang.String init, MetaMethod method, java.lang.Object object, java.lang.Object[] args, java.lang.Throwable reason, boolean setReason)
           
static java.lang.Object doConstructorInvoke(CachedConstructor constructor, java.lang.Object[] argumentArray)
           
static java.lang.Object doMethodInvoke(java.lang.Object object, MetaMethod method, java.lang.Object[] argumentArray)
           
protected static java.lang.String getClassName(java.lang.Object object)
           
private static int getMaximumInterfaceDistance(java.lang.Class c, java.lang.Class interfaceClass)
           
static Closure getMethodPointer(java.lang.Object object, java.lang.String methodName)
          Returns a callable object for the given method name on the object.
static ParameterTypes getParameterTypes(java.lang.Object methodOrConstructor)
           
private static int getPrimitiveDistance(java.lang.Class from, java.lang.Class to)
           
private static int getPrimitiveIndex(java.lang.Class c)
           
static boolean isAssignableFrom(java.lang.Class classToTransformTo, java.lang.Class classToTransformFrom)
           
static boolean isGenericSetMethod(MetaMethod method)
           
protected static boolean isSuperclass(java.lang.Class claszz, java.lang.Class superclass)
           
static boolean isValidMethod(java.lang.Object method, java.lang.Class[] arguments)
           
static void logMethodCall(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
           
static java.lang.Object makeArray(java.lang.Object obj, java.lang.Class secondary, int length)
           
static java.lang.Object makeCommonArray(java.lang.Object[] arguments, int offset, java.lang.Class fallback)
           
protected static java.lang.String normalizedValue(java.lang.Object argument)
           
static boolean parametersAreCompatible(java.lang.Class[] arguments, java.lang.Class[] parameters)
           
protected static java.lang.String shortName(java.lang.Object object)
           
static java.lang.Class[] wrap(java.lang.Class[] classes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final java.lang.Object[] EMPTY_ARRAY

EMPTY_TYPE_ARRAY

public static final java.lang.Class[] EMPTY_TYPE_ARRAY

ARRAY_WITH_NULL

public static final java.lang.Object[] ARRAY_WITH_NULL

LOG

protected static final java.util.logging.Logger LOG

MAX_ARG_LEN

private static final int MAX_ARG_LEN
See Also:
Constant Field Values

VARGS_SHIFT

private static final int VARGS_SHIFT
See Also:
Constant Field Values

PRIMITIVES

private static final java.lang.Class[] PRIMITIVES

PRIMITIVE_DISTANCE_TABLE

private static final int[][] PRIMITIVE_DISTANCE_TABLE
Constructor Detail

MetaClassHelper

public MetaClassHelper()
Method Detail

accessibleToConstructor

public static boolean accessibleToConstructor(java.lang.Class at,
                                              java.lang.reflect.Constructor constructor)

checkCompatiblePackages

private static java.lang.Boolean checkCompatiblePackages(java.lang.Class at,
                                                         java.lang.reflect.Constructor constructor)

asWrapperArray

public static java.lang.Object[] asWrapperArray(java.lang.Object parameters,
                                                java.lang.Class componentType)

asPrimitiveArray

public static java.lang.Object asPrimitiveArray(java.util.List list,
                                                java.lang.Class parameterType)
Parameters:
list - the original list
parameterType - the resulting array type
Returns:
the constructed array

getPrimitiveIndex

private static int getPrimitiveIndex(java.lang.Class c)

getPrimitiveDistance

private static int getPrimitiveDistance(java.lang.Class from,
                                        java.lang.Class to)

getMaximumInterfaceDistance

private static int getMaximumInterfaceDistance(java.lang.Class c,
                                               java.lang.Class interfaceClass)

calculateParameterDistance

private static long calculateParameterDistance(java.lang.Class argument,
                                               CachedClass parameter)

calculateParameterDistance

public static long calculateParameterDistance(java.lang.Class[] arguments,
                                              ParameterTypes pt)

capitalize

public static java.lang.String capitalize(java.lang.String property)

chooseEmptyMethodParams

public static java.lang.Object chooseEmptyMethodParams(FastArray methods)
Parameters:
methods - the methods to choose from
Returns:
the method with 1 parameter which takes the most general type of object (e.g. Object)

chooseMostGeneralMethodWith1NullParam

public static java.lang.Object chooseMostGeneralMethodWith1NullParam(FastArray methods)
Parameters:
methods - the methods to choose from
Returns:
the method with 1 parameter which takes the most general type of object (e.g. Object) ignoring primitve types

calculateSimplifiedClassDistanceToObject

private static int calculateSimplifiedClassDistanceToObject(java.lang.Class clazz)

containsMatchingMethod

public static boolean containsMatchingMethod(java.util.List list,
                                             MetaMethod method)
Parameters:
list - a list of MetaMethods
method - the MetaMethod of interest
Returns:
true if a method of the same matching prototype was found in the list

convertToTypeArray

public static java.lang.Class[] convertToTypeArray(java.lang.Object[] args)
param instance array to the type array

Parameters:
args - the arguments
Returns:
the types of the arguments

doConstructorInvoke

public static java.lang.Object doConstructorInvoke(CachedConstructor constructor,
                                                   java.lang.Object[] argumentArray)

createExceptionText

private static GroovyRuntimeException createExceptionText(java.lang.String init,
                                                          java.lang.reflect.Constructor constructor,
                                                          java.lang.Object[] argumentArray,
                                                          java.lang.Throwable e,
                                                          boolean setReason)

doMethodInvoke

public static java.lang.Object doMethodInvoke(java.lang.Object object,
                                              MetaMethod method,
                                              java.lang.Object[] argumentArray)

makeCommonArray

public static java.lang.Object makeCommonArray(java.lang.Object[] arguments,
                                               int offset,
                                               java.lang.Class fallback)

makeArray

public static java.lang.Object makeArray(java.lang.Object obj,
                                         java.lang.Class secondary,
                                         int length)

createExceptionText

public static GroovyRuntimeException createExceptionText(java.lang.String init,
                                                         MetaMethod method,
                                                         java.lang.Object object,
                                                         java.lang.Object[] args,
                                                         java.lang.Throwable reason,
                                                         boolean setReason)

getClassName

protected static java.lang.String getClassName(java.lang.Object object)

getMethodPointer

public static Closure getMethodPointer(java.lang.Object object,
                                       java.lang.String methodName)
Returns a callable object for the given method name on the object. The object acts like a Closure in that it can be called, like a closure and passed around - though really its a method pointer, not a closure per se.

Parameters:
object - the object containing the method
methodName - the method of interest
Returns:
the resulting closure-like method pointer

getParameterTypes

public static ParameterTypes getParameterTypes(java.lang.Object methodOrConstructor)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.Class classToTransformTo,
                                       java.lang.Class classToTransformFrom)

isGenericSetMethod

public static boolean isGenericSetMethod(MetaMethod method)

isSuperclass

protected static boolean isSuperclass(java.lang.Class claszz,
                                      java.lang.Class superclass)

parametersAreCompatible

public static boolean parametersAreCompatible(java.lang.Class[] arguments,
                                              java.lang.Class[] parameters)

isValidMethod

public static boolean isValidMethod(java.lang.Object method,
                                    java.lang.Class[] arguments)

logMethodCall

public static void logMethodCall(java.lang.Object object,
                                 java.lang.String methodName,
                                 java.lang.Object[] arguments)

normalizedValue

protected static java.lang.String normalizedValue(java.lang.Object argument)

shortName

protected static java.lang.String shortName(java.lang.Object object)

wrap

public static java.lang.Class[] wrap(java.lang.Class[] classes)


Copyright © ${year} The Codehaus. All Rights Reserved.