Browse Source

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
pull/471/head
Sam Brannen 11 years ago
parent
commit
0637864b39
  1. 10
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

10
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -278,19 +278,19 @@ public abstract class AnnotationUtils { @@ -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;
}

Loading…
Cancel
Save