Package org.apache.commons.lang3.reflect
Class MemberUtils
java.lang.Object
org.apache.commons.lang3.reflect.MemberUtils
Contains common code for working with
Methods/Constructors,
extracted and refactored from MethodUtils when it was imported from Commons BeanUtils.- Since:
- 2.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classA class providing a subset of the API of java.lang.reflect.Executable in Java 1.8, providing a common representation for function signatures for Constructors and Methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final Class<?>[]Array of primitive number types ordered by "promotability" -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static intcompareConstructorFit(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).(package private) static intcompareMethodFit(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).private static intcompareParameterTypes(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).private static floatgetObjectTransformationCost(Class<?> srcClass, Class<?> destClass) Gets the number of steps needed to turn the source class into the destination class.private static floatgetPrimitivePromotionCost(Class<?> srcClass, Class<?> destClass) Gets the number of steps required to promote a primitive number to another type.private static floatgetTotalTransformationCost(Class<?>[] srcArgs, MemberUtils.Executable executable) Returns the sum of the object transformation cost for each class in the source argument list.(package private) static booleanisAccessible(Member member) Tests whether aMemberis accessible.(package private) static booleanisMatchingConstructor(Constructor<?> method, Class<?>[] parameterTypes) private static booleanisMatchingExecutable(MemberUtils.Executable method, Class<?>[] parameterTypes) (package private) static booleanisMatchingMethod(Method method, Class<?>[] parameterTypes) (package private) static booleanisPackageAccess(int modifiers) Tests whether a given set of modifiers implies package access.(package private) static booleanTests whether aMemberis public.(package private) static booleanTests whether aMemberis static.(package private) static <T extends AccessibleObject>
TsetAccessibleWorkaround(T obj) Default access superclass workaround.
-
Field Details
-
ACCESS_TEST
private static final int ACCESS_TEST- See Also:
-
ORDERED_PRIMITIVE_TYPES
Array of primitive number types ordered by "promotability"
-
-
Constructor Details
-
MemberUtils
MemberUtils()
-
-
Method Details
-
compareConstructorFit
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" Constructorright- the "right" Constructoractual- the runtime parameter types to match againstleft/right- Returns:
- int consistent with
comparesemantics - Since:
- 3.5
-
compareMethodFit
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" Methodright- the "right" Methodactual- the runtime parameter types to match againstleft/right- Returns:
- int consistent with
comparesemantics - 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" Executableright- the "right" Executableactual- the runtime parameter types to match againstleft/right- Returns:
- int consistent with
comparesemantics
-
getObjectTransformationCost
Gets the number of steps 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 classdestClass- The destination class- Returns:
- The cost of transforming an object
-
getPrimitivePromotionCost
Gets the number of steps required to promote a primitive number to another type.- Parameters:
srcClass- the (primitive) source classdestClass- the (primitive) destination class- Returns:
- The cost of promoting the primitive
-
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 argumentsexecutable- The executable to calculate transformation costs for- Returns:
- The total transformation cost
-
isAccessible
Tests whether aMemberis accessible.- Parameters:
member- Member to test- Returns:
trueifmis accessible
-
isMatchingConstructor
-
isMatchingExecutable
private static boolean isMatchingExecutable(MemberUtils.Executable method, Class<?>[] parameterTypes) -
isMatchingMethod
-
isPackageAccess
static boolean isPackageAccess(int modifiers) Tests whether a given set of modifiers implies package access.- Parameters:
modifiers- to test- Returns:
trueunlesspackage/protected/privatemodifier detected
-
isPublic
Tests whether aMemberis public.- Parameters:
member- Member to test- Returns:
trueifmis public
-
isStatic
Tests whether aMemberis static.- Parameters:
member- Member to test- Returns:
trueifmis static
-
setAccessibleWorkaround
Default access superclass workaround. When apublicclass has a default access superclass withpublicmembers, 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 ispublic. CallingsetAccessible(true)solves the problem but will only work from sufficiently privileged code. Better workarounds would be gratefully accepted.- Parameters:
obj- the AccessibleObject to set as accessible- Returns:
- a boolean indicating whether the accessibility of the object was set to true.
-