Class ReflectiveELMethods
java.lang.Object
io.micronaut.el.interpreter.reflection.ReflectiveELMethods
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 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 MethodfindStaticMethod(Class<?> type, String name, Class<?> @Nullable [] paramTypes, Object @Nullable [] arguments) Finds the static method a method expression refers to.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
-
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 methodname- 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
-