Class MemberUtils

java.lang.Object
org.apache.commons.lang3.reflect.MemberUtils

abstract class MemberUtils extends Object
Contains common code for working with Methods/Constructors, extracted and refactored from MethodUtils when it was imported from Commons BeanUtils.
Since:
2.5
  • Field Details

    • ACCESS_TEST

      private static final int ACCESS_TEST
      See Also:
    • ORDERED_PRIMITIVE_TYPES

      private static final Class<?>[] ORDERED_PRIMITIVE_TYPES
      Array of primitive number types ordered by "promotability"
  • Constructor Details

    • MemberUtils

      MemberUtils()
  • Method Details

    • setAccessibleWorkaround

      static boolean setAccessibleWorkaround(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) prevent access even when the modifier 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
      Returns:
      a boolean indicating whether the accessibility of the object was set to true.
    • isPackageAccess

      static boolean isPackageAccess(int modifiers)
      Returns 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(Member m)
      Returns whether a Member is accessible.
      Parameters:
      m - Member to check
      Returns:
      true if m is accessible
    • compareConstructorFit

      static int compareConstructorFit(Constructor<?> left, Constructor<?> right, Class<?>[] actual)
      Compares the relative fitness of two Constructors in terms of how well they match a 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" Constructor
      right - the "right" Constructor
      actual - the runtime parameter types to match against left/right
      Returns:
      int consistent with compare semantics
      Since:
      3.5
    • compareMethodFit

      static int compareMethodFit(Method left, Method right, Class<?>[] actual)
      Compares the relative fitness of two Methods in terms of how well they match a 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" Method
      right - the "right" Method
      actual - the runtime parameter types to match against left/right
      Returns:
      int consistent with compare semantics
      Since:
      3.5
    • compareParameterTypes

      private static int compareParameterTypes(MemberUtils.Executable left, MemberUtils.Executable right, Class<?>[] actual)
      Compares the relative fitness of two Executables in terms of how well they match a 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" Executable
      right - the "right" Executable
      actual - the runtime parameter types to match against left/right
      Returns:
      int consistent with compare semantics
    • getTotalTransformationCost

      private static float getTotalTransformationCost(Class<?>[] srcArgs, MemberUtils.Executable executable)
      Returns the sum of the object transformation cost for each class in the source argument list.
      Parameters:
      srcArgs - The source arguments
      executable - The executable to calculate transformation costs for
      Returns:
      The total transformation cost
    • getObjectTransformationCost

      private static float getObjectTransformationCost(Class<?> srcClass, 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(Class<?> srcClass, Class<?> destClass)
      Gets 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
    • isMatchingMethod

      static boolean isMatchingMethod(Method method, Class<?>[] parameterTypes)
    • isMatchingConstructor

      static boolean isMatchingConstructor(Constructor<?> method, Class<?>[] parameterTypes)
    • isMatchingExecutable

      private static boolean isMatchingExecutable(MemberUtils.Executable method, Class<?>[] parameterTypes)