AnnotationFinder extends ClassVisitor { public Set<Field> getAnnotatedFields() { return annotatedFields; } 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 testFindAnnotationsOnFields() { cp.compile( "package governator.test;" + "public class Foo {" + " @A private String f1;" + " @A transient String f2;" + " @A static String f3;" + " @A static int f4;" + "}" ); AnnotationFinder finder = scan("governator.test.Foo", a); Set<String> matchingFields = new TreeSet<>(); for (Field field : finder.getAnnotatedFields()) matchingFields.add(field.getName()); assertThat(matchingFields, containsInAnyOrder("f1", "f2", "f3", "f4")); }