public final class ReflectionHelper extends Object
PrivilegedAction
which is necessary
for situations where a security manager is in place.Modifier and Type | Field and Description |
---|---|
static String[] |
PROPERTY_ACCESSOR_PREFIXES |
Modifier and Type | Method and Description |
---|---|
static Class<?> |
boxedType(Class<?> primitiveType)
Returns the auto-boxed type of a primitive type.
|
static Set<Class<?>> |
computeAllImplementedInterfaces(Class<?> clazz)
Get all interfaces a class directly implements.
|
static List<Class<?>> |
computeClassHierarchy(Class<?> clazz,
boolean includeInterfaces)
Get all superclasses and optionally interfaces recursively.
|
static Type |
getIndexedType(Type type)
Determines the type of elements of an
Iterable , array or the value of a Map . |
static Object |
getIndexedValue(Object value,
Integer index)
Tries to retrieve the indexed value from the specified object.
|
static Object |
getMappedValue(Object value,
Object key)
Tries to retrieve the mapped value from the specified object.
|
static String |
getPropertyName(Member member)
Returns the JavaBeans property name of the given member.
|
static Object |
getValue(Member member,
Object object) |
static boolean |
haveSameSignature(Method method1,
Method method2)
Checks, whether the given methods have the same signature, which is the
case if they have the same name, parameter count and types.
|
static boolean |
isGetterMethod(Method method)
Checks whether the given method is a valid JavaBeans getter method,
meaning its name starts with "is" or "has" and it has no parameters.
|
static boolean |
isIterable(Type type) |
static boolean |
isList(Type type) |
static boolean |
isMap(Type type) |
static Type |
typeOf(Member member) |
static Type |
typeOf(Method method,
int parameterIndex)
Returns the type of the parameter of the given method with the given parameter index.
|
public static final String[] PROPERTY_ACCESSOR_PREFIXES
public static String getPropertyName(Member member)
For fields, the field name will be returned. For getter methods, the decapitalized property name will be returned, with the "get", "is" or "has" prefix stripped off. Getter methods are methods
boolean
orboolean
(HV-specific, not mandated by JavaBeans spec).member
- The member for which to get the property name.null
if the
member is neither a field nor a getter method according to the
JavaBeans standard.public static boolean isGetterMethod(Method method)
method
- The method of interest.true
, if the given method is a JavaBeans getter method,
false
otherwise.public static Type typeOf(Member member)
member
- The Member
instance for which to retrieve the type.Type
of the given Field
or Method
.IllegalArgumentException
- in case member
is not a Field
or Method
.public static Type typeOf(Method method, int parameterIndex)
method
- The method of interest.parameterIndex
- The index of the parameter for which the type should be returned.public static Type getIndexedType(Type type)
Iterable
, array or the value of a Map
.type
- the type to inspectIterable
, array or the value of a Map
.
null
is returned in case the type is not indexable (in the context of JSR 303).public static boolean isIterable(Type type)
type
- the type to check.true
if type
is a iterable type, false
otherwise.public static boolean isMap(Type type)
type
- the type to check.true
if type
is implementing Map
, false
otherwise.public static boolean isList(Type type)
type
- the type to check.true
if type
is implementing List
, false
otherwise.public static Object getIndexedValue(Object value, Integer index)
value
- The object from which to retrieve the indexed value. The object has to be non null and
either a collection or array.
index
- The index. The index does not have to be numerical. value
could also be a map in which
case the index could also be a string key.null
if value
is null
or not a collection or array.
null
is also returned in case the index does not exist.public static Object getMappedValue(Object value, Object key)
value
- The object from which to retrieve the mapped value. The object has to be non null
and
must implement the @{code Map} interface.key
- The map key. index.null
if value
is null
or not implementing @{code Map}.public static boolean haveSameSignature(Method method1, Method method2)
method1
- A first method.method2
- A second method.public static Class<?> boxedType(Class<?> primitiveType)
primitiveType
- the primitive typeVoid
is
passed (which is considered as primitive type by
Class.isPrimitive()
), Void
will be returned.IllegalArgumentException
- in case the parameter primitiveType
does not
represent a primitive type.public static List<Class<?>> computeClassHierarchy(Class<?> clazz, boolean includeInterfaces)
clazz
- The class to start the search with.includeInterfaces
- whether or not to include interfacesclazz
. The list contains the class itself! The empty
list is returned if clazz
is null
.public static Set<Class<?>> computeAllImplementedInterfaces(Class<?> clazz)
clazz
- The class for which to find the interfacesclazz
implements. The empty list is returned if clazz
does not
implement any interfaces or clazz
is null
Copyright © 2007-2014 Red Hat Middleware, LLC. All Rights Reserved