Hi All,
I am currently working of a project which involves applying bytecode manipulation via Javassist to a set of annotation-marked methods.
We do so by traversing & loading all relevant classes,
going through all of its methods and use reflection to
examine their annotation list, i.e.:
Class clazz = Class.forName(..);
Method[] methodList = clazz.getMethods();
for each method {
Annotation[] annotationList = method.getAnnotations()
// and look for my own marker annotation here
}
I have recently read a post by Bill Burke which leads
me to believe that there might be a more efficient
way of achieving my task:
"I have to iterate through all classes in the jar to see if they are annotated. I do this through Javassist (so the classes don't have to be loaded. )"
Can I, and how can I, use JavAssist to check class's
annotation list without loading it?
Thanks in advance,
Gilad Haimov
Yes, you can. Please take a look at javassist.bytecode.MethodInfo and javassist.bytecode.AnnotationsAttribute.