in safeguard-impl/src/main/java/org/apache/safeguard/impl/annotation/AnnotationFinder.java [46:78]
public <T extends Annotation> T findAnnotation(final Class<T> type, final AnnotatedType<?> declaringClass,
final Method method) {
final Set<AnnotatedMethod<?>> methods = (Set<AnnotatedMethod<?>>) declaringClass.getMethods();
// first test on the class method directly
final Optional<AnnotatedMethod<?>> classMethod = getDirectMethod(declaringClass, method, methods);
if (classMethod.isPresent()) {
final T methodAnnotation = getMethodAnnotation(type, classMethod);
if (methodAnnotation != null) {
return methodAnnotation;
}
} else { // then on the parent methods
final Optional<AnnotatedMethod<?>> parentMethod = getParentMethod(declaringClass, method, methods);
final T annotation = getMethodAnnotation(type, parentMethod);
if (annotation != null) {
return annotation;
}
}
{ // then on the class
final T annotation = getFromDirectClass(type, declaringClass);
if (annotation != null) {
return annotation;
}
}
{ // then on the parent class
final T annotation = getFromParentClass(type, declaringClass);
if (annotation != null) {
return annotation;
}
}
// just a fallback, we should never end up here
return getByReflection(type, declaringClass, method);
}