AnnotationFinder extends ClassVisitor { public Set<Class<?>> getAnnotatedClasses() { return annotatedClasses; } 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 testFindAnnotationsOnClasses() { cp.compile( "package governator.test;" + "@A public class Foo {}" ); assertThat(scan("governator.test.Foo", a).getAnnotatedClasses(), is(Matchers.<Class<?>>iterableWithSize(1))); assertThat(scan("governator.test.Foo", b).getAnnotatedClasses(), is(emptyIterable())); }
@Test public void testInnerClasses() { Collection<String> compile = cp.compile( "package governator.test;" + "public class Foo {" + " @A class Inner {}" + " @A static class StaticInner {}" + "}" ); assertThat(scan("governator.test.Foo$Inner", a).getAnnotatedClasses(), is(Matchers.<Class<?>>iterableWithSize(1))); assertThat(scan("governator.test.Foo$StaticInner", a).getAnnotatedClasses(), is(Matchers.<Class<?>>iterableWithSize(1))); }