Top Description Fields Constructors Methods
org.springframework.expression.spel.support

public Class ReflectiveMethodResolver

extends Object
implements MethodResolver
Class Inheritance
All Implemented Interfaces
org.springframework.expression.MethodResolver
Known Direct Subclasses
org.springframework.expression.spel.support.DataBindingMethodResolver
Imports
java.lang.reflect.Method, .Modifier, .Proxy, java.util.ArrayList, .Collections, .HashMap, .LinkedHashSet, .List, .Map, .Set, org.springframework.core.BridgeMethodResolver, .MethodParameter, org.springframework.core.convert.TypeDescriptor, org.springframework.expression.AccessException, .EvaluationContext, .EvaluationException, .MethodExecutor, .MethodFilter, .MethodResolver, .TypeConverter, org.springframework.expression.spel.SpelEvaluationException, .SpelMessage, org.springframework.lang.Nullable

Reflection-based MethodResolver used by default in StandardEvaluationContext unless explicit method resolvers have been specified.
Authors
Andy Clement, Juergen Hoeller, Chris Beams, Sam Brannen
Since
3.0
See Also
StandardEvaluationContext#addMethodResolver(MethodResolver)

Field Summary

Modifier and TypeField and Description
private Map<Class<?>, MethodFilter>
private final boolean

Constructor Summary

AccessConstructor and Description
public
public
ReflectiveMethodResolver(boolean
true if distance computation should be used when calculating matches; false otherwise
useDistance
)

This constructor allows the ReflectiveMethodResolver to be configured such that it will use a distance computation to check which is the better of two close matches (when there are multiple matches).

Method Summary

Modifier and TypeMethod and Description
private Set<Method>
getMethods(Class<?> type, Object targetObject)

protected Method[]
getMethods(Class<?>
the class for which to return the methods
type
)

Return the set of methods for this type.

protected boolean
isCandidateForInvocation(Method
the Method to evaluate
method
,
Class<?>
the concrete target class that is being introspected
targetClass
)

Determine whether the given Method is a candidate for method resolution on an instance of the given target class.

public void
registerMethodFilter(Class<?>
the type to filter on
type
,
MethodFilter
the corresponding method filter, or null to clear any filter for the given type
filter
)

Register a filter for methods on the given type.

public MethodExecutor
resolve(EvaluationContext
the current evaluation context
context
,
Object
the object upon which the method is being called
targetObject
,
String
the name of the method
name
,
List<TypeDescriptor>
the types of arguments that the method must be able to handle
argumentTypes
)

Implements org.springframework.expression.MethodResolver.resolve.

Locate a method on the type.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filtersback to summary
private Map<Class<?>, MethodFilter> filters
Annotations
@Nullable
useDistanceback to summary
private final boolean useDistance

Constructor Detail

ReflectiveMethodResolverback to summary
public ReflectiveMethodResolver()
ReflectiveMethodResolverback to summary
public ReflectiveMethodResolver(boolean useDistance)

This constructor allows the ReflectiveMethodResolver to be configured such that it will use a distance computation to check which is the better of two close matches (when there are multiple matches). Using the distance computation is intended to ensure matches are more closely representative of what a Java compiler would do when taking into account boxing/unboxing and whether the method candidates are declared to handle a supertype of the type (of the argument) being passed in.

Parameters
useDistance:boolean

true if distance computation should be used when calculating matches; false otherwise

Method Detail

getMethodsback to summary
private Set<Method> getMethods(Class<?> type, Object targetObject)
getMethodsback to summary
protected Method[] getMethods(Class<?> type)

Return the set of methods for this type. The default implementation returns the result of Class#getMethods() for the given type, but subclasses may override in order to alter the results, e.g. specifying static methods declared elsewhere.

Parameters
type:Class<?>

the class for which to return the methods

Since
3.1.1
isCandidateForInvocationback to summary
protected boolean isCandidateForInvocation(Method method, Class<?> targetClass)

Determine whether the given Method is a candidate for method resolution on an instance of the given target class.

The default implementation considers any method as a candidate, even for static methods and non-user-declared methods on the Object base class.

Parameters
method:Method

the Method to evaluate

targetClass:Class<?>

the concrete target class that is being introspected

Since
4.3.15
registerMethodFilterback to summary
public void registerMethodFilter(Class<?> type, MethodFilter filter)

Register a filter for methods on the given type.

Parameters
type:Class<?>

the type to filter on

filter:MethodFilter

the corresponding method filter, or null to clear any filter for the given type

resolveback to summary
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException

Implements org.springframework.expression.MethodResolver.resolve.

Locate a method on the type.

There are three kinds of matches that might occur:

  1. An exact match where the types of the arguments match the types of the method.
  2. An inexact match where the types we are looking for are subtypes of those defined on the method.
  3. A match where we are able to convert the arguments into those expected by the method, according to the registered type converter.
Parameters
context:EvaluationContext

Doc from org.springframework.expression.MethodResolver.resolve.

the current evaluation context

targetObject:Object

Doc from org.springframework.expression.MethodResolver.resolve.

the object upon which the method is being called

name:String

Doc from org.springframework.expression.MethodResolver.resolve.

the name of the method

argumentTypes:List<TypeDescriptor>

Doc from org.springframework.expression.MethodResolver.resolve.

the types of arguments that the method must be able to handle

Returns:MethodExecutor

Doc from org.springframework.expression.MethodResolver.resolve.

a MethodExecutor that can invoke the method, or null if the method cannot be found

Annotations
@Override
@Nullable