Search in sources :

Example 6 with FieldAnnotationsScanner

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());
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Field(java.lang.reflect.Field) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) FilterBuilder(org.reflections.util.FilterBuilder) Reflections(org.reflections.Reflections)

Example 7 with FieldAnnotationsScanner

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;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) URL(java.net.URL) HashSet(java.util.HashSet) Reflections(org.reflections.Reflections)

Example 8 with FieldAnnotationsScanner

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;
}
Also used : MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) Bean(org.springframework.context.annotation.Bean)

Aggregations

FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)8 Reflections (org.reflections.Reflections)7 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)7 SubTypesScanner (org.reflections.scanners.SubTypesScanner)6 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)4 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)3 Field (java.lang.reflect.Field)2 URL (java.net.URL)2 FilterBuilder (org.reflections.util.FilterBuilder)2 Bean (org.springframework.context.annotation.Bean)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)1 RestServlet (password.pwm.ws.server.RestServlet)1