public List<String> getGeneratedProtoClasses(String serviceName) { FastClasspathScanner cpScanner = new FastClasspathScanner(); ScanResult scanResult = cpScanner.scan(); List<String> oldProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessage.class); List<String> newProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessageV3.class); List<String> retval = Stream.concat(oldProtobuf.stream(), newProtobuf.stream()).collect(Collectors.toList()); String[] packageTokens = serviceName.split("\\."); return retval.stream().filter(s -> protoFilePackageMatches(s, packageTokens)).collect(Collectors.toList()); }
/** * Return a list of types that are sub-types of baseClass. The baseClass will not be included in * the list. */ public List<String> getTypes(Class<? extends Annotation> baseClass) { return ReflectionUtils.getInstance().getNamesOfSubclassesOf(baseClass); }
/** * Return a list of types that are sub-types of baseClass. The baseClass will not be included in * the list. */ public List<String> getTypes(Class<? extends Annotation> baseClass) { return ReflectionUtils.getInstance().getNamesOfSubclassesOf(baseClass); }
private List<String> findSubclasses(Class<?> clazz) { List<String> result = Collections.emptyList(); if (isNonFinalClass(clazz)) { result = scanCache.getNamesOfSubclassesOf(clazz); } return result; }
public static Set<Class> getSubtypes(List<Class> clazzes) throws InterruptedException, ExecutionException { Set<Class> classSet = new HashSet<Class>(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); Future<ScanResult> futureScan = new FastClasspathScanner("com.nextdoor.bender").scanAsync(pool, threads); ScanResult s = futureScan.get(); for (Class<? extends AbstractConfig<?>> clazz : clazzes) { s.getNamesOfSubclassesOf(clazz).forEach(c -> { try { classSet.add((Class<? extends AbstractConfig<?>>) Class.forName(c)); } catch (ClassNotFoundException e) { } }); } pool.shutdown(); /* * Remove abstract classes as they are not allowed in the mapper */ classSet.removeIf(p -> Modifier.isAbstract(p.getModifiers()) == true); return classSet; } }
public static Set<Class> getSubtypes(List<Class> clazzes) throws InterruptedException, ExecutionException { Set<Class> classSet = new HashSet<Class>(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); Future<ScanResult> futureScan = new FastClasspathScanner("com.nextdoor.bender").scanAsync(pool, threads); ScanResult s = futureScan.get(); for (Class<? extends AbstractConfig<?>> clazz : clazzes) { s.getNamesOfSubclassesOf(clazz).forEach(c -> { try { classSet.add((Class<? extends AbstractConfig<?>>) Class.forName(c)); } catch (ClassNotFoundException e) { } }); } pool.shutdown(); /* * Remove abstract classes as they are not allowed in the mapper */ classSet.removeIf(p -> Modifier.isAbstract(p.getModifiers()) == true); return classSet; } }
/** Return a set of sub types for the given super type. Scans the full classpath. */ @SuppressWarnings("unchecked") public static <T> Set<Class<? extends T>> getSubTypes(Class<T> superType) { if (scanResult == null) { getInstance(); } List<String> classNames; if (superType.isInterface()) { classNames = scanResult.getNamesOfClassesImplementing(superType); } else { classNames = scanResult.getNamesOfSubclassesOf(superType); } Set<Class<? extends T>> ret = new HashSet<>(); scanResult.classNamesToClassRefs(classNames).forEach(c -> ret.add((Class<? extends T>) c)); return ret; }
private static void ensureInit() { if (!init) { synchronized (BeanPopulators.class) { if (!init) { log.info("Init bean populators ..."); ScanResult result = AutumnClasspathScan.getScanResult(); result.getNamesOfSubclassesOf(AnnotatedFieldPopulator.class).forEach(cn -> { try { AnnotatedFieldPopulator<?> populator = (AnnotatedFieldPopulator<?>) result.classNameToClassRef(cn).newInstance(); annotatedFieldPopulatorMap.put(populator.getAnnotationClass(), populator); } catch (Exception e) { log.warn("Cannot init bean populator [{}]: {}", cn, String.valueOf(e)); } }); init = true; } } } }
/** Return a set of sub types for the given super type. Scans the full classpath. */ @SuppressWarnings("unchecked") public static <T> Set<Class<? extends T>> getSubTypes(Class<T> superType) { if (scanResult == null) { getInstance(); } List<String> classNames; if (superType.isInterface()) { classNames = scanResult.getNamesOfClassesImplementing(superType); } else { classNames = scanResult.getNamesOfSubclassesOf(superType); } Set<Class<? extends T>> ret = new HashSet<>(); scanResult.classNamesToClassRefs(classNames).forEach(c -> ret.add((Class<? extends T>) c)); return ret; }
/** Return a set of sub types for the given super type. Scans only the given package. */ @SuppressWarnings("unchecked") public static <T> Set<Class<? extends T>> getSubTypes(String packageName, Class<T> superType) { FastClasspathScanner scanner = new FastClasspathScanner(packageName); ScanResult sr = scanner.scan(); List<String> classNames; if (superType.isInterface()) { classNames = sr.getNamesOfClassesImplementing(superType); } else { classNames = sr.getNamesOfSubclassesOf(superType); } Set<Class<? extends T>> ret = new HashSet<>(); sr.classNamesToClassRefs(classNames).forEach(c -> ret.add((Class<? extends T>) c)); return ret; } }
/** Return a set of sub types for the given super type. Scans only the given package. */ @SuppressWarnings("unchecked") public static <T> Set<Class<? extends T>> getSubTypes(String packageName, Class<T> superType) { FastClasspathScanner scanner = new FastClasspathScanner(packageName); ScanResult sr = scanner.scan(); List<String> classNames; if (superType.isInterface()) { classNames = sr.getNamesOfClassesImplementing(superType); } else { classNames = sr.getNamesOfSubclassesOf(superType); } Set<Class<? extends T>> ret = new HashSet<>(); sr.classNamesToClassRefs(classNames).forEach(c -> ret.add((Class<? extends T>) c)); return ret; } }
result.getNamesOfSubclassesOf(Jooby.class) .stream() .filter(once) .forEach(k -> result.getNamesOfSubclassesOf(k) .stream() .filter(inPackage)
@Override public void lookForMatches(final ScanResult scanResult, final LogNode log) { final String superclassName = getStandardClassName(superclass); for (final String subclassName : scanResult.getNamesOfSubclassesOf(superclassName)) { LogNode subLog = null; if (log != null) { subLog = log.log("Matched subclass of " + superclassName + ": " + subclassName); } try { // Call classloader @SuppressWarnings("unchecked") final Class<? extends T> cls = (Class<? extends T>) loadClassForMatchProcessor(subclassName, scanResult, log); // Process match if (cls != null) { subclassMatchProcessor.processMatch(cls); } } catch (final Throwable e) { if (subLog != null) { subLog.log("Exception while processing match for class " + subclassName, e); } scanResult.addMatchProcessorException(e); } } } });