org.springframework.core

Class MethodIntrospector

  • java.lang.Object
    • org.springframework.core.MethodIntrospector


  • public final class MethodIntrospector
    extends java.lang.Object
    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.

    Since:
    4.2.3
    Author:
    Juergen Hoeller, Rossen Stoyanchev
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static interface  MethodIntrospector.MetadataLookup<T>
      A callback interface for metadata lookup on a given method.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.reflect.Method selectInvocableMethod(java.lang.reflect.Method method, java.lang.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.
      static <T> java.util.Map<java.lang.reflect.Method,T> selectMethods(java.lang.Class<?> targetType, MethodIntrospector.MetadataLookup<T> metadataLookup)
      Select methods on the given target type based on the lookup of associated metadata.
      static java.util.Set<java.lang.reflect.Method> selectMethods(java.lang.Class<?> targetType, ReflectionUtils.MethodFilter methodFilter)
      Select methods on the given target type based on a filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • selectMethods

        public static <T> java.util.Map<java.lang.reflect.Method,T> selectMethods(java.lang.Class<?> targetType,
                                                                                  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 MethodIntrospector.MetadataLookup parameter, allowing to collect the associated metadata into the result map.

        Parameters:
        targetType - the target type to search methods on
        metadataLookup - a MethodIntrospector.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:
        the selected methods associated with their metadata (in the order of retrieval), or an empty map in case of no match
      • selectMethods

        public static java.util.Set<java.lang.reflect.Method> selectMethods(java.lang.Class<?> targetType,
                                                                            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 - the target type to search methods on
        methodFilter - a MethodFilter to help recognize handler methods of interest
        Returns:
        the selected methods, or an empty set in case of no match
      • selectInvocableMethod

        public static java.lang.reflect.Method selectInvocableMethod(java.lang.reflect.Method method,
                                                                     java.lang.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 - the method to check
        targetType - the target type to search methods on (typically an interface-based JDK proxy)
        Returns:
        a corresponding invocable method on the target type
        Throws:
        java.lang.IllegalStateException - if the given method is not invocable on the given target type (typically due to a proxy mismatch)