public class ReflectUtil extends Object
Constructor and Description |
---|
ReflectUtil() |
Modifier and Type | Method and Description |
---|---|
static Class<?> |
boxType(Class<?> type)
Obtain the boxed type of any incoming type.
|
static Set<Field> |
getAllDeclaredFields(Class<?> objectClass)
Obtain all the declared fields of the given
objectClass with a
deep scan inside super classes and interfaces. |
protected static void |
getAllDeclaredFields(Class<?> objectClass,
Set<Class<?>> visitedClasses,
Set<Field> result) |
static Set<Method> |
getAllDeclaredMethods(Class<?> objectClass)
Obtain all the declared methods of the given
objectClass with a
deep scan inside super classes and interfaces. |
protected static void |
getAllDeclaredMethods(Class<?> objectClass,
Set<Class<?>> visitedClasses,
Set<Method> result) |
static <T> T |
getConstant(Class<?> klass,
String fieldName) |
static <T> List<T> |
getConstants(Class<?> klass,
Class<T> searchingClass)
Recherche dans une classe donnée
klazz , les constantes d'un
certain type searchingClass et les retourne. |
static Method |
getDeclaredMethod(Class<?> klass,
String methodName,
boolean strict,
Object... arguments)
Cherche une methode selon son nom et ses paramètres d'invocation.
|
protected static Method |
getDeclaredMethod(Class<?> klass,
String methodName,
Set<Class<?>> visitedClasses,
Object... arguments) |
static <T extends Enum<T>> |
getEnumClass(Class<?> type)
Convertit une classe non typée, en une classe d'enum
|
static <A extends Annotation> |
getFieldAnnotation(Class<?> objectClass,
Class<A> annotationClass)
Obtain all the fields with the given annotation type.
|
static <A extends Annotation> |
getFieldAnnotation(Class<?> objectClass,
Class<A> annotationClass,
boolean deepVisit)
Obtain all the fields with the given annotation type.
|
protected static <A extends Annotation> |
getFieldAnnotation(Class<?> objectClass,
Class<A> annotationClass,
boolean deepVisit,
Set<Class<?>> visitedClasses,
Map<Field,A> result) |
static <A extends Annotation> |
getMethodAnnotation(Class<?> objectClass,
Class<A> annotationClass)
Obtain all the methods with the given annotation type.
|
static <A extends Annotation> |
getMethodAnnotation(Class<?> objectClass,
Class<A> annotationClass,
boolean deepVisit)
Obtain all the methods with the given annotation type.
|
protected static <A extends Annotation> |
getMethodAnnotation(Class<?> objectClass,
Class<A> annotationClass,
boolean deepVisit,
Set<Class<?>> visitedClasses,
Map<Method,A> result) |
static boolean |
isConstantField(Field field)
Pour déterminer si un champ d'une classe est une constante
(modifiers sont static, final et public)
|
static Class<?> |
unboxType(Class<?> type)
Obtain the unboxed type of any incoming type.
|
public static boolean isConstantField(Field field)
field
- le champs à testertrue
si les modifiers sont final, static et publicpublic static <T> List<T> getConstants(Class<?> klass, Class<T> searchingClass)
klazz
, les constantes d'un
certain type searchingClass
et les retourne.
L'algorithme parcourt aussi les superclasses.T
- enumeration's typeklass
- la classe contenant les constantessearchingClass
- le type des champs constants à récupérerRuntimeException
- si problème lors de la récupérationpublic static <T> T getConstant(Class<?> klass, String fieldName)
T
- enumeration's typeklass
- the required classfieldName
- the required constant namepublic static <T extends Enum<T>> Class<T> getEnumClass(Class<?> type) throws IllegalArgumentException
T
- enumeration's typetype
- la classe a typerIllegalArgumentException
- si le type est null ou non une extension
de la classe Enum.public static Method getDeclaredMethod(Class<?> klass, String methodName, boolean strict, Object... arguments) throws IllegalArgumentException
klass
- la classe dans laquelle rechercher la méthodemethodName
- le nom de la méthode recherchéestrict
- un drapeau pour déclancher une exception si la méthode
n'est pas trouvéearguments
- les arguments d'invocation de la méthodeIllegalArgumentException
- si la méthode n'est pas trouvée et que
le drapeau strict
est à true
public static Class<?> boxType(Class<?> type)
type
- the type to boxClass.isPrimitive()
public static Class<?> unboxType(Class<?> type)
type
- the type to unboxClass.isPrimitive()
public static Set<Field> getAllDeclaredFields(Class<?> objectClass)
objectClass
with a
deep scan inside super classes and interfaces.
Note: The type Object
will not be scanned.objectClass
- the object class to scanpublic static Set<Method> getAllDeclaredMethods(Class<?> objectClass)
objectClass
with a
deep scan inside super classes and interfaces.
Note: The type Object
will not be scanned.objectClass
- the object class to scanpublic static <A extends Annotation> Map<Field,A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass)
A
- type of annotation to scanobjectClass
- the type to scanannotationClass
- the type of annotation to scanpublic static <A extends Annotation> Map<Field,A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit)
deepVisit
is setted to true
.
Note: The type Object
will not be scanned.A
- type of annotation to scanobjectClass
- the type to scanannotationClass
- the type of annotation to scandeepVisit
- flag to visit deeply the class (if set to
true
, will also scan super classes
and interfaces)public static <A extends Annotation> Map<Method,A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass)
A
- type of annotation to scanobjectClass
- the type to scanannotationClass
- the type of annotation to scanpublic static <A extends Annotation> Map<Method,A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit)
deepVisit
is setted to true
.
Note: The type Object
will not be scanned.A
- type of annotation to scanobjectClass
- the type to scanannotationClass
- the type of annotation to scandeepVisit
- flag to visit deeply the class (if set to
true
, will also scan super classes
and interfaces)protected static Method getDeclaredMethod(Class<?> klass, String methodName, Set<Class<?>> visitedClasses, Object... arguments)
protected static void getAllDeclaredFields(Class<?> objectClass, Set<Class<?>> visitedClasses, Set<Field> result)
protected static void getAllDeclaredMethods(Class<?> objectClass, Set<Class<?>> visitedClasses, Set<Method> result)
protected static <A extends Annotation> void getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit, Set<Class<?>> visitedClasses, Map<Field,A> result)
Copyright © 2004–2020 CodeLutin. All rights reserved.