@SuppressWarnings("unchecked") @Test public void methodsAndFields() throws Exception { TestUtils.makeSource(src, "x.A", "import java.lang.annotation.*;", "@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})", "@net.java.sezpoz.Indexable", "public @interface A {}"); TestUtils.makeSource(src, "y.C", "public class C {", "@x.A", "public static final Object F = 1;", "@x.A", "public static Object m() {return 2;}", "}"); TestUtils.runApt(src, null, clz, new File[0], null); Class<? extends Annotation> a = loader.loadClass("x.A").asSubclass(Annotation.class); int cnt = 0; for (IndexItem item : Index.load(a, Object.class, loader)) { cnt++; assertEquals("y.C", item.className()); if (item.kind() == ElementType.FIELD) { assertEquals("F", item.memberName()); assertEquals(1, item.instance()); } else { assertEquals(ElementType.METHOD, item.kind()); assertEquals("m", item.memberName()); assertEquals(2, item.instance()); } } assertEquals(2, cnt); }
public static <A extends Annotation,I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException { return load(annotation, instanceType, Thread.currentThread().getContextClassLoader()); }
Index implements Iterable<IndexItem<A,I>> { public static <A extends Annotation,I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException { return load(annotation, instanceType, Thread.currentThread().getContextClassLoader()); } }
Index implements Iterable<IndexItem<A,I>> { public static <A extends Annotation,I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException { return load(annotation, instanceType, Thread.currentThread().getContextClassLoader()); } private  Index(Class<A> annotation, Class<I> instance, ClassLoader loader); }
Index implements Iterable<IndexItem<A,I>> { public static <A extends Annotation,I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException { return load(annotation, instanceType, Thread.currentThread().getContextClassLoader()); } private  Index(Class<A> annotation, Class<I> instance, ClassLoader loader); static Index<A,I> load(Class<A> annotation, Class<I> instanceType); static Index<A,I> load(Class<A> annotation, Class<I> instanceType, ClassLoader loader); Iterator<IndexItem<A,I>> iterator(); }
Index implements Iterable<IndexItem<A,I>> { public static <A extends Annotation,I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException { return load(annotation, instanceType, Thread.currentThread().getContextClassLoader()); } private  Index(Class<A> annotation, Class<I> instance, ClassLoader loader); static Index<A,I> load(Class<A> annotation, Class<I> instanceType); static Index<A,I> load(Class<A> annotation, Class<I> instanceType, ClassLoader loader); Iterator<IndexItem<A,I>> iterator();  }