Class ReflectUtil
java.lang.Object
org.nuiton.util.ReflectUtil
Introspection sur une classe. Détermine si un attribut est constant,
recherche de constantes d'un type donné, conversion d'une classe en
Enum...
Created: 30 décembre 2007
- Author:
- Tony Chemit - chemit@codelutin.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> Obtain the boxed type of any incoming type.getAllDeclaredFields(Class<?> objectClass) Obtain all the declared fields of the givenobjectClasswith a deep scan inside super classes and interfaces.protected static voidgetAllDeclaredMethods(Class<?> objectClass) Obtain all the declared methods of the givenobjectClasswith a deep scan inside super classes and interfaces.protected static voidstatic <T> TgetConstant(Class<?> klass, String fieldName) static <T> List<T> getConstants(Class<?> klass, Class<T> searchingClass) Recherche dans une classe donnéeklazz, les constantes d'un certain typesearchingClasset les retourne.static MethodgetDeclaredMethod(Class<?> klass, String methodName, boolean strict, Object... arguments) Cherche une methode selon son nom et ses paramètres d'invocation.protected static MethodgetDeclaredMethod(Class<?> klass, String methodName, Set<Class<?>> visitedClasses, Object... arguments) getEnumClass(Class<?> type) Convertit une classe non typée, en une classe d'enumstatic <A extends Annotation>
Map<Field, A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass) Obtain all the fields with the given annotation type.static <A extends Annotation>
Map<Field, A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit) Obtain all the fields with the given annotation type.protected static <A extends Annotation>
voidgetFieldAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit, Set<Class<?>> visitedClasses, Map<Field, A> result) static <A extends Annotation>
Map<Method, A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass) Obtain all the methods with the given annotation type.static <A extends Annotation>
Map<Method, A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit) Obtain all the methods with the given annotation type.protected static <A extends Annotation>
voidgetMethodAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit, Set<Class<?>> visitedClasses, Map<Method, A> result) static booleanisConstantField(Field field) Pour déterminer si un champ d'une classe est une constante (modifiers sont static, final et public)static Class<?> Obtain the unboxed type of any incoming type.
-
Constructor Details
-
ReflectUtil
public ReflectUtil()
-
-
Method Details
-
isConstantField
Pour déterminer si un champ d'une classe est une constante (modifiers sont static, final et public)- Parameters:
field- le champs à tester- Returns:
truesi les modifiers sont final, static et public
-
getConstants
Recherche dans une classe donnéeklazz, les constantes d'un certain typesearchingClasset les retourne. L'algorithme parcourt aussi les superclasses.- Type Parameters:
T- enumeration's type- Parameters:
klass- la classe contenant les constantessearchingClass- le type des champs constants à récupérer- Returns:
- la liste des champs du type requis dans
- Throws:
RuntimeException- si problème lors de la récupération
-
getConstant
-
getEnumClass
public static <T extends Enum<T>> Class<T> getEnumClass(Class<?> type) throws IllegalArgumentException Convertit une classe non typée, en une classe d'enum- Type Parameters:
T- enumeration's type- Parameters:
type- la classe a typer- Returns:
- la classe typee
- Throws:
IllegalArgumentException- si le type est null ou non une extension de la classe Enum.
-
getDeclaredMethod
public static Method getDeclaredMethod(Class<?> klass, String methodName, boolean strict, Object... arguments) throws IllegalArgumentException Cherche une methode selon son nom et ses paramètres d'invocation.- Parameters:
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éthode- Returns:
- la méthode trouvée
- Throws:
IllegalArgumentException- si la méthode n'est pas trouvée et que le drapeaustrictest àtrue- Since:
- 1.3.1
-
boxType
-
unboxType
-
getAllDeclaredFields
Obtain all the declared fields of the givenobjectClasswith a deep scan inside super classes and interfaces. Note: The typeObjectwill not be scanned.- Parameters:
objectClass- the object class to scan- Returns:
- the set of all declared fields found
- Since:
- 2.0
-
getAllDeclaredMethods
Obtain all the declared methods of the givenobjectClasswith a deep scan inside super classes and interfaces. Note: The typeObjectwill not be scanned.- Parameters:
objectClass- the object class to scan- Returns:
- the set of all declared methods found
- Since:
- 2.0
-
getFieldAnnotation
public static <A extends Annotation> Map<Field,A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass) Obtain all the fields with the given annotation type. Note: This method will not scan deeply the given type (no scan of super-classes nor interfaces).- Type Parameters:
A- type of annotation to scan- Parameters:
objectClass- the type to scanannotationClass- the type of annotation to scan- Returns:
- the dictionnary of fields with the given annotation
- Since:
- 2.0
-
getFieldAnnotation
public static <A extends Annotation> Map<Field,A> getFieldAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit) Obtain all the fields with the given annotation type. Note: This method will scan deeply the given type if parameterdeepVisitis setted totrue. Note: The typeObjectwill not be scanned.- Type Parameters:
A- type of annotation to scan- Parameters:
objectClass- the type to scanannotationClass- the type of annotation to scandeepVisit- flag to visit deeply the class (if set totrue, will also scan super classes and interfaces)- Returns:
- the dictionnary of fields with the given annotation
- Since:
- 2.0
-
getMethodAnnotation
public static <A extends Annotation> Map<Method,A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass) Obtain all the methods with the given annotation type. Note: This method will not scan deeply the given type (no scan of super-classes nor interfaces).- Type Parameters:
A- type of annotation to scan- Parameters:
objectClass- the type to scanannotationClass- the type of annotation to scan- Returns:
- the dictionnary of methods with the given annotation
- Since:
- 2.0
-
getMethodAnnotation
public static <A extends Annotation> Map<Method,A> getMethodAnnotation(Class<?> objectClass, Class<A> annotationClass, boolean deepVisit) Obtain all the methods with the given annotation type. Note: This method will scan deeply the given type if parameterdeepVisitis setted totrue. Note: The typeObjectwill not be scanned.- Type Parameters:
A- type of annotation to scan- Parameters:
objectClass- the type to scanannotationClass- the type of annotation to scandeepVisit- flag to visit deeply the class (if set totrue, will also scan super classes and interfaces)- Returns:
- the dictionnary of methods with the given annotation
- Since:
- 2.0
-
getDeclaredMethod
-
getAllDeclaredFields
-
getAllDeclaredMethods
-
getFieldAnnotation
-
getMethodAnnotation
-