summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-11-29 23:10:29 +0000
committerTom Tromey <tromey@redhat.com>2006-11-29 23:10:29 +0000
commit306a965fe7e642bfb08eeeecfed9bd61ed857db9 (patch)
treedf68f8e910f7c63630f620bdab2e4c05c567d197
parent3be294e0e9f07e379e1499b9868db9855eb8726f (diff)
downloadclasspath-306a965fe7e642bfb08eeeecfed9bd61ed857db9.tar.gz
PR classpath/28203:
* java/lang/Class.java (getAnnotations): Rewrote.
-rw-r--r--ChangeLog5
-rw-r--r--java/lang/Class.java27
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 <tromey@redhat.com>
+
+ PR classpath/28203:
+ * java/lang/Class.java (getAnnotations): Rewrote.
+
2006-11-29 Tania Bento <tbento@redhat.com>
* 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<T>
*/
public Annotation[] getAnnotations()
{
- HashSet<Annotation> set = new HashSet<Annotation>();
- set.addAll(Arrays.asList(getDeclaredAnnotations()));
- Class[] interfaces = getInterfaces();
- for (int i = 0; i < interfaces.length; i++)
- set.addAll(Arrays.asList(interfaces[i].getAnnotations()));
- Class<? super T> superClass = getSuperclass();
- if (superClass != null)
- set.addAll(Arrays.asList(superClass.getAnnotations()));
- return set.toArray(new Annotation[set.size()]);
+ HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
+ for (Annotation a : getDeclaredAnnotations())
+ map.put((Class) a.annotationType(), a);
+ for (Class<? super T> 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<Annotation> v = map.values();
+ return v.toArray(new Annotation[v.size()]);
}
/**