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));
}
}
}
}
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;
}
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;
}
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);
}
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");
}
}
}
Aggregations