use of org.reflections.scanners.FieldAnnotationsScanner in project startup-os by google.
the class ClassScanner method scanPackage.
public void scanPackage(String packagePrefix, Map<String, FlagData> flags) {
// TODO - figure out configuration builder.
Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packagePrefix))).setUrls(ClasspathHelper.forPackage(packagePrefix)).setScanners(new FieldAnnotationsScanner()));
Set<Field> fields = reflections.getFieldsAnnotatedWith(FlagDesc.class);
for (Field field : fields) {
Class<?> clazz = field.getType();
if (!Flag.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException("Annotation '" + field + "' does not annotate a flag.");
}
if ((field.getModifiers() & Modifier.STATIC) == 0) {
throw new IllegalArgumentException("Flag '" + field + "' should be static but is not.");
}
Class<?> declaringClass = field.getDeclaringClass();
Flag<?> flag = getFlagMember(declaringClass, field);
FlagData flagData = createFlagData(declaringClass, field, flag);
if (flags.containsKey(flagData.getName())) {
throw new IllegalArgumentException(String.format("Flag '%s' is already defined here:\n%s", field, flags.get(flagData.getName())));
}
flags.put(flagData.getName(), flagData);
flag.setName(flagData.getName());
}
}
use of org.reflections.scanners.FieldAnnotationsScanner in project kanonizo by kanonizo.
the class Util method getReflections.
public static Reflections getReflections() {
if (r == null) {
Set<URL> packages = new HashSet<>(ClasspathHelper.forPackage("org.kanonizo"));
packages.addAll(ClasspathHelper.forPackage("com.scythe"));
r = new Reflections(new ConfigurationBuilder().setUrls(packages).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
}
return r;
}
use of org.reflections.scanners.FieldAnnotationsScanner in project oc-explorer by devgateway.
the class ReflectionsConfiguration method reflections.
@Bean
public Reflections reflections() {
logger.debug("Starting reflections scanners...");
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.devgateway.ocds.persistence.mongo")).setScanners(new SubTypesScanner(), new FieldAnnotationsScanner(), new MethodParameterScanner()));
logger.debug("Configured reflections bean.");
return reflections;
}
Aggregations