Class ELMethods
java.lang.Object
io.micronaut.el.runtime.ELMethods
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 Summary
Modifier and TypeMethodDescriptionstatic Methodaccessible(Method method) Returns a declaration of the method that can be invoked reflectively.static MethodfindMethod(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments) Finds the method a method expression refers to.static @Nullable MethodfindMethodOrNull(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments, boolean isStatic) Finds a method by name and arguments, asfindMethod(Class, String, Class[], Object[])does, or returnsnullwhen the type declares no public method of the name.static @Nullable Objectinvoke(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.
-
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, asfindMethod(Class, String, Class[], Object[])does, or returnsnullwhen the type declares no public method of the name.- Parameters:
type- The type of the base object, or the class for a static methodname- The name of the methodparamTypes- The parameter types provided at parse time, can benullarguments- The evaluated arguments, can benullisStatic- Whether to look for a static method- Returns:
- The method, or
nullwhen 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 contextmethod- The methodbase- The base object, ornullfor a static methodvalues- 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 objectname- The name of the methodparamTypes- The parameter types provided at parse time, can benullarguments- The evaluated arguments, can benull- Returns:
- The method
-
accessible
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 ofList.of, the views ofCollectionsand lambdas all implement public interfaces from classes that are not public. The public declaration is found on a supertype, which is whatjakarta.el.ELUtildoes for the standard resolvers.- Parameters:
method- The method as declared on the runtime class- Returns:
- An accessible declaration of the same method
-