Find out all usages of an annotation at runtime

Is there any way to find out all usages of an annotation at runtime? Hypothetically, something like Annotation.getDeclaringElements()

which would return AnnotatedElements to which the specific annotation has been applied?

JSR 269 is out of question, as I need this at runtime (correct me, if my requirement does not imply my claim here). Think of a framework which needs to discover all uses of its own annotations in an arbitrary target environment. In addition, classes loaded at arbitrary points in runtime should be detectable if the discovery is made afterwards.

Performance is not critical: enumerating all classes of all ClassLoaders and checking each class and its members would do. Is there a way to enumerate all classes for this purpose?

Is there any way to hack around any/all limitations, using whatever non-elegant, ugly ways to achieve this?

[888 byte] By [Irfya] at [2007-11-27 5:03:39]
# 1

hey. I don't know if there is anything like that out of the box, but might use bytecode instrumentation/analysis with the -javaagent-switch. It will give you the chance to analyse everyclass that is getting loaded into the JVM. Look here for more info: http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html

I think the catch with the classloader is, that you never know if another class will be loaded in future.

joh

riejoa at 2007-7-12 10:21:45 > top of Java-index,Core,Core APIs...