use of org.reflections.Reflections in project cloudstack by apache.
the class ReflectUtil method getClassesWithAnnotation.
// Gets all classes with some annotation from a package
public static Set<Class<?>> getClassesWithAnnotation(Class<? extends Annotation> annotation, String[] packageNames) {
Reflections reflections;
Set<Class<?>> classes = new HashSet<Class<?>>();
ConfigurationBuilder builder = new ConfigurationBuilder();
for (String packageName : packageNames) {
builder.addUrls(ClasspathHelper.forPackage(packageName));
}
builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
reflections = new Reflections(builder);
classes.addAll(reflections.getTypesAnnotatedWith(annotation));
return classes;
}
use of org.reflections.Reflections in project jstructure by JonStargaryen.
the class FeatureProviderRegistry method scanForFeatureProviders.
private void scanForFeatureProviders() {
Reflections reflections = new Reflections("de.bioforscher");
Set<Class<?>> annotatedFeatureProviders = reflections.getTypesAnnotatedWith(FeatureProvider.class);
for (Class<?> annotatedFeatureProvider : annotatedFeatureProviders) {
FeatureProvider annotation = annotatedFeatureProvider.getDeclaredAnnotation(FeatureProvider.class);
logger.info("registering provider {} with priority {}", annotatedFeatureProvider.getSimpleName(), annotation.priority());
for (Class<? extends FeatureContainerEntry> providedFeature : annotation.provides()) {
TreeMap<Integer, AbstractFeatureProvider> providers = registeredFeatureProviders.getOrDefault(providedFeature, new TreeMap<>());
try {
int priority = annotation.priority();
if (providers.containsKey(priority)) {
providers.put(priority, (AbstractFeatureProvider) annotatedFeatureProvider.newInstance());
} else {
// decrease priority to dodge duplicates, as only 1 would be registered
while (providers.containsKey(priority)) {
priority++;
}
providers.put(priority, (AbstractFeatureProvider) annotatedFeatureProvider.newInstance());
}
} catch (InstantiationException | IllegalAccessException e) {
throw new InstantiationError("could not create instance of feature provider " + annotatedFeatureProvider.getSimpleName());
}
registeredFeatureProviders.put(providedFeature, providers);
}
}
}
use of org.reflections.Reflections in project asterixdb by apache.
the class ExceptionTest method test.
@Test
public void test() throws Exception {
// Tests all usual type computers.
Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false));
Set<Class<? extends IResultTypeComputer>> classes = reflections.getSubTypesOf(IResultTypeComputer.class);
int numTypeComputers = 0;
for (Class<? extends IResultTypeComputer> c : classes) {
if (Modifier.isAbstract(c.getModifiers())) {
continue;
}
testTypeComputer(c);
++numTypeComputers;
}
// Currently, there are 83 type computers.
Assert.assertTrue(numTypeComputers >= 83);
}
use of org.reflections.Reflections in project asterixdb by apache.
the class TypeComputerTest method test.
@Test
public void test() throws Exception {
// Several exceptional type computers.
Set<String> exceptionalTypeComputers = new HashSet<>();
exceptionalTypeComputers.add("InjectFailureTypeComputer");
exceptionalTypeComputers.add("RecordAddFieldsTypeComputer");
exceptionalTypeComputers.add("OpenRecordConstructorResultType");
exceptionalTypeComputers.add("RecordRemoveFieldsTypeComputer");
exceptionalTypeComputers.add("ClosedRecordConstructorResultType");
exceptionalTypeComputers.add("LocalAvgTypeComputer");
exceptionalTypeComputers.add("BooleanOnlyTypeComputer");
exceptionalTypeComputers.add("AMissingTypeComputer");
exceptionalTypeComputers.add("NullableDoubleTypeComputer");
exceptionalTypeComputers.add("RecordMergeTypeComputer");
exceptionalTypeComputers.add("BooleanOrMissingTypeComputer");
// Tests all usual type computers.
Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false));
Set<Class<? extends IResultTypeComputer>> classes = reflections.getSubTypesOf(IResultTypeComputer.class);
for (Class<? extends IResultTypeComputer> c : classes) {
if (exceptionalTypeComputers.contains(c.getSimpleName()) || Modifier.isAbstract(c.getModifiers())) {
continue;
}
System.out.println("Test type computer: " + c.getName());
Assert.assertTrue(testTypeComputer(c));
}
}
use of org.reflections.Reflections in project asterixdb by apache.
the class EvaluatorGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
baseDir = project.getBuild().getDirectory() + File.separator + "classes";
try {
// Finds all sub-classes of AbstractScalarFunctionDynamicDescriptor with in the package
// org.apache.asterix.runtime.evaluators.
Reflections reflections = new Reflections(evaluatorPackagePrefix);
Set<Class<? extends AbstractScalarFunctionDynamicDescriptor>> allClasses = reflections.getSubTypesOf(AbstractScalarFunctionDynamicDescriptor.class);
// Generates byte code for all sub-classes of AbstractScalarFunctionDynamicDescriptor.
for (Class<?> cl : allClasses) {
getLog().info("Generating byte code for " + cl.getName());
CodeGenUtil.generateScalarFunctionDescriptorBinary(evaluatorPackagePrefix, cl.getName(), CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, reflections.getClass().getClassLoader(), (name, bytes) -> writeFile(name, bytes));
}
} catch (Exception e) {
getLog().error(e);
throw new MojoFailureException(e.toString());
}
}
Aggregations