Ensure AnnotationUtils is compatible with Java 6
The previous commit introduced a dependency on Class.getDeclaredAnnotation() which is a Java 8 API. This commit refactors AnnotationUtils.findAnnotation(Class, Class, Set) to use Class.getAnnotation() in conjunction with isAnnotationDeclaredLocally() in order to achieve the same desired behavior. Issue: SPR-11475
This commit is contained in:
@@ -278,19 +278,19 @@ public abstract class AnnotationUtils {
|
||||
Set<Annotation> visited) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
|
||||
A annotation = clazz.getDeclaredAnnotation(annotationType);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
if (isAnnotationDeclaredLocally(annotationType, clazz)) {
|
||||
return clazz.getAnnotation(annotationType);
|
||||
}
|
||||
for (Class<?> ifc : clazz.getInterfaces()) {
|
||||
annotation = findAnnotation(ifc, annotationType, visited);
|
||||
A annotation = findAnnotation(ifc, annotationType, visited);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
for (Annotation ann : clazz.getDeclaredAnnotations()) {
|
||||
if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
|
||||
annotation = findAnnotation(ann.annotationType(), annotationType, visited);
|
||||
A annotation = findAnnotation(ann.annotationType(), annotationType,
|
||||
visited);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user