Class ReflectionUtil

java.lang.Object
org.eclipse.epsilon.eol.util.ReflectionUtil

public class ReflectionUtil extends Object
  • Method Details

    • hasMethods

      public static boolean hasMethods(Object obj, String methodName)
    • getMethodNames

      public static Set<String> getMethodNames(Object obj, boolean includeInheritedMethods)
    • getMethodName

      protected static String getMethodName(Method method)
    • 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

      public static Class<?>[] discoverPublicClasses(Class<?> clazz)
      Parameters:
      clazz -
      Returns:
      Since:
      1.6
    • getMethodsFromPublicClassesForName

      public static Method[] getMethodsFromPublicClassesForName(Object obj, String methodName)
      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

      public 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+
      Parameters:
      obj -
      method -
      Returns:
      Since:
      1.6
    • methodToString

      public static String methodToString(Method method)
      Returns a string representation of the method
      Parameters:
      method -
      Returns:
    • getFieldValue

      public static Object getFieldValue(Object object, String fieldName)
      Returns the value of a field of an object
      Parameters:
      object -
      fieldName -
      Returns:
    • getField

      public static Field getField(Class<?> clazz, String fieldName)
      Gets a field of a class using reflection by introspecting the class and its supertype(s)
      Parameters:
      clazz -
      fieldName -
      Returns:
    • isInstance

      public 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
      Parameters:
      clazz -
      instance -
      Returns:
    • getAllInheritedInstanceFields

      public static List<Field> getAllInheritedInstanceFields(Class<?> klazz)