org.codehaus.groovy.runtime
Class MetaClassHelper

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

public class MetaClassHelper
extends Object

Author:
John Wilson, Jochen Theodorou

Field Summary
protected static Object[] ARRAY_WITH_NULL
           
static Object[] EMPTY_ARRAY
           
static Class[] EMPTY_TYPE_ARRAY
           
protected static Logger log
           
 
Constructor Summary
MetaClassHelper()
           
 
Method Summary
static boolean accessibleToConstructor(Class at, Constructor constructor)
           
static Object asPrimitiveArray(List list, Class parameterType)
           
static Object[] asWrapperArray(Object parameters, Class componentType)
           
protected static Class autoboxType(Class type)
           
static long calculateParameterDistance(Class[] arguments, Class[] parameters)
           
static String capitalize(String property)
           
static Object chooseEmptyMethodParams(List methods)
           
static Object chooseMostGeneralMethodWith1NullParam(List methods)
           
static Object[] coerceArgumentsToClasses(Object[] argumentArray, Class[] paramTypes)
           
protected static Object coerceArray(Object argument, Class param)
           
protected static Object coerceGString(Object argument, Class clazz)
          Coerces a GString instance into String if needed
protected static Object coerceNumber(Object argument, Class param)
           
static boolean containsMatchingMethod(List list, MetaMethod method)
           
static Class[] convertToTypeArray(Object[] args)
          param instance array to the type array
static Object createListenerProxy(Class listenerType, String listenerMethodName, Closure closure)
           
static Object doConstructorInvoke(Constructor constructor, Object[] argumentArray)
           
static Object doMethodInvoke(Object object, MetaMethod method, Object[] argumentArray)
           
protected static String getClassName(Object object)
           
static Closure getMethodPointer(Object object, String methodName)
          Returns a callable object for the given method name on the object.
static Class[] getParameterTypes(Object methodOrConstructor)
           
static boolean isAssignableFrom(Class classToTransformTo, Class classToTransformFrom)
           
static boolean isGenericSetMethod(MetaMethod method)
           
protected static boolean isSuperclass(Class claszz, Class superclass)
           
static boolean isValidMethod(Class[] paramTypes, Class[] arguments, boolean includeCoerce)
           
static boolean isValidMethod(Object method, Class[] arguments, boolean includeCoerce)
           
static boolean isVargsMethod(Class[] paramTypes, Object[] arguments)
           
static void logMethodCall(Object object, String methodName, Object[] arguments)
           
protected static String normalizedValue(Object argument)
           
static boolean parametersAreCompatible(Class[] arguments, Class[] parameters)
           
protected static String shortName(Object object)
           
static Class[] wrap(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 Object[] EMPTY_ARRAY

EMPTY_TYPE_ARRAY

public static Class[] EMPTY_TYPE_ARRAY

ARRAY_WITH_NULL

protected static final Object[] ARRAY_WITH_NULL

log

protected static final Logger log
Constructor Detail

MetaClassHelper

public MetaClassHelper()
Method Detail

accessibleToConstructor

public static boolean accessibleToConstructor(Class at,
                                              Constructor constructor)

asWrapperArray

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

asPrimitiveArray

public static Object asPrimitiveArray(List list,
                                      Class parameterType)
Parameters:
list -
parameterType -

autoboxType

protected static Class autoboxType(Class type)

calculateParameterDistance

public static long calculateParameterDistance(Class[] arguments,
                                              Class[] parameters)

capitalize

public static String capitalize(String property)

chooseEmptyMethodParams

public static Object chooseEmptyMethodParams(List methods)
Returns:
the method with 1 parameter which takes the most general type of object (e.g. Object)

chooseMostGeneralMethodWith1NullParam

public static Object chooseMostGeneralMethodWith1NullParam(List methods)
Returns:
the method with 1 parameter which takes the most general type of object (e.g. Object) ignoring primitve types

coerceGString

protected static Object coerceGString(Object argument,
                                      Class clazz)
Coerces a GString instance into String if needed

Returns:
the coerced argument

coerceNumber

protected static Object coerceNumber(Object argument,
                                     Class param)

coerceArray

protected static Object coerceArray(Object argument,
                                    Class param)

containsMatchingMethod

public static boolean containsMatchingMethod(List list,
                                             MetaMethod method)
Returns:
true if a method of the same matching prototype was found in the list

convertToTypeArray

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

Parameters:
args -

createListenerProxy

public static Object createListenerProxy(Class listenerType,
                                         String listenerMethodName,
                                         Closure closure)
Parameters:
listenerType - the interface of the listener to proxy
listenerMethodName - the name of the method in the listener API to call the closure on
closure - the closure to invoke on the listenerMethodName method invocation
Returns:
a dynamic proxy which calls the given closure on the given method name

doConstructorInvoke

public static Object doConstructorInvoke(Constructor constructor,
                                         Object[] argumentArray)

coerceArgumentsToClasses

public static Object[] coerceArgumentsToClasses(Object[] argumentArray,
                                                Class[] paramTypes)

doMethodInvoke

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

getClassName

protected static String getClassName(Object object)

getMethodPointer

public static Closure getMethodPointer(Object object,
                                       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.


getParameterTypes

public static Class[] getParameterTypes(Object methodOrConstructor)

isAssignableFrom

public static boolean isAssignableFrom(Class classToTransformTo,
                                       Class classToTransformFrom)

isGenericSetMethod

public static boolean isGenericSetMethod(MetaMethod method)

isSuperclass

protected static boolean isSuperclass(Class claszz,
                                      Class superclass)

isValidMethod

public static boolean isValidMethod(Class[] paramTypes,
                                    Class[] arguments,
                                    boolean includeCoerce)

isValidMethod

public static boolean isValidMethod(Object method,
                                    Class[] arguments,
                                    boolean includeCoerce)

isVargsMethod

public static boolean isVargsMethod(Class[] paramTypes,
                                    Object[] arguments)

logMethodCall

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

normalizedValue

protected static String normalizedValue(Object argument)

parametersAreCompatible

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

shortName

protected static String shortName(Object object)

wrap

public static Class[] wrap(Class[] classes)


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