Search in sources :

Example 36 with Reflections

use of org.reflections.Reflections in project querydsl by querydsl.

the class SerializationTest method expressions.

@Test
public void expressions() throws Exception {
    Map<Class<?>, Object> args = Maps.newHashMap();
    args.put(Object.class, "obj");
    args.put(BeanPath.class, new EntityPathBase<Object>(Object.class, "obj"));
    args.put(Class.class, Integer.class);
    args.put(Class[].class, new Class<?>[] { Object.class, Object.class });
    args.put(java.util.Date.class, new java.util.Date(0));
    args.put(java.sql.Date.class, new java.sql.Date(0));
    args.put(java.sql.Time.class, new java.sql.Time(0));
    args.put(java.sql.Timestamp.class, new java.sql.Timestamp(0));
    args.put(Expression.class, Expressions.enumPath(Gender.class, "e"));
    args.put(Expression[].class, new Expression<?>[] { Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s") });
    args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str")));
    args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num")));
    args.put(Number.class, 1);
    args.put(Operator.class, Ops.AND);
    args.put(Path.class, Expressions.stringPath("str"));
    args.put(PathBuilderValidator.class, PathBuilderValidator.DEFAULT);
    args.put(PathMetadata.class, PathMetadataFactory.forVariable("obj"));
    args.put(PathInits.class, PathInits.DEFAULT);
    args.put(Predicate.class, Expressions.path(Object.class, "obj").isNull());
    args.put(QueryMetadata.class, new DefaultQueryMetadata());
    args.put(String.class, "obj");
    Reflections reflections = new Reflections();
    Set<Class<? extends Expression>> types = reflections.getSubTypesOf(Expression.class);
    for (Class<?> type : types) {
        if (!type.isInterface() && !type.isMemberClass() && !Modifier.isAbstract(type.getModifiers())) {
            for (Constructor<?> c : type.getConstructors()) {
                Object[] parameters = new Object[c.getParameterTypes().length];
                for (int i = 0; i < c.getParameterTypes().length; i++) {
                    parameters[i] = Objects.requireNonNull(args.get(c.getParameterTypes()[i]), c.getParameterTypes()[i].getName());
                }
                c.setAccessible(true);
                Object o = c.newInstance(parameters);
                assertEquals(o, Serialization.serialize(o));
            }
        }
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) GroupExpression(com.querydsl.core.group.GroupExpression) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 37 with Reflections

use of org.reflections.Reflections in project querydsl by querydsl.

the class ClassPathUtils method scanPackage.

/**
     * Return the classes from the given package and subpackages using the supplied classloader
     *
     * @param classLoader classloader to be used
     * @param pkg package to scan
     * @return set of found classes
     * @throws IOException
     */
public static Set<Class<?>> scanPackage(ClassLoader classLoader, String pkg) throws IOException {
    Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(pkg, classLoader)).addClassLoader(classLoader).setScanners(new SubTypesScanner(false)));
    Set<Class<?>> classes = new HashSet<Class<?>>();
    for (String typeNames : reflections.getStore().get(SubTypesScanner.class.getSimpleName()).values()) {
        Class<?> clazz = safeClassForName(classLoader, typeNames);
        if (clazz != null) {
            classes.add(clazz);
        }
    }
    return classes;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Example 38 with Reflections

use of org.reflections.Reflections in project swagger-core by swagger-api.

the class ReflectiveJaxrsScanner method getReflections.

protected Reflections getReflections() {
    if (reflections == null) {
        ConfigurationBuilder config = new ConfigurationBuilder();
        acceptablePackages = new HashSet<String>();
        if (resourcePackage != "") {
            String[] parts = resourcePackage.split(",");
            for (String pkg : parts) {
                if (!"".equals(pkg)) {
                    acceptablePackages.add(pkg);
                    config.addUrls(ClasspathHelper.forPackage(pkg));
                }
            }
        }
        config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
        this.reflections = new Reflections(config);
    }
    return this.reflections;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 39 with Reflections

use of org.reflections.Reflections in project ninja by ninjaframework.

the class JaxyRoutes method configureReflections.

private void configureReflections() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    Set<URL> packagesToScan = getPackagesToScanForRoutes();
    builder.addUrls(packagesToScan);
    builder.addScanners(new MethodAnnotationsScanner());
    reflections = new Reflections(builder);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) URL(java.net.URL) Reflections(org.reflections.Reflections)

Example 40 with Reflections

use of org.reflections.Reflections in project generator by mybatis.

the class GenerateTestSourceFiles method gatherGenerators.

private void gatherGenerators(List<CompilationUnitGenerator> generators) throws InstantiationException, IllegalAccessException {
    Reflections reflections = new Reflections("mbg.domtest.generators");
    Set<Class<? extends CompilationUnitGenerator>> classes = reflections.getSubTypesOf(CompilationUnitGenerator.class);
    for (Class<? extends CompilationUnitGenerator> clazz : classes) {
        if (clazz.getAnnotation(IgnoreDomTest.class) == null) {
            generators.add(clazz.newInstance());
        } else {
            System.out.println("Generator " + clazz.getName() + " ignored");
        }
    }
}
Also used : Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)60 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)26 SubTypesScanner (org.reflections.scanners.SubTypesScanner)20 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Test (org.junit.Test)9 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)9 HashSet (java.util.HashSet)7 Set (java.util.Set)6 IOException (java.io.IOException)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ResourcesScanner (org.reflections.scanners.ResourcesScanner)5 Slf4j (lombok.extern.slf4j.Slf4j)4 ClasspathHelper (org.reflections.util.ClasspathHelper)4 FilterBuilder (org.reflections.util.FilterBuilder)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Method (java.lang.reflect.Method)3 HashMap (java.util.HashMap)3