/** * Get the names of all classes that implement (or have superclasses that implement) the given interface (or one * of its subinterfaces). * * @param implementedInterface * The interface. * @return The sorted list of the names of all classes that implement the given interface, or the empty list if * none. */ public List<String> getNamesOfClassesImplementing(final Class<?> implementedInterface) { return getNamesOfClassesImplementing(scanSpec.getInterfaceName(implementedInterface)); }
private List<String> findClassesImplementingInterface(Class<?> clazz) { List<String> result = Collections.emptyList(); if (isInterface(clazz)) { result = scanCache.getNamesOfClassesImplementing(clazz); } return result; }
/** * Get the names of all classes that implement (or have superclasses that implement) all of the named interfaces * (or their subinterfaces). * * @param implementedInterfaceNames * The names of the interfaces. * @return The sorted list of the names of all classes that implement all of the named interfaces, or the empty * list if none. */ public List<String> getNamesOfClassesImplementingAllOf(final String... implementedInterfaceNames) { final HashSet<String> classNames = new HashSet<>(); for (int i = 0; i < implementedInterfaceNames.length; i++) { final String implementedInterfaceName = implementedInterfaceNames[i]; final List<String> namesOfImplementingClasses = getNamesOfClassesImplementing(implementedInterfaceName); if (i == 0) { classNames.addAll(namesOfImplementingClasses); } else { classNames.retainAll(namesOfImplementingClasses); } } return new ArrayList<>(classNames); }
private static void ensureInit() { if (!init) { synchronized (BeanProcessors.class) { if (!init) { log.info("Init bean processors ..."); ScanResult result = AutumnClasspathScan.getScanResult(); result.getNamesOfClassesImplementing(BeanProcessor.class).forEach(cn -> { try { Class<? extends BeanProcessor> processorClass = (Class<? extends BeanProcessor>) result.classNameToClassRef(cn); BeanProcessor processor = processorClass.newInstance(); for (Class<?> intf : processorClass.getInterfaces()) { if (BeanProcessor.class.isAssignableFrom(intf)) { beanProcessors.computeIfAbsent((Class<? extends BeanProcessor>) intf, x -> new ArrayList<>()).add(processor); } } } catch (Exception e) { log.warn("Cannot init bean processor [{}]: {}", 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; }
public static void processAll(ScanSpec spec, AutumnContext context) { if (scanners == null) { synchronized (BeanScanners.class) { if (scanners == null) { log.info("Init bean scanners ..."); scanners = new ArrayList<>(); ScanResult result = AutumnClasspathScan.getScanResult(); result.getNamesOfClassesImplementing(BeanScanner.class).forEach(cn -> { try { scanners.add((BeanScanner) result.classNameToClassRef(cn).newInstance()); } catch (Exception e) { log.warn("Cannot init bean scanner [{}], {}", cn, String.valueOf(e)); } }); } } } scanners.forEach(sc -> sc.process(spec, context)); } }
/** 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; } }
.filter(I) .filter(type -> type != Jooby.Module.class && type != Module.class && type != Service.class) .forEach(i -> result.getNamesOfClassesImplementing(i) .stream() .filter(inPackage) result.getNamesOfClassesImplementing(Module.class) .stream() .filter(inPackage) result.getNamesOfClassesImplementing(Service.class) .stream() .filter(inPackage)
@Override public void lookForMatches(final ScanResult scanResult, final LogNode log) { final String implementedInterfaceName = getInterfaceName(implementedInterface); for (final String implementingClassName : scanResult .getNamesOfClassesImplementing(implementedInterfaceName)) { LogNode subLog = null; if (log != null) { subLog = log.log("Matched class implementing interface " + implementedInterfaceName + ": " + implementingClassName); } try { // Call classloader @SuppressWarnings("unchecked") final Class<? extends T> cls = (Class<? extends T>) loadClassForMatchProcessor( implementingClassName, scanResult, log); // Process match if (cls != null) { implementingClassMatchProcessor.processMatch(cls); } } catch (final Throwable e) { if (subLog != null) { subLog.log("Exception while processing match for class " + implementingClassName, e); } scanResult.addMatchProcessorException(e); } } } });