Search in sources :

Example 11 with FastClasspathScanner

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;
}
Also used : FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)

Example 12 with FastClasspathScanner

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);
}
Also used : PrintWriter(java.io.PrintWriter) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) EnumMap(java.util.EnumMap) ScanResult(io.github.lukehutch.fastclasspathscanner.scanner.ScanResult) Logger(org.junit.platform.commons.logging.Logger) API(org.apiguardian.api.API) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Status(org.apiguardian.api.API.Status) Comparator(java.util.Comparator) EnumSet(java.util.EnumSet) Status(org.apiguardian.api.API.Status) ScanResult(io.github.lukehutch.fastclasspathscanner.scanner.ScanResult) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) ArrayList(java.util.ArrayList) Logger(org.junit.platform.commons.logging.Logger) API(org.apiguardian.api.API) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap)

Example 13 with FastClasspathScanner

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()]);
}
Also used : FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) HashSet(java.util.HashSet)

Aggregations

FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)13 ScanResult (io.github.lukehutch.fastclasspathscanner.scanner.ScanResult)3 UAVServer (com.creditease.monitor.UAVServer)2 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)2 ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)1 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)1 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)1 WebServiceListenerIT (com.creditease.uav.monitorframework.webservice.interceptors.WebServiceListenerIT)1 OrchidOption (com.eden.orchid.api.options.OrchidOption)1 AbstractModule (com.google.inject.AbstractModule)1 Provides (com.google.inject.Provides)1 Named (com.google.inject.name.Named)1 ClassAnnotationMatchProcessor (io.github.lukehutch.fastclasspathscanner.matchprocessor.ClassAnnotationMatchProcessor)1 PrintWriter (java.io.PrintWriter)1 Executable (java.lang.reflect.Executable)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1