Class AnnotationDetectionMethodCallback<A extends Annotation>

java.lang.Object
org.springframework.data.util.AnnotationDetectionMethodCallback<A>
All Implemented Interfaces:
org.springframework.util.ReflectionUtils.MethodCallback

public class AnnotationDetectionMethodCallback<A extends Annotation> extends Object implements org.springframework.util.ReflectionUtils.MethodCallback
ReflectionUtils.MethodCallback to find annotations of a given type.
Author:
Oliver Gierke, Christoph Strobl, Mark Paluch, Johannes Englmeier
  • Constructor Details

    • AnnotationDetectionMethodCallback

      public AnnotationDetectionMethodCallback(Class<A> annotationType)
      Creates a new AnnotationDetectionMethodCallback for the given annotation type.
      Parameters:
      annotationType - must not be null.
    • AnnotationDetectionMethodCallback

      public AnnotationDetectionMethodCallback(Class<A> annotationType, boolean enforceUniqueness)
      Creates a new AnnotationDetectionMethodCallback for the given annotation type.
      Parameters:
      annotationType - must not be null.
      enforceUniqueness - whether to fail if multiple methods with the annotation are found.
  • Method Details

    • getMethod

      @Nullable public Method getMethod()
      Returns:
      the method
    • getRequiredMethod

      public Method getRequiredMethod()
      Returns the method with the configured annotation.
      Returns:
      Throws:
      IllegalStateException - in case no method with the configured annotation was found.
    • getAnnotation

      @Nullable public A getAnnotation()
      Returns:
      the annotation
    • hasFoundAnnotation

      public boolean hasFoundAnnotation()
      Returns whether an annotation was found.
      Returns:
    • doWith

      public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException
      Specified by:
      doWith in interface org.springframework.util.ReflectionUtils.MethodCallback
      Throws:
      IllegalArgumentException
      IllegalAccessException
    • invoke

      @Nullable public <T> T invoke(@Nullable Object target, Object... args)
      Invokes the method using reflection.
      Parameters:
      target - can be null for static method invocations.
      args - method arguments.
      Returns:
      Since:
      2.7