Class ReflectionUtils


  • public class ReflectionUtils
    extends java.lang.Object
    Provides methods to help with reflective operations
    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isAssignableFrom​(java.lang.Class<?> leftType, java.lang.Class<?> rightType)
      Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e.
      static boolean isGetter​(java.lang.String name, java.lang.Class<?>[] args)
      Returns true if the name of the method specified and the number of arguments make it a javabean property
      static boolean isSetter​(java.lang.String name, java.lang.Class[] args)  
      static void makeAccessible​(java.lang.reflect.Field field)
      Make the given field accessible, explicitly setting it accessible if necessary.
      static void makeAccessible​(java.lang.reflect.Method method)
      Make the given method accessible, explicitly setting it accessible if necessary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PRIMITIVE_TYPE_COMPATIBLE_CLASSES

        public static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVE_TYPE_COMPATIBLE_CLASSES
    • Constructor Detail

      • ReflectionUtils

        public ReflectionUtils()
    • Method Detail

      • makeAccessible

        public static void makeAccessible​(java.lang.reflect.Field field)
        Make the given field accessible, explicitly setting it accessible if necessary. The setAccessible(true) method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active). Based on the same method in Spring core.
        Parameters:
        field - the field to make accessible
        See Also:
        Field.setAccessible(boolean)
      • makeAccessible

        public static void makeAccessible​(java.lang.reflect.Method method)
        Make the given method accessible, explicitly setting it accessible if necessary. The setAccessible(true) method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active). Based on the same method in Spring core.
        Parameters:
        method - the method to make accessible
        See Also:
        Method.setAccessible(boolean)
      • isAssignableFrom

        public static boolean isAssignableFrom​(java.lang.Class<?> leftType,
                                               java.lang.Class<?> rightType)

        Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e. can the left type be assigned a value of the right hand type in Groovy.

        This handles Java primitive type equivalence and uses isAssignableFrom for all other types, with a bit of magic for native types and polymorphism i.e. Number assigned an int. If either parameter is null an exception is thrown

        Parameters:
        leftType - The type of the left hand part of a notional assignment
        rightType - The type of the right hand part of a notional assignment
        Returns:
        True if values of the right hand type can be assigned in Groovy to variables of the left hand type.
      • isGetter

        public static boolean isGetter​(java.lang.String name,
                                       java.lang.Class<?>[] args)
        Returns true if the name of the method specified and the number of arguments make it a javabean property
        Parameters:
        name - True if its a Javabean property
        args - The arguments
        Returns:
        true if it is a javabean property method
      • isSetter

        public static boolean isSetter​(java.lang.String name,
                                       java.lang.Class[] args)