Package org.eclipse.epsilon.eol.util
Class ReflectionUtil
java.lang.Object
org.eclipse.epsilon.eol.util.ReflectionUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>[]discoverPublicClasses(Class<?> clazz) static ObjectexecuteMethod(Object obj, Method method, ModuleElement ast, Object... parameters) static ObjectexecuteMethod(Object obj, String methodName, Object... parameters) static MethodfindApplicableMethodOrThrow(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.getAllInheritedInstanceFields(Class<?> klazz) static FieldGets a field of a class using reflection by introspecting the class and its supertype(s)static ObjectgetFieldValue(Object object, String fieldName) Returns the value of a field of an objectstatic MethodgetLegalMethod(Object obj, Method method) This tries to find a method such that invoking via reflection won't be illegal in Java 9+static MethodgetMethodFor(Object obj, String methodName, Object[] parameters, boolean includeInheritedMethods, boolean allowContravariantConversionForParameters) protected static StringgetMethodName(Method method) getMethodNames(Object obj, boolean includeInheritedMethods) static Method[]getMethodsFromPublicClassesForName(Object obj, String methodName) static booleanhasMethods(Object obj, String methodName) static booleanisInstance(Class<?> clazz, Object instance) Checks if the instance is an instance of clazz Necessary because in Java, int.class != Integer.class etcstatic StringmethodToString(Method method) Returns a string representation of the method
-
Method Details
-
hasMethods
-
getMethodNames
-
getMethodName
-
findApplicableMethodOrThrow
public static Method findApplicableMethodOrThrow(Object obj, String methodName, Predicate<Method> criteria, Collection<?> parameters, ModuleElement ast, PrettyPrinterManager ppm) throws EolIllegalOperationException, EolIllegalOperationParametersException Searches for a method matching the name and criteria for the given object, including all super methods and super-interfaces recursively.- Parameters:
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.- Returns:
- A method (chosen non-deterministically) which matches the criteria.
- Throws:
EolIllegalOperationException- If no method matching the criteria can be found.EolIllegalOperationParametersException- If the method parameters are invalid.- Since:
- 1.6
-
discoverPublicClasses
- Parameters:
clazz-- Returns:
- Since:
- 1.6
-
getMethodsFromPublicClassesForName
- Parameters:
obj-methodName-- Returns:
- Since:
- 1.6
-
getMethodFor
public static Method getMethodFor(Object obj, String methodName, Object[] parameters, boolean includeInheritedMethods, boolean allowContravariantConversionForParameters) - Parameters:
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 method
-
executeMethod
public static Object executeMethod(Object obj, String methodName, Object... parameters) throws Throwable - Throws:
Throwable
-
executeMethod
public static Object executeMethod(Object obj, Method method, ModuleElement ast, Object... parameters) throws EolRuntimeException - Throws:
EolRuntimeException
-
getLegalMethod
This tries to find a method such that invoking via reflection won't be illegal in Java 9+- Parameters:
obj-method-- Returns:
- Since:
- 1.6
-
methodToString
Returns a string representation of the method- Parameters:
method-- Returns:
-
getFieldValue
Returns the value of a field of an object- Parameters:
object-fieldName-- Returns:
-
getField
Gets a field of a class using reflection by introspecting the class and its supertype(s)- Parameters:
clazz-fieldName-- Returns:
-
isInstance
Checks if the instance is an instance of clazz Necessary because in Java, int.class != Integer.class etc- Parameters:
clazz-instance-- Returns:
-
getAllInheritedInstanceFields
-