Class ELMethods

java.lang.Object
io.micronaut.el.runtime.ELMethods

@Internal public final class ELMethods extends Object
Selects the method a method expression refers to, as described in the section 1.6 of the Jakarta Expression Language specification.

When the parameter types are provided at parse time they select the method on their own. Otherwise the evaluated arguments are used: an exact match is preferred over an assignable one, an assignable one over a coercible one, and a method with a fixed arity over a variable arity method. A tie makes the reference ambiguous, which is an error.

Since:
1.0
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
    • 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