Top Fields Constructors Methods
org.codehaus.groovy.runtime

public Class MetaClassHelper

extends Object
Class Inheritance
Imports
groovy.lang.Closure, .GString, .GroovyObject, .GroovyRuntimeException, .MetaClass, .MetaMethod, org.apache.groovy.util.BeanUtils, org.codehaus.groovy.reflection.CachedClass, .ParameterTypes, .ReflectionCache, org.codehaus.groovy.runtime.wrappers.Wrapper, org.codehaus.groovy.util.FastArray, java.lang.reflect.Array, .Constructor, .Modifier, java.math.BigDecimal, .BigInteger, java.util.Arrays, .HashSet, .List, .Set, java.util.logging.Level, .Logger

Field Summary

Modifier and TypeField and Description
public static final Object[]
public static final Object[]
public static final Class<T>[]
public static final Class<T>[]
private static final int
protected static final Logger
private static final int
private static final int
private static final int[][]
private static final int
private static final Class<T>[]
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean
accessibleToConstructor(final Class<T> at, final Constructor<T> constructor)

public static Object

Returns:

the constructed array
asPrimitiveArray
(List<E>
the original list
list
,
Class<T>
the resulting array type
parameterType
)

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

private static long
public static long
public static String
capitalize(final String property)

Deprecated Use BeanUtils.capitalize instead
public static Class<T>[]
private static Boolean
checkCompatiblePackages(Class<T> at, Constructor<T> constructor)

public static Object

Returns:

the method with 1 parameter which takes the most general type of object (e.g. Object)
chooseEmptyMethodParams
(FastArray
the methods to choose from
methods
)

public static Object

Returns:

the method with 1 parameter which takes the most general type of object (e.g. Object) ignoring primitive types
chooseMostGeneralMethodWith1NullParam
(FastArray
the methods to choose from
methods
)

Deprecated

Warning

this method does not choose properly if multiple methods with the same distance are encountered

public static boolean

Returns:

true if a method of the same matching prototype was found in the list
containsMatchingMethod
(List<E>
a list of MetaMethods
list
,
MetaMethod
the MetaMethod of interest
method
)

public static String

Returns:

the converted name
convertPropertyName
(String
the original name
prop
)

Converts a String into a standard property name.

public static Class<T>[]

Returns:

the types of the arguments
convertToTypeArray
(Object[]
the arguments
args
)

param instance array to the type array

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

public static void
doSetMetaClass(Object
the object for which to set the meta class
self
,
MetaClass
the metaclass
mc
)

Sets the meta class for an object, by delegating to the appropriate DefaultGroovyMethods helper method.

protected static String
private static Class<T>
private static int
getMaximumInterfaceDistance(Class<T> c, Class<T> interfaceClass)

public static Closure<V>

Returns:

the resulting closure-like method pointer
getMethodPointer
(Object
the object containing the method
object
,
String
the method of interest
methodName
)

Returns a callable object for the given method name on the object.

private static int
private static int
public static boolean
isAssignableFrom(Class<T> classToTransformTo, Class<T> classToTransformFrom)

public static boolean
private static boolean
isIntegerLongShortByte(Class<T> classToTransformFrom)

protected static boolean
isSuperclass(Class<T> clazz, Class<T> superclass)

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

public static Object
makeArray(Object obj, Class<T> secondary, int length)

public static Object
makeCommonArray(Object[] arguments, int offset, Class<T> fallback)

protected static String
public static boolean
parametersAreCompatible(Class<T>[] arguments, Class<T>[] parameters)

public static boolean
sameClass(Class<T>[] params, Object arg)

public static boolean
sameClasses(Class<T>[] params, Object[] arguments, boolean weakNullCheck)

public static boolean
sameClasses(Class<T>[] params, Object[] arguments)

public static boolean
sameClasses(Class<T>[] params)

public static boolean
sameClasses(Class<T>[] params, Object arg1)

public static boolean
sameClasses(Class<T>[] params, Object arg1, Object arg2)

public static boolean
sameClasses(Class<T>[] params, Object arg1, Object arg2, Object arg3)

public static boolean
sameClasses(Class<T>[] params, Object arg1, Object arg2, Object arg3, Object arg4)

protected static String
shortName(Object object)

public static void
unwrap(Object[] arguments)

public static Class<T>[]
wrap(Class<T>[] classes)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAY_WITH_NULLback to summary
public static final Object[] ARRAY_WITH_NULL
EMPTY_ARRAYback to summary
public static final Object[] EMPTY_ARRAY
EMPTY_CLASS_ARRAYback to summary
public static final Class<T>[] EMPTY_CLASS_ARRAY
EMPTY_TYPE_ARRAYback to summary
public static final Class<T>[] EMPTY_TYPE_ARRAY
INTERFACE_SHIFTback to summary
private static final int INTERFACE_SHIFT
LOGback to summary
protected static final Logger LOG
MAX_ARG_LENback to summary
private static final int MAX_ARG_LEN
OBJECT_SHIFTback to summary
private static final int OBJECT_SHIFT
PRIMITIVE_DISTANCE_TABLEback to summary
private static final int[][] PRIMITIVE_DISTANCE_TABLE
PRIMITIVE_SHIFTback to summary
private static final int PRIMITIVE_SHIFT
PRIMITIVESback to summary
private static final Class<T>[] PRIMITIVES
VARGS_SHIFTback to summary
private static final int VARGS_SHIFT

