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?

