Class MetaClassHelper

  • public class MetaClassHelper
    extends Object
    • Field Detail


        public static final Object[] EMPTY_ARRAY

        public static final Class[] EMPTY_TYPE_ARRAY

        public static final Object[] ARRAY_WITH_NULL
      • LOG

        protected static final Logger LOG

        public static final Class[] EMPTY_CLASS_ARRAY
    • 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)
        list - the original list
        parameterType - the resulting array type
        the constructed array
      • calculateParameterDistance

        public static long calculateParameterDistance​(Class[] arguments,
                                                      ParameterTypes pt)
      • capitalize

        public static String capitalize​(String property)
        Use BeanUtils.capitalize instead
      • chooseEmptyMethodParams

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

        public static Object chooseMostGeneralMethodWith1NullParam​(FastArray methods)
        Warning: this method does not choose properly if multiple methods with the same distance are encountered
        methods - the methods to choose from
        the method with 1 parameter which takes the most general type of object (e.g. Object) ignoring primitive types
      • containsMatchingMethod

        public static boolean containsMatchingMethod​(List list,
                                                     MetaMethod method)
        list - a list of MetaMethods
        method - the MetaMethod of interest
        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
        args - the arguments
        the types of the arguments
      • makeCommonArray

        public static Object makeCommonArray​(Object[] arguments,
                                             int offset,
                                             Class fallback)
      • makeArray

        public static Object makeArray​(Object obj,
                                       Class secondary,
                                       int length)
      • 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.
        object - the object containing the method
        methodName - the method of interest
        the resulting closure-like method pointer
      • isAssignableFrom

        public static boolean isAssignableFrom​(Class classToTransformTo,
                                               Class classToTransformFrom)
      • isGenericSetMethod

        public static boolean isGenericSetMethod​(MetaMethod method)
      • isSuperclass

        protected static boolean isSuperclass​(Class clazz,
                                              Class superclass)
      • parametersAreCompatible

        public static boolean parametersAreCompatible​(Class[] arguments,
                                                      Class[] parameters)
      • 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)
      • sameClasses

        public static boolean sameClasses​(Class[] params,
                                          Object[] arguments,
                                          boolean weakNullCheck)
      • sameClasses

        public static boolean sameClasses​(Class[] params,
                                          Object[] arguments)
      • sameClasses

        public static boolean sameClasses​(Class[] params)
      • sameClasses

        public static boolean sameClasses​(Class[] params,
                                          Object arg1)
      • sameClasses

        public static boolean sameClasses​(Class[] params,
                                          Object arg1,
                                          Object arg2)
      • sameClass

        public static boolean sameClass​(Class[] params,
                                        Object arg)
      • castArgumentsToClassArray

        public static Class[] castArgumentsToClassArray​(Object[] argTypes)
      • unwrap

        public static void unwrap​(Object[] arguments)
      • doSetMetaClass

        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.
        self - the object for which to set the meta class
        mc - the metaclass
      • convertPropertyName

        public static String convertPropertyName​(String prop)
        Converts a String into a standard property name.
        prop - the original name
        the converted name