Package caseine.reflect
Class ReflectUtilities
java.lang.Object
caseine.reflect.ReflectUtilities
Classe utilitaires offrant de nombreuses méthodes introspectives utiles
- Author:
- Yvan Maillot <yvan.maillot@uha.fr>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic Objectstatic Objectstatic booleanEgalité de deux objets non nécessairement de mêmes types.static Object[]static <T> Tstatic <T> Tstatic ObjectgetAttribut(Class<?> c, Object o, String nom) static Class<?>getDeclaredClass(Class<?> c, String name) static ObjectgetFromMethod(Class<?> c, Object o, String methodName, Object... pv) Retourne par introspection le résultat de l'invocation d'une méthode avec ses arguments.static ObjectgetFromMethod(String className, Object o, String methodName, Object... pv) static ObjectgetFromMethodTA(Class<?> c, Object o, String methodName, Object... pv) Retourne par introspection le résultat de l'invocation d'une méthode avec ses arguments.static ObjectgetFromMethodTA(String className, Object o, String methodName, Object... pv) static StringRetourne dans une chaine de caractères le résultat à l'écran de l'invocation d'une méthode avec ses arguments.static StringgetFromMethodTASystemOut(Class<?> c, Object o, String methodName, Object... pv) Retourne dans une chaine de caractères le résultat à l'écran de l'invocation d'une méthode avec ses arguments.static Constructor<?>getOneConstructor(Class<?> c) static Constructor<?>getOneSimpleConstructor(Class<?> c) Retourne le premier constructeur contenant que des paramètres simples.static <T> Tstatic <T> Tstatic booleanisCheckedException(Class<?> crt) Retourne vrai l'objet de classe donné en paramètre est une exception contrôlée, faux si c'est une exception non contrôlée.static booleanisCheckedException(Throwable cause) static booleanstatic Stringstatic Stringstatic Class<?>static intrandomInt(int min, int max) static intrandomInt(int min, int max, boolean notNul) static ObjectrandomValue(Class<?> c) static ObjectrandomValue(Class<?> c, Class<?>... p) static ObjectrandomValue(Class<?> c, Object... p) static booleansameResult(boolean checkStdOut, StringBuilder msg, Class<?> c1, Class<?> c2, String methodName, Class<?>... parameterTypes) static booleansameResult(StringBuilder msg, Class<?> c1, Class<?> c2, String methodName, Class<?>... parameterTypes) static voidsetAttribut(Class<?> c, Object o, String nom, Object v) Met à jour la valeur d'un attribut d'un object donnéstatic StringwritePreviousUnitTestCalling(TreeMap<String, StringBuilder> msb, String[] priorities)
-
Constructor Details
-
ReflectUtilities
public ReflectUtilities()
-
-
Method Details
-
getTA
public static <T> T getTA(Class<T> c, Object... pv) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
getTA
public static <T> T getTA(String className, Object... pv) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
get
public static <T> T get(Class<T> c, Object... pv) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
get
public static <T> T get(String className, Object... pv) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException -
getFromMethodTA
public static Object getFromMethodTA(Class<?> c, Object o, String methodName, Object... pv) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException Retourne par introspection le résultat de l'invocation d'une méthode avec ses arguments.- Parameters:
c- la classe à laquelle la méthode appartient.o- l'objet sur lequel s'application la méthode (peut-être null dans le cas d'une méthode static)methodName- le nom de la méthodepv- une liste de couples (type et sa valeur)- Returns:
- le résultat de l'invocation
- Throws:
NoSuchMethodException- la méthode n'existe pasIllegalAccessException- accès interditIllegalArgumentException- les types arguments de ne correspondent pasInvocationTargetException- l'invocation de la méthode a engendré une exception
-
getFromMethodTA
public static Object getFromMethodTA(String className, Object o, String methodName, Object... pv) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
getFromMethod
public static Object getFromMethod(Class<?> c, Object o, String methodName, Object... pv) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException Retourne par introspection le résultat de l'invocation d'une méthode avec ses arguments.- Parameters:
c- la classe à laquelle la méthode appartiento- l'objet sur lequel s'application la méthodemethodName- le nom de la méthodepv- une liste de valeurs (dont les types sont déduits)- Returns:
- le résultat de l'invocation
- Throws:
NoSuchMethodExceptionIllegalAccessExceptionIllegalArgumentExceptionInvocationTargetException
-
getFromMethod
public static Object getFromMethod(String className, Object o, String methodName, Object... pv) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException -
getFromMethodTASystemOut
public static String getFromMethodTASystemOut(Class<?> c, Object o, String methodName, Object... pv) throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException Retourne dans une chaine de caractères le résultat à l'écran de l'invocation d'une méthode avec ses arguments.- Parameters:
c- la classe à laquelle la méthode appartiento- l'objet sur lequel s'application la méthodemethodName- le nom de la méthodepv- une liste de couples (type et sa valeur)- Returns:
- le résultat de l'invocation
- Throws:
FileNotFoundExceptionIOExceptionNoSuchMethodExceptionIllegalAccessExceptionInvocationTargetException
-
getFromMethodTASystemInOut
public static String getFromMethodTASystemInOut(Class<?> c, Object o, String methodName, String sin, Object... pv) throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException Retourne dans une chaine de caractères le résultat à l'écran de l'invocation d'une méthode avec ses arguments.- Parameters:
c- la classe à laquelle la méthode appartiento- l'objet sur lequel s'application la méthodemethodName- le nom de la méthodesin- String à envoyer dans l'entrée standardpv- une liste de couples (type et sa valeur)- Returns:
- le résultat de l'invocation
- Throws:
FileNotFoundExceptionIOExceptionNoSuchMethodExceptionIllegalAccessExceptionInvocationTargetException
-
setAttribut
public static void setAttribut(Class<?> c, Object o, String nom, Object v) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException Met à jour la valeur d'un attribut d'un object donné- Parameters:
c- l'objet de classe de l'objet donnéo- l'objet donnénom- le nom de l'attributv- la valeur à affecter à cet attribut- Throws:
NoSuchFieldExceptionIllegalArgumentExceptionIllegalAccessException
-
getAttribut
public static Object getAttribut(Class<?> c, Object o, String nom) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException -
isMutable
-
clone
public static Object clone(Object o1, Class<?> c2) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException -
clone
public static Object clone(Object o) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException -
equals
public static boolean equals(Object o1, Object o2) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException Egalité de deux objets non nécessairement de mêmes types.Deux objets o1 et o2 sont considérés égaux (au sens défini ICI) si
- ils sont des wrappers de type simple ET o1.equals(o2)
- OU ils sont de même type ET ils redéfissent Object::equals(Object) ET o1.equals(o2)
- OU
- leur type ont le même nom (simple)
- ET leurs attributs non statique ont les mêmes noms et sont égaux entre eux (au sens défini ICI)
- Parameters:
o1- à comparer avec o2o2- à comparer avec o1- Returns:
- vrai si o1 est égal à o2 au sens défini ICI
- Throws:
InstantiationException- problèmeIllegalAccessException- problèmeIllegalArgumentException- problèmeInvocationTargetException- problèmeNoSuchMethodException- problème
-
allParametersArePrimitive
-
getOneConstructor
-
getOneSimpleConstructor
Retourne le premier constructeur contenant que des paramètres simples. Les constructeurs publiques sont cherchés en premier Si le constructeur retourné est non-public, alors il est rendu accessible.- Parameters:
c- le type de classe dont on veut un constructeur- Returns:
- un constructeur
- Throws:
NoSimpleConstructor- aucun constructeur trouvé
-
fillParametersArray
public static Object[] fillParametersArray(Executable k) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException -
randomInt
public static int randomInt(int min, int max, boolean notNul) -
randomInt
public static int randomInt(int min, int max) -
randomValue
public static Object randomValue(Class<?> c, Object... p) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
randomValue
public static Object randomValue(Class<?> c, Class<?>... p) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
randomValue
public static Object randomValue(Class<?> c) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException -
isCheckedException
Retourne vrai l'objet de classe donné en paramètre est une exception contrôlée, faux si c'est une exception non contrôlée.- Parameters:
crt- l'exception dont on veut connaître la nature- Returns:
- vrai si crt est une exception contrôlée, faux si crt est une exception non contrôlée
- Throws:
IllegalArgumentException- si crt n'est pas une exception
-
isCheckedException
-
sameResult
public static boolean sameResult(StringBuilder msg, Class<?> c1, Class<?> c2, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException -
sameResult
public static boolean sameResult(boolean checkStdOut, StringBuilder msg, Class<?> c1, Class<?> c2, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException -
parseType
- Throws:
ClassNotFoundException
-
getDeclaredClass
-
paramsToStringClass
-
paramsToString
-
writePreviousUnitTestCalling
public static String writePreviousUnitTestCalling(TreeMap<String, StringBuilder> msb, String[] priorities)
-