From 306a965fe7e642bfb08eeeecfed9bd61ed857db9 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 29 Nov 2006 23:10:29 +0000 Subject: PR classpath/28203: * java/lang/Class.java (getAnnotations): Rewrote. --- ChangeLog | 5 +++++ java/lang/Class.java | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39ce2d3d8..9d587fd59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-11-29 Tom Tromey + + PR classpath/28203: + * java/lang/Class.java (getAnnotations): Rewrote. + 2006-11-29 Tania Bento * tools/gnu/classpath/tools/appletviewer/TagParser.java: diff --git a/java/lang/Class.java b/java/lang/Class.java index ad51044c3..a159898c0 100644 --- a/java/lang/Class.java +++ b/java/lang/Class.java @@ -44,6 +44,7 @@ import gnu.java.lang.reflect.ClassSignatureParser; import java.io.InputStream; import java.io.Serializable; import java.lang.annotation.Annotation; +import java.lang.annotation.Inherited; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -62,6 +63,7 @@ import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -1505,15 +1507,22 @@ public final class Class */ public Annotation[] getAnnotations() { - HashSet set = new HashSet(); - set.addAll(Arrays.asList(getDeclaredAnnotations())); - Class[] interfaces = getInterfaces(); - for (int i = 0; i < interfaces.length; i++) - set.addAll(Arrays.asList(interfaces[i].getAnnotations())); - Class superClass = getSuperclass(); - if (superClass != null) - set.addAll(Arrays.asList(superClass.getAnnotations())); - return set.toArray(new Annotation[set.size()]); + HashMap map = new HashMap(); + for (Annotation a : getDeclaredAnnotations()) + map.put((Class) a.annotationType(), a); + for (Class s = getSuperclass(); + s != null; + s = s.getSuperclass()) + { + for (Annotation a : s.getDeclaredAnnotations()) + { + Class k = (Class) a.annotationType(); + if (! map.containsKey(k) && k.isAnnotationPresent(Inherited.class)) + map.put(k, a); + } + } + Collection v = map.values(); + return v.toArray(new Annotation[v.size()]); } /** -- cgit v1.2.1