Constructor Detail

MetaClassHelperback to summary
public MetaClassHelper()

Method Detail

accessibleToConstructorback to summary
public static boolean accessibleToConstructor(final Class<T> at, final Constructor<T> constructor)
asPrimitiveArrayback to summary
public static Object asPrimitiveArray(List<E> list, Class<T> parameterType)
Parameters
list:List<E>

the original list

parameterType:Class<T>

the resulting array type

Returns:Object

the constructed array

asWrapperArrayback to summary
public static Object[] asWrapperArray(Object parameters, Class<T> componentType)
calculateParameterDistanceback to summary
private static long calculateParameterDistance(Class<T> argument, CachedClass parameter)
calculateParameterDistanceback to summary
public static long calculateParameterDistance(Class<T>[] arguments, ParameterTypes pt)
capitalizeback to summary
public static String capitalize(final String property)

Deprecated

Use BeanUtils.capitalize instead

Annotations
@Deprecated
castArgumentsToClassArrayback to summary
public static Class<T>[] castArgumentsToClassArray(Object[] argTypes)
checkCompatiblePackagesback to summary
private static Boolean checkCompatiblePackages(Class<T> at, Constructor<T> constructor)
chooseEmptyMethodParamsback to summary
public static Object chooseEmptyMethodParams(FastArray methods)
Parameters
methods:FastArray

the methods to choose from

Returns:Object

the method with 1 parameter which takes the most general type of object (e.g. Object)

chooseMostGeneralMethodWith1NullParamback to summary
public static Object chooseMostGeneralMethodWith1NullParam(FastArray methods)

Deprecated

Warning

this method does not choose properly if multiple methods with the same distance are encountered

Parameters
methods:FastArray

the methods to choose from

Returns:Object

the method with 1 parameter which takes the most general type of object (e.g. Object) ignoring primitive types

Annotations
@Deprecated
containsMatchingMethodback to summary
public static boolean containsMatchingMethod(List<E> list, MetaMethod method)
Parameters
list:List<E>

a list of MetaMethods

method:MetaMethod

the MetaMethod of interest

Returns:boolean

true if a method of the same matching prototype was found in the list

convertPropertyNameback to summary
public static String convertPropertyName(String prop)

Converts a String into a standard property name.

Parameters
prop:String

the original name

Returns:String

the converted name

convertToTypeArrayback to summary
public static Class<T>[] convertToTypeArray(Object[] args)

param instance array to the type array

Parameters
args:Object[]

the arguments

Returns:Class<T>[]

the types of the arguments

createExceptionTextback to summary
public static GroovyRuntimeException createExceptionText(String init, MetaMethod method, Object object, Object[] args, Throwable reason, boolean setReason)
doSetMetaClassback to summary
public static void doSetMetaClass(Object self, MetaClass mc)

Sets the meta class for an object, by delegating to the appropriate DefaultGroovyMethods helper method. This method was introduced as a breaking change in 2.0 to solve rare cases of stack overflow. See GROOVY-5285. The method is named doSetMetaClass in order to prevent misusages. Do not use this method directly unless you know what you do.

Parameters
self:Object

the object for which to set the meta class

mc:MetaClass

the metaclass

getClassNameback to summary
protected static String getClassName(Object object)
getClassWithNullAndWrapperback to summary
private static Class<T> getClassWithNullAndWrapper(Object arg)
getMaximumInterfaceDistanceback to summary
private static int getMaximumInterfaceDistance(Class<T> c, Class<T> interfaceClass)
getMethodPointerback to summary
public static Closure<V> 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:Object

the object containing the method

methodName:String

the method of interest

Returns:Closure<V>

the resulting closure-like method pointer

getPrimitiveDistanceback to summary
private static int getPrimitiveDistance(Class<T> from, Class<T> to)
getPrimitiveIndexback to summary
private static int getPrimitiveIndex(Class<T> c)
isAssignableFromback to summary
public static boolean isAssignableFrom(Class<T> classToTransformTo, Class<T> classToTransformFrom)
isGenericSetMethodback to summary
public static boolean isGenericSetMethod(MetaMethod method)
isIntegerLongShortByteback to summary
private static boolean isIntegerLongShortByte(Class<T> classToTransformFrom)
isSuperclassback to summary
protected static boolean isSuperclass(Class<T> clazz, Class<T> superclass)
logMethodCallback to summary
public static void logMethodCall(Object object, String methodName, Object[] arguments)
makeArrayback to summary
public static Object makeArray(Object obj, Class<T> secondary, int length)
makeCommonArrayback to summary
public static Object makeCommonArray(Object[] arguments, int offset, Class<T> fallback)
normalizedValueback to summary
protected static String normalizedValue(Object argument)
parametersAreCompatibleback to summary
public static boolean parametersAreCompatible(Class<T>[] arguments, Class<T>[] parameters)
sameClassback to summary
public static boolean sameClass(Class<T>[] params, Object arg)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object[] arguments, boolean weakNullCheck)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object[] arguments)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object arg1)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object arg1, Object arg2)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object arg1, Object arg2, Object arg3)
sameClassesback to summary
public static boolean sameClasses(Class<T>[] params, Object arg1, Object arg2, Object arg3, Object arg4)
shortNameback to summary
protected static String shortName(Object object)
unwrapback to summary
public static void unwrap(Object[] arguments)
wrapback to summary
public static Class<T>[] wrap(Class<T>[] classes)