public class ReflectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?>[] |
discoverPublicClasses(Class<?> clazz) |
static Object |
executeMethod(Object obj,
Method method,
ModuleElement ast,
Object... parameters) |
static Object |
executeMethod(Object obj,
String methodName,
Object... parameters) |
static Method |
findApplicableMethodOrThrow(Object obj,
String methodName,
Predicate<Method> criteria,
Collection<?> parameters,
ModuleElement ast,
PrettyPrinterManager ppm)
Searches for a method matching the name and criteria for the given object,
including all super methods and super-interfaces recursively.
|
static List<Field> |
getAllInheritedInstanceFields(Class<?> klazz) |
static Field |
getField(Class<?> clazz,
String fieldName)
Gets a field of a class using reflection
by introspecting the class and its supertype(s)
|
static Object |
getFieldValue(Object object,
String fieldName)
Returns the value of a field of an object
|
static Method |
getLegalMethod(Object obj,
Method method)
This tries to find a method such that invoking via reflection won't be illegal in Java 9+
|
static Method |
getMethodFor(Object obj,
String methodName,
Object[] parameters,
boolean includeInheritedMethods,
boolean allowContravariantConversionForParameters) |
protected static String |
getMethodName(Method method) |
static Set<String> |
getMethodNames(Object obj,
boolean includeInheritedMethods) |
static Method[] |
getMethodsFromPublicClassesForName(Object obj,
String methodName) |
static boolean |
hasMethods(Object obj,
String methodName) |
static boolean |
isInstance(Class<?> clazz,
Object instance)
Checks if the instance is an instance of clazz
Necessary because in Java, int.class != Integer.class etc
|
static String |
methodToString(Method method)
Returns a string representation
of the method
|
public static Set<String> getMethodNames(Object obj, boolean includeInheritedMethods)
public static Method findApplicableMethodOrThrow(Object obj, String methodName, Predicate<Method> criteria, Collection<?> parameters, ModuleElement ast, PrettyPrinterManager ppm) throws EolIllegalOperationException, EolIllegalOperationParametersException
obj
- The target object to look for methods on.methodName
- The name of the method to find.criteria
- Function which limits the search scope of methods.EolIllegalOperationException
- If no method matching the criteria can be found.EolIllegalOperationParametersException
- If the method parameters are invalid.public static Class<?>[] discoverPublicClasses(Class<?> clazz)
clazz
- public static Method[] getMethodsFromPublicClassesForName(Object obj, String methodName)
obj
- methodName
- public static Method getMethodFor(Object obj, String methodName, Object[] parameters, boolean includeInheritedMethods, boolean allowContravariantConversionForParameters)
allowContravariantConversionForParameters
- when false, parameters will have exactly the same class as the arguments to the returned method
when true, parameters may have a type that is more specific than the arguments to the returned methodpublic static Object executeMethod(Object obj, String methodName, Object... parameters) throws Throwable
Throwable
public static Object executeMethod(Object obj, Method method, ModuleElement ast, Object... parameters) throws EolRuntimeException
EolRuntimeException
public static Method getLegalMethod(Object obj, Method method)
obj
- method
- public static String methodToString(Method method)
method
- public static Object getFieldValue(Object object, String fieldName)
object
- fieldName
- public static Field getField(Class<?> clazz, String fieldName)
clazz
- fieldName
- public static boolean isInstance(Class<?> clazz, Object instance)
clazz
- instance
- Copyright © 2020. All rights reserved.