Class MemberUtils


  • abstract class MemberUtils
    extends java.lang.Object
    Contains common code for working with Methods/Constructors, extracted and refactored from MethodUtils when it was imported from Commons BeanUtils.
    Since:
    2.5
    Version:
    $Id: MemberUtils.java 1057013 2011-01-09 20:04:16Z niallp $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int ACCESS_TEST  
      private static java.lang.reflect.Method IS_SYNTHETIC  
      private static java.lang.Class[] ORDERED_PRIMITIVE_TYPES
      Array of primitive number types ordered by "promotability"
    • Constructor Summary

      Constructors 
      Constructor Description
      MemberUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int compareParameterTypes​(java.lang.Class[] left, java.lang.Class[] right, java.lang.Class[] actual)
      Compare the relative fitness of two sets of parameter types in terms of matching a third set of runtime parameter types, such that a list ordered by the results of the comparison would return the best match first (least).
      private static float getObjectTransformationCost​(java.lang.Class srcClass, java.lang.Class destClass)
      Gets the number of steps required needed to turn the source class into the destination class.
      private static float getPrimitivePromotionCost​(java.lang.Class srcClass, java.lang.Class destClass)
      Get the number of steps required to promote a primitive number to another type.
      private static float getTotalTransformationCost​(java.lang.Class[] srcArgs, java.lang.Class[] destArgs)
      Returns the sum of the object transformation cost for each class in the source argument list.
      (package private) static boolean isAccessible​(java.lang.reflect.Member m)
      Check a Member for basic accessibility.
      (package private) static boolean isPackageAccess​(int modifiers)
      Learn whether a given set of modifiers implies package access.
      (package private) static boolean isSynthetic​(java.lang.reflect.Member m)
      Try to learn whether a given member, on JDK >= 1.5, is synthetic.
      (package private) static void setAccessibleWorkaround​(java.lang.reflect.AccessibleObject o)
      XXX Default access superclass workaround When a public class has a default access superclass with public members, these members are accessible.
      • Methods inherited from class java.lang.Object

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

      • IS_SYNTHETIC

        private static final java.lang.reflect.Method IS_SYNTHETIC
      • ORDERED_PRIMITIVE_TYPES

        private static final java.lang.Class[] ORDERED_PRIMITIVE_TYPES
        Array of primitive number types ordered by "promotability"
    • Constructor Detail

      • MemberUtils

        MemberUtils()
    • Method Detail

      • setAccessibleWorkaround

        static void setAccessibleWorkaround​(java.lang.reflect.AccessibleObject o)
        XXX Default access superclass workaround When a public class has a default access superclass with public members, these members are accessible. Calling them from compiled code works fine. Unfortunately, on some JVMs, using reflection to invoke these members seems to (wrongly) to prevent access even when the modifer is public. Calling setAccessible(true) solves the problem but will only work from sufficiently privileged code. Better workarounds would be gratefully accepted.
        Parameters:
        o - the AccessibleObject to set as accessible
      • isPackageAccess

        static boolean isPackageAccess​(int modifiers)
        Learn whether a given set of modifiers implies package access.
        Parameters:
        modifiers - to test
        Returns:
        true unless package/protected/private modifier detected
      • isAccessible

        static boolean isAccessible​(java.lang.reflect.Member m)
        Check a Member for basic accessibility.
        Parameters:
        m - Member to check
        Returns:
        true if m is accessible
      • isSynthetic

        static boolean isSynthetic​(java.lang.reflect.Member m)
        Try to learn whether a given member, on JDK >= 1.5, is synthetic.
        Parameters:
        m - Member to check
        Returns:
        true if m was introduced by the compiler.
      • compareParameterTypes

        static int compareParameterTypes​(java.lang.Class[] left,
                                         java.lang.Class[] right,
                                         java.lang.Class[] actual)
        Compare the relative fitness of two sets of parameter types in terms of matching a third set of runtime parameter types, such that a list ordered by the results of the comparison would return the best match first (least).
        Parameters:
        left - the "left" parameter set
        right - the "right" parameter set
        actual - the runtime parameter types to match against left/right
        Returns:
        int consistent with compare semantics
      • getTotalTransformationCost

        private static float getTotalTransformationCost​(java.lang.Class[] srcArgs,
                                                        java.lang.Class[] destArgs)
        Returns the sum of the object transformation cost for each class in the source argument list.
        Parameters:
        srcArgs - The source arguments
        destArgs - The destination arguments
        Returns:
        The total transformation cost
      • getObjectTransformationCost

        private static float getObjectTransformationCost​(java.lang.Class srcClass,
                                                         java.lang.Class destClass)
        Gets the number of steps required needed to turn the source class into the destination class. This represents the number of steps in the object hierarchy graph.
        Parameters:
        srcClass - The source class
        destClass - The destination class
        Returns:
        The cost of transforming an object
      • getPrimitivePromotionCost

        private static float getPrimitivePromotionCost​(java.lang.Class srcClass,
                                                       java.lang.Class destClass)
        Get the number of steps required to promote a primitive number to another type.
        Parameters:
        srcClass - the (primitive) source class
        destClass - the (primitive) destination class
        Returns:
        The cost of promoting the primitive