@Test public void getSubTypesOf_interface() { Set<Class<? extends ReflectionsExampleInterface>> found = reflectionsToTest.getSubTypesOf(ReflectionsExampleInterface.class); assertNotNull(found); assertEquals(2, found.size()); assertTrue(found.contains(ReflectionsExampleClass1.class)); assertTrue(found.contains(ReflectionsExampleClass2.class)); }
public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> clazz) { ensureScan(); synchronized (MONITOR) { @SuppressWarnings("rawtypes") Set x = classToSubTypes.get(clazz); @SuppressWarnings("unchecked") Set<Class<? extends T>> result = x; if (result != null) { return result; } Set<Class<? extends T>> newresult = new LinkedHashSet<>(); visitEveryClass(new Visitor() { @SuppressWarnings("unchecked") @Override public void visit(Class<?> clazzToInspect) { if (clazzToInspect==clazz) { return; } if (clazz.isAssignableFrom(clazzToInspect)) { newresult.add((Class<? extends T>) clazzToInspect); } } }); classToSubTypes.put(clazz, newresult); return newresult; } }
Reflections { public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> clazz) { ensureScan(); synchronized (MONITOR) { @SuppressWarnings("rawtypes") Set x = classToSubTypes.get(clazz); @SuppressWarnings("unchecked") Set<Class<? extends T>> result = x; if (result != null) { return result; } Set<Class<? extends T>> newresult = new LinkedHashSet<>(); visitEveryClass(new Visitor() { @SuppressWarnings("unchecked") @Override public void visit(Class<?> clazzToInspect) { if (clazzToInspect==clazz) { return; } if (clazz.isAssignableFrom(clazzToInspect)) { newresult.add((Class<? extends T>) clazzToInspect); } } }); classToSubTypes.put(clazz, newresult); return newresult; } } }
Reflections { public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> clazz) { ensureScan(); synchronized (MONITOR) { @SuppressWarnings("rawtypes") Set x = classToSubTypes.get(clazz); @SuppressWarnings("unchecked") Set<Class<? extends T>> result = x; if (result != null) { return result; } Set<Class<? extends T>> newresult = new LinkedHashSet<>(); visitEveryClass(new Visitor() { @SuppressWarnings("unchecked") @Override public void visit(Class<?> clazzToInspect) { if (clazzToInspect==clazz) { return; } if (clazz.isAssignableFrom(clazzToInspect)) { newresult.add((Class<? extends T>) clazzToInspect); } } }); classToSubTypes.put(clazz, newresult); return newresult; } } Reflections(); }
Reflections { public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> clazz) { ensureScan(); synchronized (MONITOR) { @SuppressWarnings("rawtypes") Set x = classToSubTypes.get(clazz); @SuppressWarnings("unchecked") Set<Class<? extends T>> result = x; if (result != null) { return result; } Set<Class<? extends T>> newresult = new LinkedHashSet<>(); visitEveryClass(new Visitor() { @SuppressWarnings("unchecked") @Override public void visit(Class<?> clazzToInspect) { if (clazzToInspect==clazz) { return; } if (clazz.isAssignableFrom(clazzToInspect)) { newresult.add((Class<? extends T>) clazzToInspect); } } }); classToSubTypes.put(clazz, newresult); return newresult; } } Reflections(); Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation); Set<Method> getMethodsAnnotatedWith(Class<? extends Annotation> annotation); Set<Field> getFieldsAnnotatedWith(Class<? extends Annotation> annotation); Set<Class<? extends T>> getSubTypesOf(Class<T> clazz); boolean isInspecting(Class<?> clazz); int getAmountOfInspectedClasses(); }
Reflections { public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> clazz) { ensureScan(); synchronized (MONITOR) { @SuppressWarnings("rawtypes") Set x = classToSubTypes.get(clazz); @SuppressWarnings("unchecked") Set<Class<? extends T>> result = x; if (result != null) { return result; } Set<Class<? extends T>> newresult = new LinkedHashSet<>(); visitEveryClass(new Visitor() { @SuppressWarnings("unchecked") @Override public void visit(Class<?> clazzToInspect) { if (clazzToInspect==clazz) { return; } if (clazz.isAssignableFrom(clazzToInspect)) { newresult.add((Class<? extends T>) clazzToInspect); } } }); classToSubTypes.put(clazz, newresult); return newresult; } } Reflections(); Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation); Set<Method> getMethodsAnnotatedWith(Class<? extends Annotation> annotation); Set<Field> getFieldsAnnotatedWith(Class<? extends Annotation> annotation); Set<Class<? extends T>> getSubTypesOf(Class<T> clazz); boolean isInspecting(Class<?> clazz); int getAmountOfInspectedClasses();  }