findAnnotation

@Nullable
open fun <A : Annotation?> findAnnotation(clazz: Class<out Any>, @Nullable annotationType: @Nullable Class<A>): @Nullable A

Find a single Annotation of annotationType on the supplied Class, traversing its interfaces, annotations, and superclasses if the annotation is not directly present on the given class itself.

This method explicitly handles class-level annotations which are not declared as inheritedas well as meta-annotations and annotations on interfaces.

The algorithm operates as follows:

  1. Search for the annotation on the given class and return it if found.
  2. Recursively search through all interfaces that the given class declares.
  3. Recursively search through the superclass hierarchy of the given class.

Note: in this context, the term recursively means that the search process continues by returning to step #1 with the current interface, annotation, or superclass as the class to look for annotations on.

Return

the first matching annotation, or null if not found

Parameters

clazz

the class to look for annotations on

annotationType

the type of annotation to look for


@Nullable
open fun <A : Annotation?> findAnnotation(method: Method, @Nullable annotationType: @Nullable Class<A>): @Nullable A

Find a single Annotation of annotationType on the supplied Method, traversing its super methods if the annotation is not directly present on the given method itself.

Annotations on methods are not inherited by default, so we need to handle this explicitly.

Return

the first matching annotation, or null if not found

Parameters

method

the method to look for annotations on

annotationType

the type of annotation to look for