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)));
}
Aggregations