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 Class<?> |
getClassFromType(Type type)
Converts the given
Type to a Class. |
static Type |
getCollectionElementType(Type type)
Determines the type of the 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(Field field,
Object object) |
static Object |
getValue(Member member,
Object object) |
static Object |
getValue(Method method,
Object object) |
static boolean |
isCollection(Type type)
Indicates whether the given type represents a collection of elements or not (i.e.
|
static boolean |
isGetterMethod(Method method)
Checks whether the given method 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(Type type)
Indicates if the type is considered indexable (ie is a
List, an array or a Map). |
static boolean |
isIterable(Type type) |
static boolean |
isList(Type type) |
static boolean |
isMap(Type type) |
static Type |
typeOf(ExecutableElement executable,
int parameterIndex)
Returns the type of the parameter of the given method with the given parameter index.
|
static Type |
typeOf(Member member) |
static Class<?> |
unBoxedType(Class<?> type)
Returns the primitive type for a boxed type.
|
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)
boolean orboolean (HV-specific, not mandated by JavaBeans spec).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(ExecutableElement executable, int parameterIndex)
executable - The executable of interest.parameterIndex - The index of the parameter for which the type should be returned.public static boolean isCollection(Type type)
Iterable, Map or array type).public static Type getCollectionElementType(Type type)
Iterable, array or the value of a Map.public static boolean isIndexable(Type type)
List, an array or a Map).
Note that it does not include Sets as they are not indexable.
type - the type to inspect.public static Class<?> getClassFromType(Type type)
Type to a Class.type - the type to convertpublic 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 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 Class<?> unBoxedType(Class<?> type)
type - the boxed 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.Copyright © 2018 JBoss by Red Hat. All rights reserved.