/** get all types scanned. this is effectively similar to getting all subtypes of Object. * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown * <p><i>note using this might be a bad practice. it is better to get types matching some criteria, * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i> * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen */ public Set<String> getAllTypes() { Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName())); if (allTypes.isEmpty()) { throw new ReflectionsException("Couldn't find subtypes of Object. " + "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)"); } return allTypes; }
/** get all types scanned. this is effectively similar to getting all subtypes of Object. * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown * <p><i>note using this might be a bad practice. it is better to get types matching some criteria, * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i> * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen */ public Set<String> getAllTypes() { Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName())); if (allTypes.isEmpty()) { throw new ReflectionsException("Couldn't find subtypes of Object. " + "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)"); } return allTypes; }
/** * gets all sub types in hierarchy of a given type * <p/>depends on SubTypesScanner configured */ public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) { return Sets.newHashSet(ReflectionUtils.<T>forNames( store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders())); }
/** * gets all sub types in hierarchy of a given type * <p/>depends on SubTypesScanner configured */ public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) { return Sets.newHashSet(ReflectionUtils.<T>forNames( store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders())); }
protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) { if (honorInherited) { if (inherited) { Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() { public boolean apply(@Nullable String input) { final Class<?> type = forName(input, loaders()); return type != null && !type.isInterface(); } })); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } else { return annotated; } } else { Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated)); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } }
protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) { if (honorInherited) { if (inherited) { Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() { public boolean apply(@Nullable String input) { final Class<?> type = forName(input, loaders()); return type != null && !type.isInterface(); } })); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } else { return annotated; } } else { Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated)); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } }
public Set<String> getAllTypes() { final String index = index(SubTypesScanner.class); final Iterable<String> storeAll = store.getAll(index , Object.class.getName()); final Set<String> allTypes = StreamSupport .stream(storeAll.spliterator() , false) .collect(Collectors.toSet()); if (allTypes.isEmpty()) { throw new ReflectionsException("Couldn't find subtypes of Object. " + "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)"); } return allTypes; }
/** get all types scanned. this is effectively similar to getting all subtypes of Object. * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown * <p><i>note using this might be a bad practice. it is better to get types matching some criteria, * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i> * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen */ public Set<String> getAllTypes() { Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName())); if (allTypes.isEmpty()) { throw new ReflectionsException("Couldn't find subtypes of Object. " + "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)"); } return allTypes; }
/** get all types scanned. this is effectively similar to getting all subtypes of Object. * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown * <p><i>note using this might be a bad practice. it is better to get types matching some criteria, * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i> * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen */ public Set<String> getAllTypes() { Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName())); if (allTypes.isEmpty()) { throw new ReflectionsException("Couldn't find subtypes of Object. " + "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)"); } return allTypes; }
/** * gets all sub types in hierarchy of a given type * <p/>depends on SubTypesScanner configured */ public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) { return Sets.newHashSet(ReflectionUtils.<T>forNames( store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders())); }
/** * gets all sub types in hierarchy of a given type * <p/>depends on SubTypesScanner configured */ public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) { return Sets.newHashSet(ReflectionUtils.<T>forNames( store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders())); }
Set<Class<? extends T>> scan(Class<? extends T> aClass) { Configuration configuration = ConfigurationBuilder.build((Object[]) packages).addClassLoaders(classLoaders) .addScanners(new AssignableScanner(aClass)); Reflections reflections = new Reflections(configuration); Predicate<Class<? extends T>> classPredicate = klass -> Modifier.isPublic(klass.getModifiers()) && (!klass.isMemberClass() || (klass.isMemberClass() && Modifier .isStatic(klass.getModifiers()))) && !Modifier.isInterface(klass.getModifiers()) && !Modifier.isAbstract(klass.getModifiers()); HashSet<Class<? extends T>> subtypes = Sets.newHashSet( ReflectionUtils.forNames( reflections.getStore() .getAll(AssignableScanner.class.getSimpleName(), Collections.singletonList(aClass.getName())), classLoaders)); return subtypes.stream().filter(classPredicate).collect(Collectors.toSet()); }
private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) { //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes List<String> classNames = Collections.singletonList(UIModule.class.getName()); Reflections reflections = new Reflections(); org.reflections.Store store = reflections.getStore(); Iterable<String> subtypesByName = store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames); Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName)); List<Class<?>> toCreate = new ArrayList<>(); for (Class<?> c : subtypeClasses) { if (excludeClasses.contains(c)) continue;; toCreate.add(c); } List<UIModule> ret = new ArrayList<>(toCreate.size()); for (Class<?> c : toCreate) { UIModule m; try { m = (UIModule) c.newInstance(); } catch (Exception e) { log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e); continue; } log.debug("Created instance of custom UI module: {}", c); ret.add(m); } return ret; }
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) { final Iterable<String> all = store.getAll(index(SubTypesScanner.class) , Arrays.asList(type.getName())); return new HashSet<>(ReflectionUtils.<T>forNames(all , loaders())); }
private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) { //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes List<String> classNames = Collections.singletonList(UIModule.class.getName()); Reflections reflections = new Reflections(); org.reflections.Store store = reflections.getStore(); Iterable<String> subtypesByName = store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames); Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName)); List<Class<?>> toCreate = new ArrayList<>(); for (Class<?> c : subtypeClasses) { if (excludeClasses.contains(c)) continue;; toCreate.add(c); } List<UIModule> ret = new ArrayList<>(toCreate.size()); for (Class<?> c : toCreate) { UIModule m; try { m = (UIModule) c.newInstance(); } catch (Exception e) { log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e); continue; } log.debug("Created instance of custom UI module: {}", c); ret.add(m); } return ret; }
protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) { if (honorInherited) { if (inherited) { Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() { public boolean apply(@Nullable String input) { final Class<?> type = forName(input, loaders()); return type != null && !type.isInterface(); } })); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } else { return annotated; } } else { Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated)); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } }
protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) { if (honorInherited) { if (inherited) { Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() { public boolean apply(@Nullable String input) { return !ReflectionUtils.forName(input, loaders()).isInterface(); } })); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } else { return annotated; } } else { Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated)); return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes)); } }
private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) { //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes List<String> classNames = Collections.singletonList(UIModule.class.getName()); Reflections reflections = new Reflections(); org.reflections.Store store = reflections.getStore(); Iterable<String> subtypesByName = store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames); Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName)); List<Class<?>> toCreate = new ArrayList<>(); for (Class<?> c : subtypeClasses) { if (excludeClasses.contains(c)) continue;; toCreate.add(c); } List<UIModule> ret = new ArrayList<>(toCreate.size()); for (Class<?> c : toCreate) { UIModule m; try { m = (UIModule) c.newInstance(); } catch (Exception e) { log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e); continue; } log.debug("Created instance of custom UI module: {}", c); ret.add(m); } return ret; }
protected Iterable<String> getAllAnnotated(Iterable<String> annotated , boolean inherited , boolean honorInherited) { if (honorInherited) { if (inherited) { Iterable<String> subTypes = store.get(index(SubTypesScanner.class) , filter(annotated , (Predicate<String>) input -> ! ReflectionUtils.forName(input , loaders()).isInterface())); return concat(subTypes , store.getAll(index(SubTypesScanner.class) , subTypes)); } else { return annotated; } } else { Iterable<String> subTypes = concat(annotated , store.getAll(index(TypeAnnotationsScanner.class) , annotated)); return concat(subTypes , store.getAll(index(SubTypesScanner.class) , subTypes)); } }
org.reflections.Store store = reflections.getStore(); Iterable<String> subtypesByName = store.getAll(DataVecSubTypesScanner.class.getSimpleName(), classNames);