Search in sources :

Example 1 with BugChecker

use of com.google.errorprone.bugpatterns.BugChecker in project error-prone by google.

the class ErrorPronePlugins method loadPlugins.

public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);
    // ANNOTATION_PROCESSOR_PATH is unavailable.
    if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
        return scannerSupplier;
    }
    // Use the same classloader that Error Prone was loaded from to avoid classloader skew
    // when using Error Prone plugins together with the Error Prone javac plugin.
    JavacProcessingEnvironment processingEnvironment = JavacProcessingEnvironment.instance(context);
    ClassLoader loader = processingEnvironment.getProcessorClassLoader();
    Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader);
    if (Iterables.isEmpty(extraBugCheckers)) {
        return scannerSupplier;
    }
    return scannerSupplier.plus(ScannerSupplier.fromBugCheckerClasses(Iterables.transform(extraBugCheckers, BugChecker::getClass)));
}
Also used : JavaFileManager(javax.tools.JavaFileManager) BugChecker(com.google.errorprone.bugpatterns.BugChecker) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Aggregations

BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)1 JavaFileManager (javax.tools.JavaFileManager)1