|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xwiki.component.util.ReflectionUtils
public final class ReflectionUtils
Various Reflection utilities.
| Method Summary | ||
|---|---|---|
static Collection<Field> |
getAllFields(Class<?> clazz)
|
|
static
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Collection<Field> getAllFields(Class<?> clazz)
clazz - the class for which to return all fields
public static Field getField(Class<?> clazz,
String fieldName)
throws NoSuchFieldException
clazz - the class for which to return all fieldsfieldName - the name of the field to get
NoSuchFieldException - if the field doesn't exist in the class or superclassespublic static Class getTypeClass(Type type)
Type.
type - the generic 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 type
public static Type getLastFieldGenericArgument(Field field)
B class.
field - the field from which to extract the generic type
public static Type getLastTypeGenericArgument(Type type)
B class.
type - the type from which to extract the generic type
public static Class<?> getLastGenericClassType(Class clazz,
Class filterClass)
B.
clazz - the class to extract fromfilterClass - the class of the generic type we're looking for
public static Type getGenericClassType(Class clazz,
Class filterClass)
clazz - the class to extract fromfilterClass - the class of the generic type we're looking for
public static Type[] resolveSuperArguments(Type[] parameters,
Type childType)
parameters - the parameters of a direct superclass or interfacechildType - a extending class as Type
public 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 class
public static Type resolveType(Type type,
Map<TypeVariable,Type> typeMapping)
type - the type to resolvetypeMapping - the mapping between TypeVariable and real type
public static Type resolveType(Type targetType,
Type rootType)
targetType - the type for which to resolve the parametersrootType - an extending class as Type
public 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 Type
String
ClassNotFoundException - if no class corresponding to the passed serialized type can be found
public 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 assigned
public static List<Type> getDirectTypes(Type type)
type - the type from which to extract super type and interfaces
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||