org.codehaus.groovy.runtime
Class MetaClassHelper
java.lang.Object
org.codehaus.groovy.runtime.MetaClassHelper
public class MetaClassHelper
- extends Object
- Author:
- John Wilson, Jochen Theodorou
Method Summary |
static boolean |
accessibleToConstructor(Class at,
Constructor constructor)
|
static Object |
asPrimitiveArray(List list,
Class parameterType)
|
static Object[] |
asWrapperArray(Object parameters,
Class componentType)
|
static long |
calculateParameterDistance(Class[] arguments,
Class[] parameters)
|
static String |
capitalize(String property)
|
static Object |
chooseEmptyMethodParams(FastArray methods)
|
static Object |
chooseMostGeneralMethodWith1NullParam(FastArray methods)
|
static boolean |
containsMatchingMethod(List list,
MetaMethod method)
|
static Class[] |
convertToTypeArray(Object[] args)
param instance array to the type array |
static Object |
doConstructorInvoke(CachedConstructor 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 ParameterTypes |
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(Object method,
Class[] arguments,
boolean includeCoerce)
|
static boolean |
isValidMethod(ParameterTypes pt,
Class[] arguments,
boolean includeCoerce)
|
static void |
logMethodCall(Object object,
String methodName,
Object[] arguments)
|
static Object |
makeArray(Object obj,
Class secondary,
int length)
|
static Object |
makeCommonArray(Object[] arguments,
int offset,
Class fallback)
|
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 |
EMPTY_ARRAY
public static final Object[] EMPTY_ARRAY
EMPTY_TYPE_ARRAY
public static final Class[] EMPTY_TYPE_ARRAY
ARRAY_WITH_NULL
public static final Object[] ARRAY_WITH_NULL
LOG
protected static final Logger LOG
MetaClassHelper
public MetaClassHelper()
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
- the original listparameterType
- the resulting array type
- Returns:
- the constructed array
calculateParameterDistance
public static long calculateParameterDistance(Class[] arguments,
Class[] parameters)
capitalize
public static String capitalize(String property)
chooseEmptyMethodParams
public static 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 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
containsMatchingMethod
public static boolean containsMatchingMethod(List list,
MetaMethod method)
- Parameters:
list
- a list of MetaMethodsmethod
- the MetaMethod of interest
- 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
- the arguments
- Returns:
- the types of the arguments
doConstructorInvoke
public static Object doConstructorInvoke(CachedConstructor constructor,
Object[] argumentArray)
makeCommonArray
public static Object makeCommonArray(Object[] arguments,
int offset,
Class fallback)
makeArray
public static Object makeArray(Object obj,
Class secondary,
int length)
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.
- Parameters:
object
- the object containing the methodmethodName
- the method of interest
- Returns:
- the resulting closure-like method pointer
getParameterTypes
public static ParameterTypes 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)
parametersAreCompatible
public static boolean parametersAreCompatible(Class[] arguments,
Class[] parameters)
isValidMethod
public static boolean isValidMethod(ParameterTypes pt,
Class[] arguments,
boolean includeCoerce)
isValidMethod
public static boolean isValidMethod(Object method,
Class[] arguments,
boolean includeCoerce)
logMethodCall
public static void logMethodCall(Object object,
String methodName,
Object[] arguments)
normalizedValue
protected static String normalizedValue(Object argument)
shortName
protected static String shortName(Object object)
wrap
public static Class[] wrap(Class[] classes)