示例#1
0
 /**
  * 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;
 }
示例#2
0
 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));
   }
 }
示例#3
0
 /**
  * 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()));
 }