ClassIndex { @SuppressWarnings("unchecked") public static <T> Iterable<Class<? extends T>> getSubclasses(Class<T> superClass) { return getSubclasses(superClass, Thread.currentThread().getContextClassLoader()); } private  ClassIndex(); @SuppressWarnings("unchecked") static Iterable<Class<? extends T>> getSubclasses(Class<T> superClass); @SuppressWarnings("unchecked") static Iterable<Class<? extends T>> getSubclasses(Class<T> superClass, ClassLoader classLoader); @SuppressWarnings("unchecked") static Iterable<String> getSubclassesNames(Class<T> superClass); @SuppressWarnings("unchecked") static Iterable<String> getSubclassesNames(Class<T> superClass, ClassLoader classLoader); static Iterable<Class<?>> getPackageClasses(String packageName); static Iterable<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader); static Iterable<String> getPackageClassesNames(String packageName); static Iterable<String> getPackageClassesNames(String packageName, ClassLoader classLoader); static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation); static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation, ClassLoader classLoader); static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation); static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation, ClassLoader classLoader); static String getClassSummary(Class<?> klass); static String getClassSummary(Class<?> klass, ClassLoader classLoader); static final String SUBCLASS_INDEX_PREFIX; static final String ANNOTATED_INDEX_PREFIX; static final String PACKAGE_INDEX_NAME; static final String JAVADOC_PREFIX; }
@Test @SuppressWarnings("unchecked") public void shouldIndexSubclasses() { Iterable<Class<? extends Service>> services = ClassIndex.getSubclasses(Service.class); assertThat(services).containsOnly(FirstService.class, SecondService.class, InnerClasses.InnerService.class); }
@Test @SuppressWarnings("unchecked") public void customProcessorShouldIndexSubclasses() { Iterable<Class<? extends Plugin>> plugins = ClassIndex.getSubclasses(Plugin.class); assertThat(plugins).containsOnly(FirstComponent.class, ExtraPlugin.class); }