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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A method the selection of the section 1.6 can choose between, with what the selection needs read once.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object[]
    coerceArguments(jakarta.el.ELContext context, String name, Class<?>[] parameterTypes, boolean varArgs, Object @Nullable [] values)
    Prepares the arguments of a call for the declared parameters, as described in the section 1.23 of the specification: every argument is coerced to its parameter type, and the arguments a variable arity parameter takes are packed into an array of its component type.
    static jakarta.el.MethodNotFoundException
    notFound(Class<?> type, String name, int count)
    The failure reported when a type declares no method of the given name and arity.
    static boolean
    sameTypes(Class<?>[] declared, Class<?>[] provided)
    Compares parameter types, treating a primitive and its wrapper as the same type.
    static <T> T
    select(Class<?> type, String name, List<ELMethods.Candidate<T>> candidates, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments, boolean isStatic)
    Selects the method the section 1.6 of the specification prefers among the candidates of a name.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • coerceArguments

      public static Object[] coerceArguments(jakarta.el.ELContext context, String name, Class<?>[] parameterTypes, boolean varArgs, Object @Nullable [] values)
      Prepares the arguments of a call for the declared parameters, as described in the section 1.23 of the specification: every argument is coerced to its parameter type, and the arguments a variable arity parameter takes are packed into an array of its component type.

      An array already of the parameter type is passed through as the variable arity array itself, rather than becoming its single element. This is the one implementation of that rule, so a caller that dispatches directly prepares its arguments exactly as the reflective invocation does.

      Parameters:
      context - The context
      name - The name of the method, for the error message
      parameterTypes - The declared parameter types
      varArgs - Whether the last parameter is of variable arity
      values - The evaluated arguments, can be null
      Returns:
      The arguments to pass, one per declared parameter
      Throws:
      IllegalArgumentException - when the number of arguments does not fit the parameters
    • select

      public static <T> T select(Class<?> type, String name, List<ELMethods.Candidate<T>> candidates, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments, boolean isStatic)
      Selects the method the section 1.6 of the specification prefers among the candidates of a name.

      This is the one implementation of the selection rules: a caller that dispatches directly, without reflection, describes its methods as candidates and gets the selected one back.

      Type Parameters:
      T - The type of the method the candidates stand for
      Parameters:
      type - The type of the base object, or the class declaring a static method
      name - The name of the method, for the error messages
      candidates - The methods of that name
      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 selected method
      Throws:
      jakarta.el.MethodNotFoundException - when no candidate accepts the arguments, or several are equally specific
    • notFound

      public static jakarta.el.MethodNotFoundException notFound(Class<?> type, String name, int count)
      The failure reported when a type declares no method of the given name and arity.
      Parameters:
      type - The type declaring the method
      name - The name of the method
      count - The number of arguments
      Returns:
      The failure
    • sameTypes

      public static boolean sameTypes(Class<?>[] declared, Class<?>[] provided)
      Compares parameter types, treating a primitive and its wrapper as the same type.
      Parameters:
      declared - The declared parameter types
      provided - The parameter types to match
      Returns:
      Whether every declared type matches its provided counterpart