Class ReflectiveELMethods

java.lang.Object
io.micronaut.el.interpreter.reflection.ReflectiveELMethods

@Internal public final class ReflectiveELMethods extends Object
Finds and invokes a java.lang.reflect.Method, which is the selection of the section 1.6 of the specification applied to what a class reports about itself.

This is the reflective half of ELMethods, which stayed in the core module with the parts that need no reflection: the overload selection, the coercions and the metadata a registry of contributed methods describes for itself. A runtime without this module resolves a method through the executors it was given and never reads a class to find one.

Since:
1.1
Author:
Denis Stepanov
  • Method Details

    • findMethodOrNull

      public static @Nullable Method findMethodOrNull(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments, boolean isStatic)
      Finds a method by name and arguments, as findMethod(Class, String, Class[], Object[]) does, or returns null when the type declares no public method of the name.
      Parameters:
      type - The type of the base object, or the class for a static method
      name - The name of the method
      paramTypes - The parameter types provided at parse time, can be null
      arguments - The evaluated arguments, can be null
      isStatic - Whether to look for a static method
      Returns:
      The method, or null when the type declares no method of the name
    • invoke

      public static @Nullable Object invoke(jakarta.el.ELContext context, Method method, @Nullable Object base, Object @Nullable [] values)
      Invokes a method reflectively, the arguments coerced to the parameter types as described in the section 1.23 of the specification, the variable arity arguments packed into an array, the exceptions of the method unwrapped.
      Parameters:
      context - The context
      method - The method
      base - The base object, or null for a static method
      values - The arguments
      Returns:
      The result of the invocation
    • findMethod

      public static Method findMethod(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments)
      Finds the method a method expression refers to.
      Parameters:
      type - The type of the base object
      name - The name of the method
      paramTypes - The parameter types provided at parse time, can be null
      arguments - The evaluated arguments, can be null
      Returns:
      The method
    • findStaticMethod

      public static Method findStaticMethod(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments)
      Finds the static method a method expression refers to.
      Parameters:
      type - The type declaring the method
      name - The name of the method
      paramTypes - The parameter types provided at parse time, can be null
      arguments - The evaluated arguments, can be null
      Returns:
      The method
    • accessible

      public static Method accessible(Method method)
      Returns a declaration of the method that can be invoked reflectively.

      Class.getMethods() returns the method as declared on the runtime class, which may not be accessible: the lists of List.of, the views of Collections and lambdas all implement public interfaces from classes that are not public. The public declaration is found on a supertype, which is what jakarta.el.ELUtil does for the standard resolvers.

      Parameters:
      method - The method as declared on the runtime class
      Returns:
      An accessible declaration of the same method