Top Description Inners Constructors Methods
org.springframework.core

public final Class MethodIntrospector

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, .Proxy, java.util.LinkedHashMap, .LinkedHashSet, .Map, .Set, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ReflectionUtils

Defines the algorithm for searching for metadata-associated methods exhaustively including interfaces and parent classes while also dealing with parameterized methods as well as common scenarios encountered with interface and class-based proxies.

Typically, but not necessarily, used for finding annotated handler methods.

Authors
Juergen Hoeller, Rossen Stoyanchev
Since
4.2.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
MethodIntrospector.MetadataLookup<
the type of metadata returned
T
>

A callback interface for metadata lookup on a given method.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Method

Returns:

a corresponding invocable method on the target type
selectInvocableMethod
(Method
the method to check
method
,
Class<?>
the target type to search methods on (typically an interface-based JDK proxy)
targetType
)

Select an invocable method on the target type: either the given method itself if actually exposed on the target type, or otherwise a corresponding method on one of the target type's interfaces or on the target type itself.

public static <T> Map<Method, T>

Returns:

the selected methods associated with their metadata (in the order of retrieval), or an empty map in case of no match
selectMethods
(Class<?>
the target type to search methods on
targetType
,
final MethodIntrospector.MetadataLookup<T>
a MetadataLookup callback to inspect methods of interest, returning non-null metadata to be associated with a given method if there is a match, or null for no match
metadataLookup
)

Select methods on the given target type based on the lookup of associated metadata.

public static Set<Method>

Returns:

the selected methods, or an empty set in case of no match
selectMethods
(Class<?>
the target type to search methods on
targetType
,
final ReflectionUtils.MethodFilter
a MethodFilter to help recognize handler methods of interest
methodFilter
)

Select methods on the given target type based on a filter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MethodIntrospectorback to summary
private MethodIntrospector()

Method Detail

selectInvocableMethodback to summary
public static Method selectInvocableMethod(Method method, Class<?> targetType)

Select an invocable method on the target type: either the given method itself if actually exposed on the target type, or otherwise a corresponding method on one of the target type's interfaces or on the target type itself.

Matches on user-declared interfaces will be preferred since they are likely to contain relevant metadata that corresponds to the method on the target class.

Parameters
method:Method

the method to check

targetType:Class<?>

the target type to search methods on (typically an interface-based JDK proxy)

Returns:Method

a corresponding invocable method on the target type

Exceptions
IllegalStateException:
if the given method is not invocable on the given target type (typically due to a proxy mismatch)
selectMethodsback to summary
public static <T> Map<Method, T> selectMethods(Class<?> targetType, final MethodIntrospector.MetadataLookup<T> metadataLookup)

Select methods on the given target type based on the lookup of associated metadata.

Callers define methods of interest through the MetadataLookup parameter, allowing to collect the associated metadata into the result map.

Parameters
targetType:Class<?>

the target type to search methods on

metadataLookup:MethodIntrospector.MetadataLookup<T>

a MetadataLookup callback to inspect methods of interest, returning non-null metadata to be associated with a given method if there is a match, or null for no match

Returns:Map<Method, T>

the selected methods associated with their metadata (in the order of retrieval), or an empty map in case of no match

selectMethodsback to summary
public static Set<Method> selectMethods(Class<?> targetType, final ReflectionUtils.MethodFilter methodFilter)

Select methods on the given target type based on a filter.

Callers define methods of interest through the MethodFilter parameter.

Parameters
targetType:Class<?>

the target type to search methods on

methodFilter:ReflectionUtils.MethodFilter

a MethodFilter to help recognize handler methods of interest

Returns:Set<Method>

the selected methods, or an empty set in case of no match

org.springframework.core back to summary

public Interface MethodIntrospector.MetadataLookup<T>

Annotations
@FunctionalInterface
Type Parameters
<T>
the type of metadata returned

A callback interface for metadata lookup on a given method.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

non-null metadata to be associated with a method if there is a match, or null for no match
inspect
(Method
the method to inspect
method
)

Perform a lookup on the given method and return associated metadata, if any.

Method Detail

inspectback to summary
public T inspect(Method method)

Perform a lookup on the given method and return associated metadata, if any.

Parameters
method:Method

the method to inspect

Returns:T

non-null metadata to be associated with a method if there is a match, or null for no match

Annotations
@Nullable