org.codehaus.groovy.runtime
Class MetaClassHelper

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

public class MetaClassHelper
extends Object

Author:
John Wilson

Field Summary
protected static Object[] ARRAY_WITH_EMPTY_ARRAY
           
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)
           
protected static Class autoboxType(Class type)
           
static int calculateParameterDistance(Class[] arguments, Class[] parameters)
           
static String capitalize(String property)
           
protected static void checkForInvalidOverloading(String name, Class[] baseTypes, Class[] derivedTypes)
          Checks that one of the parameter types is a superset of the other and that the two lists of types don't conflict.
static Object chooseEmptyMethodParams(List methods)
           
static Object chooseMostGeneralMethodWith1NullParam(List methods)
           
static boolean coerceGStrings(Object[] arguments)
          Coerces any GString instances into Strings
protected static Object[] coerceNumbers(MetaMethod method, Object[] arguments)
           
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)
           
protected static boolean isAssignableFrom(Class mostSpecificType, Class type)
           
protected static boolean isCompatibleClass(Class type, Class value, boolean includeCoerce)
           
protected static boolean isCompatibleInstance(Class type, Object value, boolean includeCoerce)
           
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_EMPTY_ARRAY

protected static final Object[] ARRAY_WITH_EMPTY_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)

asPrimitiveArray

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

autoboxType

protected static Class autoboxType(Class type)

calculateParameterDistance

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

capitalize

public static String capitalize(String property)

checkForInvalidOverloading

protected static void checkForInvalidOverloading(String name,
                                                 Class[] baseTypes,
                                                 Class[] derivedTypes)
Checks that one of the parameter types is a superset of the other and that the two lists of types don't conflict. e.g. foo(String, Object) and foo(Object, String) would conflict if called with foo("a", "b"). Note that this method is only called with 2 possible signatures. i.e. possible invalid combinations will already have been filtered out. So if there were methods foo(String, Object) and foo(Object, String) then one of these would be already filtered out if foo was called as foo(12, "a")


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

coerceGStrings

public static boolean coerceGStrings(Object[] arguments)
Coerces any GString instances into Strings

Returns:
true if some coercion was done.

coerceNumbers

protected static Object[] coerceNumbers(MetaMethod method,
                                        Object[] arguments)

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 -
Returns:

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)

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

protected static boolean isAssignableFrom(Class mostSpecificType,
                                          Class type)

isCompatibleClass

protected static boolean isCompatibleClass(Class type,
                                           Class value,
                                           boolean includeCoerce)

isCompatibleInstance

protected static boolean isCompatibleInstance(Class type,
                                              Object value,
                                              boolean includeCoerce)

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-2007 The Codehaus. All Rights Reserved.