public final class ReflectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Collection<Field> |
getAllFields(Class<?> clazz) |
static <T extends Annotation> |
getDirectAnnotation(Class<T> annotationClass,
AnnotatedElement element)
Get the first found annotation with the provided class directly assigned to the provided
AnnotatedElement
. |
static List<Type> |
getDirectTypes(Type type) |
static Field |
getField(Class<?> clazz,
String fieldName) |
static Type |
getGenericClassType(Class clazz,
Class filterClass)
Extract the real Type from the passed class.
|
static Type |
getLastFieldGenericArgument(Field field)
Extract the last generic type from the passed field.
|
static Class<?> |
getLastGenericClassType(Class clazz,
Class filterClass)
Extract the last generic type from the passed class.
|
static Class<?> |
getLastGenericFieldType(Field field)
Extract the last generic type from the passed field.
|
static Type |
getLastTypeGenericArgument(Type type)
Extract the last generic type from the passed Type.
|
static Class |
getTypeClass(Type type)
Extract the main class from the passed
Type. |
static Type[] |
resolveSuperArguments(Type[] parameters,
Class childClass,
Type[] childParameters) |
static Type[] |
resolveSuperArguments(Type[] parameters,
Type childType) |
static Type |
resolveType(Type type,
Map<TypeVariable,Type> typeMapping) |
static Type |
resolveType(Type targetType,
Type rootType)
Find and replace the generic parameters with the real types.
|
static void |
setFieldValue(Object instanceContainingField,
String fieldName,
Object fieldValue)
Sets a value to a field using reflection even if the field is private.
|
static Type |
unserializeType(String serializedType,
ClassLoader classLoader)
Retrieve a
Type object from it's serialized form. |
public static Collection<Field> getAllFields(Class<?> clazz)
clazz - the class for which to return all fieldspublic static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException
clazz - the class for which to return all fieldsfieldName - the name of the field to getNoSuchFieldException - if the field doesn't exist in the class or superclassespublic static Class getTypeClass(Type type)
Type.public static void setFieldValue(Object instanceContainingField, String fieldName, Object fieldValue)
instanceContainingField - the object containing the fieldfieldName - the name of the field in the objectfieldValue - the value to set for the provided fieldpublic static Class<?> getLastGenericFieldType(Field field)
B class.field - the field from which to extract the generic typepublic static Type getLastFieldGenericArgument(Field field)
B class.field - the field from which to extract the generic typepublic static Type getLastTypeGenericArgument(Type type)
B class.type - the type from which to extract the generic typepublic static Class<?> getLastGenericClassType(Class clazz, Class filterClass)
B.clazz - the class to extract fromfilterClass - the class of the generic type we're looking forpublic static Type getGenericClassType(Class clazz, Class filterClass)
clazz - the class to extract fromfilterClass - the class of the generic type we're looking forpublic static Type[] resolveSuperArguments(Type[] parameters, Type childType)
parameters - the parameters of a direct superclass or interfacechildType - a extending class as Typepublic static Type[] resolveSuperArguments(Type[] parameters, Class childClass, Type[] childParameters)
parameters - the parameters of a direct superclass or interfacechildClass - an extending classchildParameters - the actual parameters of the extending classpublic static Type resolveType(Type type, Map<TypeVariable,Type> typeMapping)
type - the type to resolvetypeMapping - the mapping between TypeVariable and real typepublic static Type resolveType(Type targetType, Type rootType)
targetType - the type for which to resolve the parametersrootType - an extending class as Typepublic static Type unserializeType(String serializedType, ClassLoader classLoader) throws ClassNotFoundException
Type object from it's serialized form.serializedType - the serialized form of the Type to retrieveclassLoader - the ClassLoader to look into to find the given TypeStringClassNotFoundException - if no class corresponding to the passed serialized type can be foundpublic static <T extends Annotation> T getDirectAnnotation(Class<T> annotationClass, AnnotatedElement element)
AnnotatedElement
.T - the type of the annotationannotationClass - the annotation classelement - the class on which annotation are assignedCopyright © 2004–2014 XWiki. All rights reserved.