AnnotationFinder extends ClassVisitor { public Set<Method> getAnnotatedMethods() { return annotatedMethods; } AnnotationFinder(ClassLoader classLoader, Collection<Class<? extends Annotation>> annotations); @Override void visit(int version, int access, String name, String signature, String superName, String[] interfaces); @Override AnnotationVisitor visitAnnotation(String desc, boolean visible); @Override FieldVisitor visitField(int access, String name, String desc, String signature, Object value); @Override MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions); Set<Class<?>> getAnnotatedClasses(); Set<Method> getAnnotatedMethods(); Set<Constructor> getAnnotatedConstructors(); Set<Field> getAnnotatedFields();  }
@Test public void testFindAnnotationsOnMethods() { cp.compile( "package governator.test;" + "import java.util.Collection;" + "public class Foo {" + " @A private void m1() {}" + " @A void m2(String p) {}" + " @A void m3(String[] p) {}" + " @A void m4(Collection<String> p) {}" + " @A void m5(int p) {}" + "}" ); AnnotationFinder finder = scan("governator.test.Foo", a); Set<String> matchingMethods = new TreeSet<>(); for (Method method : finder.getAnnotatedMethods()) matchingMethods.add(method.getName()); assertThat(matchingMethods, containsInAnyOrder("m1", "m2", "m3", "m4", "m5")); }