本文整理了Java中org.reflections.Store
类的一些代码示例,展示了Store
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Store
类的具体详情如下:
包路径:org.reflections.Store
类名称:Store
[英]stores metadata information in multimaps
use the different query methods (getXXX) to query the metadata
the query methods are string based, and does not cause the class loader to define the types
use org.reflections.Reflections#getStore() to access this store
[中]在多重映射中存储元数据信息
使用不同的查询方法(getXXX)查询元数据
查询方法是基于字符串的,不会导致类加载器定义类型
使用组织。反思。反射#getStore()以访问此存储
代码示例来源:origin: org.reflections/reflections
/**
* 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>
* <li>if expanding supertypes, B will be expanded with A (A->B in store) - then getSubTypes(A) will return C</li>
* </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) {
final Class<?> type = forName(key);
if (type != null) {
expandSupertypes(expand, key, type);
}
}
mmap.putAll(expand);
}
}
代码示例来源:origin: org.reflections/reflections
/**
* 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()));
}
代码示例来源:origin: org.reflections/reflections
/**
* constructs a Reflections instance and scan according to given {@link org.reflections.Configuration}
* <p>it is preferred to use {@link org.reflections.util.ConfigurationBuilder}
*/
public Reflections(final Configuration configuration) {
this.configuration = configuration;
store = new Store(configuration);
if (configuration.getScanners() != null && !configuration.getScanners().isEmpty()) {
//inject to scanners
for (Scanner scanner : configuration.getScanners()) {
scanner.setConfiguration(configuration);
scanner.setStore(store.getOrCreate(scanner.getClass().getSimpleName()));
}
scan();
if (configuration.shouldExpandSuperTypes()) {
expandSuperTypes();
}
}
}
代码示例来源:origin: ronmamo/reflections
/** recursively get the values stored for the given {@code index} and {@code keys}, including keys */
private Iterable<String> getAllIncluding(String index, Iterable<String> keys, IterableChain<String> result) {
result.addAll(keys);
for (String key : keys) {
Iterable<String> values = get(index, key);
if (values.iterator().hasNext()) {
getAllIncluding(index, values, result);
}
}
return result;
}
代码示例来源:origin: ronmamo/reflections
/**
* 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;
}
代码示例来源:origin: org.reflections/reflections
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));
}
}
代码示例来源:origin: org.reflections/reflections
/**
* get types annotated with a given annotation, both classes and annotations, including annotation member values matching
* <p>{@link java.lang.annotation.Inherited} is honored according to given honorInherited
* <p/>depends on TypeAnnotationsScanner configured
*/
public Set<Class<?>> getTypesAnnotatedWith(final Annotation annotation, boolean honorInherited) {
Iterable<String> annotated = store.get(index(TypeAnnotationsScanner.class), annotation.annotationType().getName());
Iterable<Class<?>> filter = filter(forNames(annotated, loaders()), withAnnotation(annotation));
Iterable<String> classes = getAllAnnotated(names(filter), annotation.annotationType().isAnnotationPresent(Inherited.class), honorInherited);
return Sets.newHashSet(concat(filter, forNames(filter(classes, not(in(Sets.newHashSet(annotated)))), loaders())));
}
代码示例来源:origin: ronmamo/reflections
public String toString(Reflections reflections) {
if (reflections.getStore().get(index(TypeElementsScanner.class)).isEmpty()) {
if (log != null) log.warn("JavaCodeSerializer needs TypeElementsScanner configured");
int indent = 1;
List<String> keys = Lists.newArrayList(reflections.getStore().get(index(TypeElementsScanner.class)).keySet());
Collections.sort(keys);
for (String fqn : keys) {
for (String element : reflections.getStore().get(index(TypeElementsScanner.class), fqn)) {
if (element.startsWith("@")) {
annotations.add(element.substring(1));
methods.put(name, normalized);
代码示例来源:origin: org.reflections/reflections
/**
* get types annotated with a given annotation, both classes and annotations
* <p>{@link java.lang.annotation.Inherited} is honored according to given honorInherited.
* <p>when honoring @Inherited, meta-annotation should only effect annotated super classes and it's sub types
* <p>when not honoring @Inherited, meta annotation effects all subtypes, including annotations interfaces and classes
* <p><i>Note that this (@Inherited) meta-annotation type has no effect if the annotated type is used for anything other then a class.
* Also, this meta-annotation causes annotations to be inherited only from superclasses; annotations on implemented interfaces have no effect.</i>
* <p/>depends on TypeAnnotationsScanner and SubTypesScanner configured
*/
public Set<Class<?>> getTypesAnnotatedWith(final Class<? extends Annotation> annotation, boolean honorInherited) {
Iterable<String> annotated = store.get(index(TypeAnnotationsScanner.class), annotation.getName());
Iterable<String> classes = getAllAnnotated(annotated, annotation.isAnnotationPresent(Inherited.class), honorInherited);
return Sets.newHashSet(concat(forNames(annotated, loaders()), forNames(classes, loaders())));
}
代码示例来源:origin: org.reflections/reflections
/** 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;
}
代码示例来源:origin: org.reflections/reflections
/** get resources relative paths where simple name (key) matches given namePredicate
* <p>depends on ResourcesScanner configured
* */
public Set<String> getResources(final Predicate<String> namePredicate) {
Iterable<String> resources = Iterables.filter(store.get(index(ResourcesScanner.class)).keySet(), namePredicate);
return Sets.newHashSet(store.get(index(ResourcesScanner.class), resources));
}
代码示例来源:origin: ronmamo/reflections
/** get resources relative paths where simple name (key) matches given namePredicate
* <p>depends on ResourcesScanner configured
* */
public Set<String> getResources(final Predicate<String> namePredicate) {
Iterable<String> resources = Iterables.filter(store.get(index(ResourcesScanner.class)).keySet(), namePredicate);
return Sets.newHashSet(store.get(index(ResourcesScanner.class), resources));
}
代码示例来源:origin: org.reflections/reflections
/**
* get all fields annotated with a given annotation
* <p/>depends on FieldAnnotationsScanner configured
*/
public Set<Field> getFieldsAnnotatedWith(final Class<? extends Annotation> annotation) {
final Set<Field> result = Sets.newHashSet();
for (String annotated : store.get(index(FieldAnnotationsScanner.class), annotation.getName())) {
result.add(getFieldFromString(annotated, loaders()));
}
return result;
}
代码示例来源:origin: ronmamo/reflections
/**
* get all fields annotated with a given annotation
* <p/>depends on FieldAnnotationsScanner configured
*/
public Set<Field> getFieldsAnnotatedWith(final Class<? extends Annotation> annotation) {
final Set<Field> result = Sets.newHashSet();
for (String annotated : store.get(index(FieldAnnotationsScanner.class), annotation.getName())) {
result.add(getFieldFromString(annotated, loaders()));
}
return result;
}
代码示例来源:origin: ronmamo/reflections
public Reflections read(InputStream inputStream) {
Reflections reflections;
try {
Constructor<Reflections> constructor = Reflections.class.getDeclaredConstructor();
constructor.setAccessible(true);
reflections = constructor.newInstance();
} catch (Exception e) {
reflections = new Reflections(new ConfigurationBuilder());
}
try {
Document document = new SAXReader().read(inputStream);
for (Object e1 : document.getRootElement().elements()) {
Element index = (Element) e1;
for (Object e2 : index.elements()) {
Element entry = (Element) e2;
Element key = entry.element("key");
Element values = entry.element("values");
for (Object o3 : values.elements()) {
Element value = (Element) o3;
reflections.getStore().getOrCreate(index.getName()).put(key.getText(), value.getText());
}
}
}
} catch (DocumentException e) {
throw new ReflectionsException("could not read.", e);
} catch (Throwable e) {
throw new RuntimeException("Could not read. Make sure relevant dependencies exist on classpath.", e);
}
return reflections;
}
代码示例来源:origin: ronmamo/reflections
private Document createDocument(final Reflections reflections) {
Store map = reflections.getStore();
Document document = DocumentFactory.getInstance().createDocument();
Element root = document.addElement("Reflections");
for (String indexName : map.keySet()) {
Element indexElement = root.addElement(indexName);
for (String key : map.get(indexName).keySet()) {
Element entryElement = indexElement.addElement("entry");
entryElement.addElement("key").setText(key);
Element valuesElement = entryElement.addElement("values");
for (String value : map.get(indexName).get(key)) {
valuesElement.addElement("value").setText(value);
}
}
}
return document;
}
}
代码示例来源:origin: ronmamo/reflections
/** 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;
}
代码示例来源:origin: eventsourcing/es4j
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());
}
代码示例来源:origin: xtuhcy/gecco
/**
* 动态增加的spiderBean
*/
private void dynamic() {
GeccoClassLoader gcl = GeccoClassLoader.get();
for (String className : gcl.getClasses().keySet()) {
reflections.getStore().get(TypeAnnotationsScanner.class.getSimpleName()).put(Gecco.class.getName(),
className);
}
}
代码示例来源:origin: ronmamo/reflections
if (urls.isEmpty()) return null;
long start = System.currentTimeMillis();
final Reflections reflections = new Reflections();
Iterable<Vfs.File> files = Vfs.findFiles(urls, packagePrefix, resourceNameFilter);
for (final Vfs.File file : files) {
try {
inputStream = file.openInputStream();
reflections.merge(serializer.read(inputStream));
} catch (IOException e) {
throw new ReflectionsException("could not merge " + file, e);
Store store = reflections.getStore();
int keys = 0;
int values = 0;
for (String index : store.keySet()) {
keys += store.get(index).keySet().size();
values += store.get(index).size();
内容来源于网络,如有侵权,请联系作者删除!