public final class ReflectionHelper
extends java.lang.Object
PrivilegedAction
which is necessary
for situations where a security manager is in place.Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
PROPERTY_ACCESSOR_PREFIXES |
Modifier and Type | Method and Description |
---|---|
static java.lang.Class<?> |
boxedType(java.lang.Class<?> type)
Returns the corresponding auto-boxed type if given a primitive type.
|
static java.lang.reflect.Type |
boxedType(java.lang.reflect.Type type)
Returns the corresponding auto-boxed type if given a primitive type.
|
static java.lang.Class<?> |
getClassFromType(java.lang.reflect.Type type)
Converts the given
Type to a Class . |
static java.lang.reflect.Type |
getCollectionElementType(java.lang.reflect.Type type)
Determines the type of the elements of an
Iterable , array or the value of a Map . |
static java.lang.Object |
getIndexedValue(java.lang.Object value,
int index)
Tries to retrieve the indexed value from the specified object.
|
static java.lang.Object |
getMappedValue(java.lang.Object value,
java.lang.Object key)
Tries to retrieve the mapped value from the specified object.
|
static java.lang.String |
getPropertyName(java.lang.reflect.Member member)
Returns the JavaBeans property name of the given member.
|
static java.lang.Object |
getValue(java.lang.reflect.Field field,
java.lang.Object object) |
static java.lang.Object |
getValue(java.lang.reflect.Method method,
java.lang.Object object) |
static boolean |
isCollection(java.lang.reflect.Type type)
Indicates whether the given type represents a collection of elements or not (i.e.
|
static boolean |
isGetterMethod(java.lang.reflect.Executable executable)
Checks whether the given executable is a valid JavaBeans getter method, which
is the case if
its name starts with "get" and it has a return type but no parameter or
its name starts with "is", it has no parameter and is returning
boolean or
its name starts with "has", it has no parameter and is returning
boolean (HV-specific, not mandated by JavaBeans spec).
|
static boolean |
isIndexable(java.lang.reflect.Type type)
Indicates if the type is considered indexable (ie is a
List , an array or a Map ). |
static boolean |
isIterable(java.lang.reflect.Type type) |
static boolean |
isList(java.lang.reflect.Type type) |
static boolean |
isMap(java.lang.reflect.Type type) |
static java.lang.reflect.Type |
typeOf(java.lang.reflect.Executable executable,
int parameterIndex)
Returns the type of the parameter of the given method with the given parameter index.
|
static java.lang.reflect.Type |
typeOf(java.lang.reflect.Member member) |
static java.lang.Class<?> |
unBoxedType(java.lang.Class<?> type)
Returns the primitive type for a boxed type.
|
public static final java.lang.String[] PROPERTY_ACCESSOR_PREFIXES
public static java.lang.String getPropertyName(java.lang.reflect.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(java.lang.reflect.Executable executable)
boolean
orboolean
(HV-specific, not mandated by JavaBeans spec).executable
- The executable of interest.true
, if the given executable is a JavaBeans getter method,
false
otherwise.public static java.lang.reflect.Type typeOf(java.lang.reflect.Member member)
member
- The Member
instance for which to retrieve the type.Type
of the given Field
or Method
.java.lang.IllegalArgumentException
- in case member
is not a Field
or Method
.public static java.lang.reflect.Type typeOf(java.lang.reflect.Executable executable, int parameterIndex)
executable
- The executable of interest.parameterIndex
- The index of the parameter for which the type should be returned.public static java.lang.Object getValue(java.lang.reflect.Field field, java.lang.Object object)
public static java.lang.Object getValue(java.lang.reflect.Method method, java.lang.Object object)
public static boolean isCollection(java.lang.reflect.Type type)
Iterable
, Map
or array type).public static java.lang.reflect.Type getCollectionElementType(java.lang.reflect.Type type)
Iterable
, array or the value of a Map
.public static boolean isIndexable(java.lang.reflect.Type type)
List
, an array or a Map
).
Note that it does not include Set
s as they are not indexable.
type
- the type to inspect.public static java.lang.Class<?> getClassFromType(java.lang.reflect.Type type)
Type
to a Class
.type
- the type to convertpublic static boolean isIterable(java.lang.reflect.Type type)
type
- the type to check.true
if type
is a iterable type, false
otherwise.public static boolean isMap(java.lang.reflect.Type type)
type
- the type to check.true
if type
is implementing Map
, false
otherwise.public static boolean isList(java.lang.reflect.Type type)
type
- the type to check.true
if type
is implementing List
, false
otherwise.public static java.lang.Object getIndexedValue(java.lang.Object value, int 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.null
if value
is null
or not a collection or array.
null
is also returned in case the index does not exist.public static java.lang.Object getMappedValue(java.lang.Object value, java.lang.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 java.lang.reflect.Type boxedType(java.lang.reflect.Type type)
public static java.lang.Class<?> boxedType(java.lang.Class<?> type)
public static java.lang.Class<?> unBoxedType(java.lang.Class<?> type)
type
- the boxed typeVoid
is
passed (which is considered as primitive type by
Class.isPrimitive()
), Void
will be returned.java.lang.IllegalArgumentException
- in case the parameter primitiveType
does not
represent a primitive type.Copyright © 2007-2022 Red Hat, Inc. All Rights Reserved