Search in sources :

Example 1 with FieldAnnotationsScanner

use of org.reflections.scanners.FieldAnnotationsScanner in project ocvn 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)

Example 2 with FieldAnnotationsScanner

use of org.reflections.scanners.FieldAnnotationsScanner in project pwm by pwm-project.

the class ControlledPwmServletTest method getClassAndMethods.

private Map<Class<? extends ControlledPwmServlet>, Map<String, Method>> getClassAndMethods() {
    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("password.pwm")).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
    Set<Class<? extends ControlledPwmServlet>> classes = reflections.getSubTypesOf(ControlledPwmServlet.class);
    final Map<Class<? extends ControlledPwmServlet>, Map<String, Method>> returnMap = new HashMap<>();
    for (final Class<? extends ControlledPwmServlet> controlledPwmServlet : classes) {
        if (!Modifier.isAbstract(controlledPwmServlet.getModifiers())) {
            final Map<String, Method> annotatedMethods = new HashMap<>();
            for (Method method : JavaHelper.getAllMethodsForClass(controlledPwmServlet)) {
                if (method.getAnnotation(ControlledPwmServlet.ActionHandler.class) != null) {
                    final String actionName = method.getAnnotation(ControlledPwmServlet.ActionHandler.class).action();
                    annotatedMethods.put(actionName, method);
                }
            }
            returnMap.put(controlledPwmServlet, Collections.unmodifiableMap(annotatedMethods));
        }
    }
    return Collections.unmodifiableMap(returnMap);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) HashMap(java.util.HashMap) Map(java.util.Map) Reflections(org.reflections.Reflections)

Example 3 with FieldAnnotationsScanner

use of org.reflections.scanners.FieldAnnotationsScanner in project pwm by pwm-project.

the class RestServletTest method getClasses.

private Set<Class<? extends RestServlet>> getClasses() {
    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("password.pwm")).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
    Set<Class<? extends RestServlet>> classes = reflections.getSubTypesOf(RestServlet.class);
    return Collections.unmodifiableSet(classes);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) RestServlet(password.pwm.ws.server.RestServlet) Reflections(org.reflections.Reflections)

Example 4 with FieldAnnotationsScanner

use of org.reflections.scanners.FieldAnnotationsScanner in project disconf by knightliao.

the class ReflectionScanStatic method getReflection.

/**
 * 通过扫描,获取反射对象
 */
private Reflections getReflection(List<String> packNameList) {
    // 
    // filter
    // 
    FilterBuilder filterBuilder = new FilterBuilder().includePackage(Constants.DISCONF_PACK_NAME);
    for (String packName : packNameList) {
        filterBuilder = filterBuilder.includePackage(packName);
    }
    Predicate<String> filter = filterBuilder;
    // 
    // urls
    // 
    Collection<URL> urlTotals = new ArrayList<URL>();
    for (String packName : packNameList) {
        Set<URL> urls = ClasspathHelper.forPackage(packName);
        urlTotals.addAll(urls);
    }
    // 
    Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter).setScanners(new SubTypesScanner().filterResultsBy(filter), new TypeAnnotationsScanner().filterResultsBy(filter), new FieldAnnotationsScanner().filterResultsBy(filter), new MethodAnnotationsScanner().filterResultsBy(filter), new MethodParameterScanner()).setUrls(urlTotals));
    return reflections;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ArrayList(java.util.ArrayList) URL(java.net.URL) MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Reflections(org.reflections.Reflections)

Example 5 with FieldAnnotationsScanner

use of org.reflections.scanners.FieldAnnotationsScanner in project reflections by ronmamo.

the class ReflectionUtilsTest method getAllAndReflections.

@Test
public void getAllAndReflections() {
    Reflections reflections = new Reflections(TestModel.class, new FieldAnnotationsScanner());
    Set<Field> af1 = reflections.getFieldsAnnotatedWith(TestModel.AF1.class);
    Set<? extends Field> allFields = ReflectionUtils.getAll(af1, withModifier(Modifier.PROTECTED));
    assertTrue(allFields.size() == 1);
    assertThat(allFields, names("f2"));
}
Also used : Field(java.lang.reflect.Field) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) Test(org.junit.Test)

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