/** * expand super types after scanning, for super types that were not scanned. this is helpful in * finding the transitive closure without scanning all 3rd party dependencies. it uses {@link * ReflectionUtils#getSuperTypes(Class)}. * * <p>for example, for classes A,B,C where A supertype of B, B supertype of C: * * <ul> * <li>if scanning C resulted in B (B->C in store), but A was not scanned (although A supertype * of B) - then getSubTypes(A) will not return C * <li>if expanding supertypes, B will be expanded with A (A->B in store) - then getSubTypes(A) * will return C * </ul> */ public void expandSuperTypes() { if (store.keySet().contains(index(SubTypesScanner.class))) { Multimap<String, String> mmap = store.get(index(SubTypesScanner.class)); Sets.SetView<String> keys = Sets.difference(mmap.keySet(), Sets.newHashSet(mmap.values())); Multimap<String, String> expand = HashMultimap.create(); for (String key : keys) { expandSupertypes(expand, key, forName(key)); } mmap.putAll(expand); } }
/** merges a Reflections instance metadata into this instance */ public Reflections merge(final Reflections reflections) { if (reflections.store != null) { for (String indexName : reflections.store.keySet()) { Multimap<String, String> index = reflections.store.get(indexName); for (String key : index.keySet()) { for (String string : index.get(key)) { store.getOrCreate(indexName).put(key, string); } } } } return this; }
private void expandSupertypes(Multimap<String, String> mmap, String key, Class<?> type) { for (Class<?> supertype : ReflectionUtils.getSuperTypes(type)) { if (mmap.put(supertype.getName(), key)) { if (log != null) log.debug("expanded subtype {} -> {}", supertype.getName(), key); expandSupertypes(mmap, supertype.getName(), supertype); } } }