Top Description Inners Fields Constructors Methods
org.apache.commons.lang3.reflect

pack-priv final Class MemberUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.AccessibleObject, .Constructor, .Member, .Method, .Modifier, org.apache.commons.lang3.ClassUtils

Contains common code for working with Methods/Constructors, extracted and refactored from MethodUtils when it was imported from Commons BeanUtils.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MemberUtils.Executable

A 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

Modifier and TypeField and Description
private static final int
private static final Class<?>[]
WIDENING_PRIMITIVE_TYPES

Array of primitive number types ordered by "promotability" from narrow to wide.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static int

Returns:

int consistent with compare semantics.
compareConstructorFit
(final Constructor<?>
the "left" Constructor.
left
,
final Constructor<?>
the "right" Constructor.
right
,
final Class<?>[]
the runtime parameter types to match against. left/right.
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).

pack-priv static int

Returns:

int consistent with compare semantics.
compareMethodFit
(final Method
the "left" Method.
left
,
final Method
the "right" Method.
right
,
final Class<?>[]
the runtime parameter types to match against. left/right.
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 int

Returns:

int consistent with compare semantics.
compareParameterTypes
(final MemberUtils.Executable
the "left" Executable.
left
,
final MemberUtils.Executable
the "right" Executable.
right
,
final Class<?>[]
the runtime parameter types to match against. left/right.
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 float

Returns:

The cost of transforming an object.
getObjectTransformationCost
(Class<?>
The source class.
srcClass
,
final Class<?>
The destination class.
destClass
)

Gets the number of steps needed to turn the source class into the destination class.

private static float

Returns:

The cost of promoting the primitive.
getPrimitivePromotionCost
(final Class<?>
the (primitive) source class.
srcClass
,
final Class<?>
the (primitive) destination class.
destClass
)

Gets the number of steps required to promote a primitive to another type.

private static float

Returns:

The total transformation cost.
getTotalTransformationCost
(final Class<?>[]
The source arguments.
srcArgs
,
final MemberUtils.Executable
The executable to calculate transformation costs for.
executable
)

Gets the sum of the object transformation cost for each class in the source argument list.

pack-priv static boolean

Returns:

true if m is accessible.
isAccessible
(final Member
Member to test, may be null.
member
)

Tests whether a Member is accessible.

pack-priv static boolean
isMatchingConstructor(final Constructor<?> method, final Class<?>[] parameterTypes)

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

pack-priv static boolean
isMatchingMethod(final Method method, final Class<?>[] parameterTypes)

pack-priv static boolean

Returns:

true unless package/protected/private modifier detected
isPackage
(final int
to test.
modifiers
)

Tests whether a given set of modifiers implies package access.

pack-priv static boolean

Returns:

true if m is public.
isPublic
(final Member
Member to test, may be null.
member
)

Tests whether a Member is public.

pack-priv static boolean

Returns:

true if m is static.
isStatic
(final Member
Member to test, may be null.
member
)

Tests whether a Member is static.

pack-priv static <T extends AccessibleObject> T

Returns:

a boolean indicating whether the accessibility of the object was set to true.
setAccessibleWorkaround
(final T
the AccessibleObject to set as accessible, may be null.
obj
)

Default access superclass workaround.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACCESS_TESTback to summary
private static final int ACCESS_TEST
WIDENING_PRIMITIVE_TYPESback to summary
private static final Class<?>[] WIDENING_PRIMITIVE_TYPES

Array of primitive number types ordered by "promotability" from narrow to wide.

Constructor Detail

MemberUtilsback to summary
pack-priv MemberUtils()

Method Detail

compareConstructorFitback to summary
pack-priv static int compareConstructorFit(final Constructor<?> left, final Constructor<?> right, final 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:Constructor<?>

the "left" Constructor.

right:Constructor<?>

the "right" Constructor.

actual:Class<?>[]

the runtime parameter types to match against. left/right.

Returns:int

int consistent with compare semantics.

compareMethodFitback to summary
pack-priv static int compareMethodFit(final Method left, final Method right, final 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:Method

the "left" Method.

right:Method

the "right" Method.

actual:Class<?>[]

the runtime parameter types to match against. left/right.

Returns:int

int consistent with compare semantics.

compareParameterTypesback to summary
private static int compareParameterTypes(final MemberUtils.Executable left, final MemberUtils.Executable right, final 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:MemberUtils.Executable

the "left" Executable.

right:MemberUtils.Executable

the "right" Executable.

actual:Class<?>[]

the runtime parameter types to match against. left/right.

Returns:int

int consistent with compare semantics.

getObjectTransformationCostback to summary
private static float getObjectTransformationCost(Class<?> srcClass, final Class<?> destClass)

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:Class<?>

The source class.

destClass:Class<?>

The destination class.

Returns:float

The cost of transforming an object.

getPrimitivePromotionCostback to summary
private static float getPrimitivePromotionCost(final Class<?> srcClass, final Class<?> destClass)

Gets the number of steps required to promote a primitive to another type.

Parameters
srcClass:Class<?>

the (primitive) source class.

destClass:Class<?>

the (primitive) destination class.

Returns:float

The cost of promoting the primitive.

getTotalTransformationCostback to summary
private static float getTotalTransformationCost(final Class<?>[] srcArgs, final MemberUtils.Executable executable)

Gets the sum of the object transformation cost for each class in the source argument list.

Parameters
srcArgs:Class<?>[]

The source arguments.

executable:MemberUtils.Executable

The executable to calculate transformation costs for.

Returns:float

The total transformation cost.

isAccessibleback to summary
pack-priv static boolean isAccessible(final Member member)

Tests whether a Member is accessible.

Parameters
member:Member

Member to test, may be null.

Returns:boolean

true if m is accessible.

isMatchingConstructorback to summary
pack-priv static boolean isMatchingConstructor(final Constructor<?> method, final Class<?>[] parameterTypes)
isMatchingExecutableback to summary
private static boolean isMatchingExecutable(final MemberUtils.Executable method, final Class<?>[] parameterTypes)
isMatchingMethodback to summary
pack-priv static boolean isMatchingMethod(final Method method, final Class<?>[] parameterTypes)
isPackageback to summary
pack-priv static boolean isPackage(final int modifiers)

Tests whether a given set of modifiers implies package access.

Parameters
modifiers:int

to test.

Returns:boolean

true unless package/protected/private modifier detected

isPublicback to summary
pack-priv static boolean isPublic(final Member member)

Tests whether a Member is public.

Parameters
member:Member

Member to test, may be null.

Returns:boolean

true if m is public.

isStaticback to summary
pack-priv static boolean isStatic(final Member member)

Tests whether a Member is static.

Parameters
member:Member

Member to test, may be null.

Returns:boolean

true if m is static.

setAccessibleWorkaroundback to summary
pack-priv static <T extends AccessibleObject> T setAccessibleWorkaround(final T obj)

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
obj:T

the AccessibleObject to set as accessible, may be null.

Returns:T

a boolean indicating whether the accessibility of the object was set to true.

org.apache.commons.lang3.reflect back to summary

private final Class MemberUtils.Executable

extends Object
Class Inheritance

A 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

Modifier and TypeField and Description
private final boolean
private final Class<?>[]

Constructor Summary

AccessConstructor and Description
private
Executable(final Constructor<?> constructor)

private
Executable(final Method method)

Method Summary

Modifier and TypeMethod and Description
public Class<?>[]
public boolean
private static MemberUtils.Executable
of(final Constructor<?> constructor)

private static MemberUtils.Executable
of(final Method method)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

isVarArgsback to summary
private final boolean isVarArgs
parameterTypesback to summary
private final Class<?>[] parameterTypes

Constructor Detail

Executableback to summary
private Executable(final Constructor<?> constructor)
Executableback to summary
private Executable(final Method method)

Method Detail

getParameterTypesback to summary
public Class<?>[] getParameterTypes()
isVarArgsback to summary
public boolean isVarArgs()
ofback to summary
private static MemberUtils.Executable of(final Constructor<?> constructor)
ofback to summary
private static MemberUtils.Executable of(final Method method)