Class ELMethods
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 ClassesModifier and TypeClassDescriptionstatic final recordA method the selection of the section 1.6 can choose between, with what the selection needs read once. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.MethodNotFoundExceptionThe failure reported when a type declares no method of the given name and arity.static booleanCompares parameter types, treating a primitive and its wrapper as the same type.static <T> Tselect(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.
-
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 contextname- The name of the method, for the error messageparameterTypes- The declared parameter typesvarArgs- Whether the last parameter is of variable arityvalues- The evaluated arguments, can benull- 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
candidatesand 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 methodname- The name of the method, for the error messagescandidates- The methods of that nameparamTypes- The parameter types provided at parse time, can benullarguments- The evaluated arguments, can benullisStatic- 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
The failure reported when a type declares no method of the given name and arity.- Parameters:
type- The type declaring the methodname- The name of the methodcount- The number of arguments- Returns:
- The failure
-
sameTypes
Compares parameter types, treating a primitive and its wrapper as the same type.- Parameters:
declared- The declared parameter typesprovided- The parameter types to match- Returns:
- Whether every declared type matches its provided counterpart
-