aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/sun/reflect
diff options
context:
space:
mode:
authoralundblad <none@none>2013-10-24 18:52:13 +0200
committeralundblad <none@none>2013-10-24 18:52:13 +0200
commita5c599521b747c0b431f039bf7829df27953fff5 (patch)
tree0b90b2242b60461b2e71e765eb25df7a3703d2b6 /src/share/classes/sun/reflect
parent51072b226d77d2017b5feb0d8384654856d419d8 (diff)
8027170: Annotations declared on super-super-class should be overridden by super-class.
Reviewed-by: jfranck Contributed-by: andreas.lundblad@oracle.com, peter.levart@gmail.com
Diffstat (limited to 'src/share/classes/sun/reflect')
-rw-r--r--src/share/classes/sun/reflect/annotation/AnnotationSupport.java54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/share/classes/sun/reflect/annotation/AnnotationSupport.java b/src/share/classes/sun/reflect/annotation/AnnotationSupport.java
index 4bb33d649..604e19574 100644
--- a/src/share/classes/sun/reflect/annotation/AnnotationSupport.java
+++ b/src/share/classes/sun/reflect/annotation/AnnotationSupport.java
@@ -32,8 +32,12 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
+
+import sun.misc.JavaLangAccess;
public final class AnnotationSupport {
+ private static final JavaLangAccess LANG_ACCESS = sun.misc.SharedSecrets.getJavaLangAccess();
/**
* Finds and returns all annotations in {@code annotations} matching
@@ -51,17 +55,13 @@ public final class AnnotationSupport {
*
* @param annotations the {@code Map} in which to search for annotations
* @param annoClass the type of annotation to search for
- * @param includeNonInheritedContainees if false, the annoClass must be
- * inheritable for the containers to be searched
*
* @return an array of instances of {@code annoClass} or an empty
* array if none were found
*/
- private static <A extends Annotation> A[] getDirectlyAndIndirectlyPresent(
+ public static <A extends Annotation> A[] getDirectlyAndIndirectlyPresent(
Map<Class<? extends Annotation>, Annotation> annotations,
- Class<A> annoClass,
- boolean includeNonInheritedContainees) {
-
+ Class<A> annoClass) {
List<A> result = new ArrayList<A>();
@SuppressWarnings("unchecked")
@@ -69,17 +69,12 @@ public final class AnnotationSupport {
if (direct != null)
result.add(direct);
- if (includeNonInheritedContainees ||
- AnnotationType.getInstance(annoClass).isInherited()) {
- A[] indirect = getIndirectlyPresent(annotations, annoClass);
-
- if (indirect != null) {
+ A[] indirect = getIndirectlyPresent(annotations, annoClass);
+ if (indirect != null && indirect.length != 0) {
+ boolean indirectFirst = direct == null ||
+ containerBeforeContainee(annotations, annoClass);
- boolean indirectFirst = direct == null ||
- containerBeforeContainee(annotations, annoClass);
-
- result.addAll((indirectFirst ? 0 : 1), Arrays.asList(indirect));
- }
+ result.addAll((indirectFirst ? 0 : 1), Arrays.asList(indirect));
}
@SuppressWarnings("unchecked")
@@ -87,19 +82,6 @@ public final class AnnotationSupport {
return result.toArray(arr);
}
-
- /**
- * Equivalent to calling {@code getDirectlyAndIndirectlyPresentAnnotations(
- * annotations, annoClass, true)}.
- */
- public static <A extends Annotation> A[] getDirectlyAndIndirectlyPresent(
- Map<Class<? extends Annotation>, Annotation> annotations,
- Class<A> annoClass) {
-
- return getDirectlyAndIndirectlyPresent(annotations, annoClass, true);
- }
-
-
/**
* Finds and returns all annotations matching the given {@code annoClass}
* indirectly present in {@code annotations}.
@@ -166,22 +148,28 @@ public final class AnnotationSupport {
* annotations in the relevant map.
*
* @param declaredAnnotations the declared annotations indexed by their types
- * @param allAnnotations declared and inherited annotations indexed by their types
+ * @param decl the class declaration on which to search for annotations
* @param annoClass the type of annotation to search for
*
* @return an array of instances of {@code annoClass} or an empty array if none were found.
*/
public static <A extends Annotation> A[] getAssociatedAnnotations(
Map<Class<? extends Annotation>, Annotation> declaredAnnotations,
- Map<Class<? extends Annotation>, Annotation> allAnnotations,
+ Class<?> decl,
Class<A> annoClass) {
+ Objects.requireNonNull(decl);
// Search declared
A[] result = getDirectlyAndIndirectlyPresent(declaredAnnotations, annoClass);
// Search inherited
- if (result.length == 0)
- result = getDirectlyAndIndirectlyPresent(allAnnotations, annoClass, false);
+ if(AnnotationType.getInstance(annoClass).isInherited()) {
+ Class<?> superDecl = decl.getSuperclass();
+ while (result.length == 0 && superDecl != null) {
+ result = getDirectlyAndIndirectlyPresent(LANG_ACCESS.getDeclaredAnnotationMap(superDecl), annoClass);
+ superDecl = superDecl.getSuperclass();
+ }
+ }
return result;
}