use of io.github.classgraph.ClassInfo in project hazelcast by hazelcast.
the class ReflectionUtils method nestedClassesOf.
@Nonnull
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "False positive on try-with-resources as of JDK11")
public static Collection<Class<?>> nestedClassesOf(Class<?>... classes) {
ClassGraph classGraph = new ClassGraph().enableClassInfo().ignoreClassVisibility();
stream(classes).map(Class::getClassLoader).distinct().forEach(classGraph::addClassLoader);
stream(classes).map(ReflectionUtils::toPackageName).distinct().forEach(classGraph::whitelistPackages);
try (ScanResult scanResult = classGraph.scan()) {
Set<String> classNames = stream(classes).map(Class::getName).collect(toSet());
return concat(stream(classes), scanResult.getAllClasses().stream().filter(classInfo -> classNames.contains(classInfo.getName())).flatMap(classInfo -> classInfo.getInnerClasses().stream()).map(ClassInfo::loadClass)).collect(toList());
}
}
use of io.github.classgraph.ClassInfo in project morphia by mongodb.
the class Mapper method getClasses.
private List<Class> getClasses(ClassLoader loader, String packageName, boolean mapSubPackages) throws ClassNotFoundException {
final Set<Class> classes = new HashSet<>();
ClassGraph classGraph = new ClassGraph().addClassLoader(loader).enableAllInfo();
if (mapSubPackages) {
classGraph.acceptPackages(packageName);
classGraph.acceptPackages(packageName + ".*");
} else {
classGraph.acceptPackagesNonRecursive(packageName);
}
try (ScanResult scanResult = classGraph.scan()) {
for (ClassInfo classInfo : scanResult.getAllClasses()) {
classes.add(Class.forName(classInfo.getName(), true, loader));
}
}
return new ArrayList<>(classes);
}
use of io.github.classgraph.ClassInfo in project dhis2-core by dhis2.
the class PreheatStrategyScanner method scanSupplierStrategies.
public Map<String, String> scanSupplierStrategies() {
Map<String, String> classMap = new HashMap<>();
final String pkg = getCurrentPackage();
final String annotation = StrategyFor.class.getName();
try (ScanResult scanResult = new ClassGraph().enableClassInfo().acceptPackages(pkg).enableAnnotationInfo().scan()) {
for (ClassInfo classInfo : scanResult.getClassesWithAnnotation(annotation)) {
classMap.put(getTargetClass(classInfo, annotation), classInfo.getSimpleName());
}
}
return classMap;
}
Aggregations