use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project FXGL by AlmasB.
the class ReflectionUtils method findClasses.
/**
* @return mapping from annotation class to list of classes with that annotation (on the classpath)
*/
public static Map<Class<?>, List<Class<?>>> findClasses(String packageName, Class<? extends java.lang.annotation.Annotation>... annotations) {
Map<Class<?>, List<Class<?>>> map = new HashMap<>();
FastClasspathScanner scanner = new FastClasspathScanner(packageName);
for (Class<? extends Annotation> annotationClass : annotations) {
map.put(annotationClass, new ArrayList<>());
scanner.matchClassesWithAnnotation(annotationClass, map.get(annotationClass)::add);
}
scanner.scan();
return map;
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project junit5 by junit-team.
the class ApiReportGenerator method generateReport.
// -------------------------------------------------------------------------
ApiReport generateReport(String... packages) {
final Logger logger = LoggerFactory.getLogger(ApiReportGenerator.class);
final String EOL = System.lineSeparator();
// Scan packages
ScanResult scanResult = new FastClasspathScanner(packages).scan();
// Collect names
List<String> names = new ArrayList<>();
names.addAll(scanResult.getNamesOfClassesWithAnnotation(API.class));
names.addAll(scanResult.getNamesOfAnnotationsWithMetaAnnotation(API.class));
logger.debug(() -> {
StringBuilder builder = new StringBuilder(names.size() + " @API declarations (including meta) found in class-path:");
builder.append(EOL);
scanResult.getUniqueClasspathElements().forEach(e -> builder.append(e).append(EOL));
return builder.toString();
});
// Collect types
List<Class<?>> types = scanResult.classNamesToClassRefs(names);
// only retain directly annotated types
types.removeIf(c -> !c.isAnnotationPresent(API.class));
types.sort(Comparator.comparing(type -> type.getName()));
logger.debug(() -> {
StringBuilder builder = new StringBuilder("Listing of all " + types.size() + " annotated types:");
builder.append(EOL);
types.forEach(e -> builder.append(e).append(EOL));
return builder.toString();
});
// Build map
Map<Status, List<Class<?>>> declarationsMap = new EnumMap<>(Status.class);
for (Status status : Status.values()) {
declarationsMap.put(status, new ArrayList<>());
}
types.forEach(type -> declarationsMap.get(type.getAnnotation(API.class).status()).add(type));
// Create report
return new ApiReport(types, declarationsMap);
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project bender by Nextdoor.
the class AbstractConfig method getSubtypes.
public static Class<?>[] getSubtypes(Class clazz) {
Set<Class<? extends AbstractConfig>> classSet = new HashSet();
FastClasspathScanner s = new FastClasspathScanner();
s.scan().getNamesOfSubclassesOf(clazz).forEach(c -> {
try {
classSet.add((Class<? extends AbstractConfig>) Class.forName(c));
} catch (ClassNotFoundException e) {
}
});
/*
* Remove abstract classes as they are not allowed in the mapper
*/
classSet.removeIf(p -> Modifier.isAbstract(p.getModifiers()) == true);
return classSet.toArray(new Class<?>[classSet.size()]);
}
Aggregations