org.nuiton.util
Class ReflectUtil

java.lang.Object
  extended by org.nuiton.util.ReflectUtil

public class ReflectUtil
extends Object

Des méthodes utiles d'introspection

Author:
tchemit

Constructor Summary
ReflectUtil()
           
 
Method Summary
static Class<?> boxType(Class<?> type)
          Obtain the boxed type of any incoming type.
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>>
Class<T>
getEnumClass(Class<?> type)
          Convertit une classe non typée, en une classe d'enum
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectUtil

public ReflectUtil()
Method Detail

isConstantField

public static boolean isConstantField(Field field)
Pour déterminer si un champ d'une classe est une constante (modifiers sont static, final et public)

Parameters:
field - le champs à tester
Returns:
true si les modifiers sont final, static et public

getConstants

public 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.

L'algorithme parcourt aussi les superclasses.

Type Parameters:
T - enumeration's type
Parameters:
klass - la classe contenant les constantes
searchingClass - 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

public static <T> T getConstant(Class<?> klass,
                                String fieldName)
Type Parameters:
T - enumeration's type
Parameters:
klass - the required class
fieldName - the required constant name
Returns:
the constant value

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éthode
methodName - le nom de la méthode recherchée
strict - un drapeau pour déclancher une exception si la méthode n'est pas trouvée
arguments - 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 drapeau strict est à true
Since:
1.3.1

boxType

public static Class<?> boxType(Class<?> type)
Obtain the boxed type of any incoming type.

If incoming type is not a primitive type, then just returns himself.

Parameters:
type - the type to box
Returns:
the boxed type
Since:
1.3.1
See Also:
Class.isPrimitive()

unboxType

public static Class<?> unboxType(Class<?> type)
Obtain the unboxed type of any incoming type.

If incoming type is a primitive type, then just returns himself.

Parameters:
type - the type to unbox
Returns:
the unboxed type
Since:
1.3.1
See Also:
Class.isPrimitive()

getDeclaredMethod

protected static Method getDeclaredMethod(Class<?> klass,
                                          String methodName,
                                          Set<Class<?>> visitedClasses,
                                          Object... arguments)


Copyright © 2004-2010 CodeLutin. All Rights Reserved.