Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: google/error-prone
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: HubSpot/error-prone
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: hubspot
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Jun 22, 2021

  1. Include both the current classloader along with the annotation processor

    This allows one to not use the annotation processor method of including
    extra checks.
    axiak authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    aba1180 View commit details
  2. Add a hubspot import organizer.

    This patch enables ` -XepPatchImportOrder:hubspot` to be specified, which
    makes it so that suggestions that mutate imports will preserve the HubSpot
    style guide.
    axiak authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    1a100e0 View commit details
  3. fix build

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    1f21ffb View commit details
  4. updates

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    372db34 View commit details
  5. fix dep

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    7232e2b View commit details
  6. Add the ability to define custom description listeners

    This will make it easy for us to integrate with whatever build
    tooling we need, such as Sir Jester
    axiak authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    d809d06 View commit details
  7. Add the compilation unit to the resources

    This can be useful when generating diffs
    axiak authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    fa629f0 View commit details
  8. add error-prone flags to context

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    5c50e17 View commit details
  9. catch check failures

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    aaeaf5b View commit details
  10. space

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    f3bee70 View commit details
  11. refactor, give more memory

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    4f5f21b View commit details
  12. even moar memory

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    977044d View commit details
  13. even moar memory

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    3438b76 View commit details
  14. remove this

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    0802414 View commit details
  15. refactor into separate class

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    3fb239f View commit details
  16. space

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    33cb1c9 View commit details
  17. fix build

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    10d3468 View commit details
  18. more resources

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    30bb766 View commit details
  19. use the right type token

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    809ec8e View commit details
  20. unused imports

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    30a59e6 View commit details
  21. handle missing checks

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    62c2872 View commit details
  22. use camelCase

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    a628ebd View commit details
  23. Add extra test for generics in placeholders

    Xcelled authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    97060cf View commit details
  24. Match anonymous classes in placeholders

    Xcelled authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    c43fc49 View commit details
  25. handle init errors

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    8293640 View commit details
  26. pass in options

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    f27f09d View commit details
  27. its a throwable

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    15a2c8c View commit details
  28. fix checks

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    82377d0 View commit details
  29. add hidden severity

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    b02d21e View commit details
  30. update plugin

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    f6ccd02 View commit details
  31. update blazar yaml

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    a538d5e View commit details
  32. fix branch

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    be3fb0d View commit details
  33. add back deleted method

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    d6e6f61 View commit details
  34. update path resolution

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    dde1cca View commit details
  35. fix test

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    b8e76ec View commit details
  36. Disable throwing on re-setting args

    Megan Ketelaar authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    440bb77 View commit details
  37. add dynamic enum

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    14242e9 View commit details
  38. update to use Severity enum

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    5b59d89 View commit details
  39. remove severity level

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    d6503d2 View commit details
  40. add metadata

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    e0e7123 View commit details
  41. use a map

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    0a79bfb View commit details
  42. update get

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    195a824 View commit details
  43. fix null

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    6f7dc22 View commit details
  44. use immutable map

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    db33807 View commit details
  45. make this optional

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    458fa9a View commit details
  46. improve error handling

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    f26d220 View commit details
  47. Account for backport of Java13 fix to Java 11

    Megan Ketelaar authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    c535831 View commit details
  48. record timings

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    3fd2796 View commit details
  49. update timings storage

    kmclarnon committed Jun 22, 2021
    Copy the full SHA
    af00552 View commit details
  50. Update .blazar.yaml

    stevie400 authored and kmclarnon committed Jun 22, 2021
    Copy the full SHA
    fa2a280 View commit details
Showing with 2,228 additions and 171 deletions.
  1. +9 −0 .blazar.yaml
  2. 0 .build-jdk17
  3. +12 −0 annotation/.blazar.yaml
  4. +1 −1 annotation/pom.xml
  5. +4 −0 annotation/src/main/java/com/google/errorprone/BugPattern.java
  6. +12 −0 annotations/.blazar.yaml
  7. +1 −1 annotations/pom.xml
  8. +13 −0 check_api/.blazar.yaml
  9. +26 −1 check_api/pom.xml
  10. +12 −4 check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java
  11. +10 −0 check_api/src/main/java/com/google/errorprone/BugCheckerInfo.java
  12. +11 −5 check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
  13. +2 −0 check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java
  14. +27 −20 check_api/src/main/java/com/google/errorprone/ErrorPronePlugins.java
  15. +1 −0 check_api/src/main/java/com/google/errorprone/ImportOrderParser.java
  16. +18 −33 check_api/src/main/java/com/google/errorprone/JavacErrorDescriptionListener.java
  17. +4 −2 check_api/src/main/java/com/google/errorprone/RefactoringCollection.java
  18. +25 −5 check_api/src/main/java/com/google/errorprone/SuppressionInfo.java
  19. +61 −0 check_api/src/main/java/com/google/errorprone/apply/HubSpotImportOrganizer.java
  20. +2 −0 check_api/src/main/java/com/google/errorprone/apply/ImportOrganizer.java
  21. +17 −1 check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java
  22. +7 −0 ...api/src/main/java/com/google/errorprone/descriptionlistener/CustomDescriptionListenerFactory.java
  23. +21 −0 check_api/src/main/java/com/google/errorprone/descriptionlistener/DescriptionListenerResources.java
  24. +88 −0 check_api/src/main/java/com/google/errorprone/descriptionlistener/DescriptionListeners.java
  25. +13 −0 ...in/java/com/google/errorprone/descriptionlistener/JavacErrorCustomDescriptionListenerFactory.java
  26. +108 −0 check_api/src/main/java/com/google/errorprone/hubspot/FileManager.java
  27. +72 −0 check_api/src/main/java/com/google/errorprone/hubspot/HubSpotErrorProneAnalyzer.java
  28. +136 −0 check_api/src/main/java/com/google/errorprone/hubspot/HubSpotLifecycleManager.java
  29. +161 −0 check_api/src/main/java/com/google/errorprone/hubspot/HubSpotMetrics.java
  30. +49 −0 check_api/src/main/java/com/google/errorprone/hubspot/HubSpotPatchUtils.java
  31. +165 −0 check_api/src/main/java/com/google/errorprone/hubspot/HubSpotUtils.java
  32. +36 −0 check_api/src/main/java/com/google/errorprone/hubspot/JsonUtils.java
  33. +171 −0 ..._api/src/main/java/com/google/errorprone/hubspot/module/CompilationEndAwareErrorPoneAnalyzer.java
  34. +21 −0 check_api/src/main/java/com/google/errorprone/hubspot/module/ModuleAwareChecker.java
  35. +67 −0 check_api/src/main/java/com/google/errorprone/hubspot/module/ModuleDescription.java
  36. +80 −0 check_api/src/main/java/com/google/errorprone/hubspot/module/ModuleState.java
  37. +51 −4 check_api/src/main/java/com/google/errorprone/matchers/Description.java
  38. +5 −0 check_api/src/main/java/com/google/errorprone/matchers/Suppressible.java
  39. +20 −2 check_api/src/main/java/com/google/errorprone/scanner/ErrorProneScanner.java
  40. +11 −3 check_api/src/main/java/com/google/errorprone/scanner/Scanner.java
  41. +12 −0 check_api/src/main/java/com/google/errorprone/scanner/ScannerSupplier.java
  42. +47 −0 check_api/src/test/java/com/google/errorprone/HubSpotPatchUtilsTest.java
  43. +21 −0 core/.blazar.yaml
  44. +1 −1 core/pom.xml
  45. +13 −2 core/src/main/java/com/google/errorprone/ErrorProneJavacPlugin.java
  46. +1 −1 core/src/main/java/com/google/errorprone/bugpatterns/CheckReturnValue.java
  47. +37 −1 core/src/main/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlock.java
  48. +2 −2 core/src/main/java/com/google/errorprone/bugpatterns/FutureReturnValueIgnored.java
  49. +1 −1 core/src/main/java/com/google/errorprone/bugpatterns/MathAbsoluteNegative.java
  50. +10 −3 core/src/main/java/com/google/errorprone/bugpatterns/UnusedMethod.java
  51. +13 −4 core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java
  52. +199 −0 core/src/main/java/com/google/errorprone/refaster/HubSpotPretty.java
  53. +28 −3 core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java
  54. +2 −50 core/src/main/java/com/google/errorprone/refaster/Template.java
  55. +2 −1 core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java
  56. +9 −0 core/src/test/java/com/google/errorprone/bugpatterns/BugCheckerTest.java
  57. +75 −0 core/src/test/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlockTest.java
  58. +1 −0 core/src/test/java/com/google/errorprone/bugpatterns/RestrictedApiCheckerTest.java
  59. +5 −0 core/src/test/java/com/google/errorprone/refaster/TemplateIntegrationTest.java
  60. +34 −0 ...m/google/errorprone/refaster/testdata/input/PlaceholderSupportsAnonymousClassTemplateExample.java
  61. +1 −1 core/src/test/java/com/google/errorprone/refaster/testdata/output/AsVarargsTemplateExample.java
  62. +2 −2 core/src/test/java/com/google/errorprone/refaster/testdata/output/InferLambdaBodyTypeExample.java
  63. +2 −2 core/src/test/java/com/google/errorprone/refaster/testdata/output/InferLambdaTypeExample.java
  64. +1 −1 core/src/test/java/com/google/errorprone/refaster/testdata/output/LambdaImplicitTypeExample.java
  65. +34 −0 .../google/errorprone/refaster/testdata/output/PlaceholderSupportsAnonymousClassTemplateExample.java
  66. +1 −1 .../src/test/java/com/google/errorprone/refaster/testdata/output/UnnecessaryLambdaParensExample.java
  67. +1 −1 ...java/com/google/errorprone/refaster/testdata/output/VoidExpressionPlaceholderTemplateExample.java
  68. +53 −0 ...a/com/google/errorprone/refaster/testdata/template/PlaceholderSupportsAnonymousClassTemplate.java
  69. +14 −0 docgen/.blazar.yaml
  70. +1 −1 docgen/pom.xml
  71. +12 −0 docgen_processor/.blazar.yaml
  72. +1 −1 docgen_processor/pom.xml
  73. +1 −2 pom.xml
  74. +12 −0 refaster/.blazar.yaml
  75. +1 −1 refaster/pom.xml
  76. +14 −0 test_helpers/.blazar.yaml
  77. +1 −1 test_helpers/pom.xml
  78. +0 −5 test_helpers/src/main/java/com/google/errorprone/CompilationTestHelper.java
  79. +12 −0 type_annotations/.blazar.yaml
  80. +1 −1 type_annotations/pom.xml
9 changes: 9 additions & 0 deletions .blazar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
buildpack:
name: Blazar-Buildpack-Java

provides:
- parent

env:
SET_VERSION_OVERRIDE: "2.36.0-$GIT_BRANCH-SNAPSHOT"

Empty file added .build-jdk17
Empty file.
12 changes: 12 additions & 0 deletions annotation/.blazar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
buildpack:
name: Blazar-Buildpack-Java

provides:
- annotation

depends:
- annotations

env:
SET_VERSION_OVERRIDE: "2.36.0-$GIT_BRANCH-SNAPSHOT"

2 changes: 1 addition & 1 deletion annotation/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>1.0-HEAD-SNAPSHOT</version>
<version>2.36.0</version>
</parent>

<name>@BugPattern annotation</name>
Original file line number Diff line number Diff line change
@@ -155,6 +155,7 @@ enum SeverityLevel {
WARNING,
/** Note that this level generally disables the bug checker. */
SUGGESTION,
HIDDEN
}

/** True if the check can be disabled using command-line flags. */
@@ -171,6 +172,9 @@ enum SeverityLevel {
*/
Class<? extends Annotation>[] suppressionAnnotations() default SuppressWarnings.class;

/** True if this check should be invoked on generated code */
boolean inspectGeneratedCode() default false;

/**
* Generate an explanation of how to suppress the check.
*
12 changes: 12 additions & 0 deletions annotations/.blazar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
buildpack:
name: Blazar-Buildpack-Java

provides:
- annotations

depends:
- parent

env:
SET_VERSION_OVERRIDE: "2.36.0-$GIT_BRANCH-SNAPSHOT"

2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>1.0-HEAD-SNAPSHOT</version>
<version>2.36.0</version>
</parent>

<name>error-prone annotations</name>
13 changes: 13 additions & 0 deletions check_api/.blazar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
buildpack:
name: Blazar-Buildpack-Java

provides:
- check_api

depends:
- annotation
- annotations

env:
SET_VERSION_OVERRIDE: "2.36.0-$GIT_BRANCH-SNAPSHOT"

27 changes: 26 additions & 1 deletion check_api/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>1.0-HEAD-SNAPSHOT</version>
<version>2.36.0</version>
</parent>

<name>error-prone check api</name>
@@ -61,6 +61,13 @@
<artifactId>java-diff-utils</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<!-- Apache 2.0 -->
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc4</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- Apache 2.0 -->
<groupId>com.google.auto.value</groupId>
@@ -129,6 +136,24 @@
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>

<!-- Hubspot deps -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>2.12.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.12.5</version>
</dependency>

<dependency>
<!-- Apache 2.0 -->
<groupId>com.google.jimfs</groupId>
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.RefactoringCollection.RefactoringResult;
import com.google.errorprone.hubspot.HubSpotErrorProneAnalyzer;
import com.google.errorprone.scanner.ErrorProneScannerTransformer;
import com.google.errorprone.scanner.ScannerSupplier;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.BasicJavacTask;
@@ -38,7 +42,6 @@
import javax.lang.model.SourceVersion;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
@@ -83,13 +86,18 @@ public CompilationTask getTask(
static void addTaskListener(
JavacTask javacTask, ScannerSupplier scannerSupplier, ErrorProneOptions errorProneOptions) {
Context context = ((BasicJavacTask) javacTask).getContext();
context.put(ErrorProneOptions.class, errorProneOptions);
checkCompilePolicy(Options.instance(context).get("compilePolicy"));
checkShouldStopIfErrorPolicy(Options.instance(context).get("should-stop.ifError"));
setupMessageBundle(context);
RefactoringCollection[] refactoringCollection = {null};
javacTask.addTaskListener(
ErrorProneAnalyzer.createAnalyzer(
scannerSupplier, errorProneOptions, context, refactoringCollection));
if (errorProneOptions.patchingOptions().doRefactor()) {
javacTask.addTaskListener(
ErrorProneAnalyzer.createAnalyzer(scannerSupplier, errorProneOptions, context, refactoringCollection));
} else {
javacTask.addTaskListener(
HubSpotErrorProneAnalyzer.create(scannerSupplier, errorProneOptions, context));
}
if (refactoringCollection[0] != null) {
javacTask.addTaskListener(
new ErrorProneAnalyzer.RefactoringTask(context, refactoringCollection[0]));
10 changes: 10 additions & 0 deletions check_api/src/main/java/com/google/errorprone/BugCheckerInfo.java
Original file line number Diff line number Diff line change
@@ -74,6 +74,8 @@ public class BugCheckerInfo implements Serializable {

private final boolean supportsSuppressWarnings;

private final boolean inspectGeneratedCode;

/**
* A set of suppression annotations for this check. Computed from the {@code
* suppressionAnnotations} attributes from its {@code BugPattern}. May be empty if there are no
@@ -116,6 +118,7 @@ private BugCheckerInfo(
pattern.severity(),
createLinkUrl(canonicalName, pattern),
Stream.of(pattern.suppressionAnnotations()).anyMatch(a -> isSuppressWarnings(a)),
pattern.inspectGeneratedCode(),
Stream.of(pattern.suppressionAnnotations())
.filter(a -> !isSuppressWarnings(a))
.collect(toImmutableSet()),
@@ -131,6 +134,7 @@ private BugCheckerInfo(
SeverityLevel defaultSeverity,
String linkUrl,
boolean supportsSuppressWarnings,
boolean inspectGeneratedCode,
Set<Class<? extends Annotation>> customSuppressionAnnotations,
ImmutableSet<String> tags,
boolean disableable) {
@@ -141,6 +145,7 @@ private BugCheckerInfo(
this.defaultSeverity = defaultSeverity;
this.linkUrl = linkUrl;
this.supportsSuppressWarnings = supportsSuppressWarnings;
this.inspectGeneratedCode = inspectGeneratedCode;
this.customSuppressionAnnotations = customSuppressionAnnotations;
this.tags = tags;
this.disableable = disableable;
@@ -167,6 +172,7 @@ public BugCheckerInfo withCustomDefaultSeverity(SeverityLevel defaultSeverity) {
defaultSeverity,
linkUrl,
supportsSuppressWarnings,
inspectGeneratedCode,
customSuppressionAnnotations,
tags,
disableable);
@@ -227,6 +233,10 @@ public Set<Class<? extends Annotation>> customSuppressionAnnotations() {
return Collections.unmodifiableSet(customSuppressionAnnotations);
}

public boolean inspectGeneratedCode() {
return inspectGeneratedCode;
}

public boolean disableable() {
return disableable;
}
Original file line number Diff line number Diff line change
@@ -24,6 +24,10 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.errorprone.descriptionlistener.DescriptionListeners;
import com.google.errorprone.hubspot.HubSpotLifecycleManager;
import com.google.errorprone.hubspot.HubSpotMetrics;
import com.google.errorprone.hubspot.HubSpotUtils;
import com.google.errorprone.RefactoringCollection.RefactoringResult;
import com.google.errorprone.scanner.ErrorProneScannerTransformer;
import com.google.errorprone.scanner.ScannerSupplier;
@@ -80,7 +84,7 @@ public static ErrorProneAnalyzer createAnalyzer(
Suppliers.memoize(
() -> {
ScannerSupplier toUse =
ErrorPronePlugins.loadPlugins(scannerSupplier, context);
ErrorPronePlugins.loadPlugins(scannerSupplier, epOptions, context);
ImmutableSet<String> namedCheckers =
epOptions.patchingOptions().namedCheckers();
if (!namedCheckers.isEmpty()) {
@@ -133,11 +137,12 @@ public void finished(TaskEvent event) {

public static ErrorProneAnalyzer createByScanningForPlugins(
ScannerSupplier scannerSupplier, ErrorProneOptions errorProneOptions, Context context) {
context.put(ErrorProneFlags.class, errorProneOptions.getFlags());
return new ErrorProneAnalyzer(
scansPlugins(scannerSupplier, errorProneOptions, context),
errorProneOptions,
context,
JavacErrorDescriptionListener.provider(context));
DescriptionListeners.factory(context));
}

private static Supplier<CodeTransformer> scansPlugins(
@@ -149,7 +154,7 @@ private static Supplier<CodeTransformer> scansPlugins(
ErrorProneTimings timings = ErrorProneTimings.instance(context);
try (AutoCloseable unused = timings.initializationTimeSpan()) {
return ErrorProneScannerTransformer.create(
ErrorPronePlugins.loadPlugins(scannerSupplier, context)
ErrorPronePlugins.loadPlugins(scannerSupplier, errorProneOptions, context)
.applyOverrides(errorProneOptions)
.get());
} catch (InvalidCommandLineOptionException e) {
@@ -166,11 +171,12 @@ static ErrorProneAnalyzer createWithCustomDescriptionListener(
ErrorProneOptions errorProneOptions,
Context context,
DescriptionListener.Factory descriptionListenerFactory) {
context.put(ErrorProneFlags.class, errorProneOptions.getFlags());
return new ErrorProneAnalyzer(
codeTransformer, errorProneOptions, context, descriptionListenerFactory);
}

private ErrorProneAnalyzer(
public ErrorProneAnalyzer(
Supplier<CodeTransformer> transformer,
ErrorProneOptions errorProneOptions,
Context context,
@@ -180,7 +186,6 @@ private ErrorProneAnalyzer(
this.descriptionListenerFactory = checkNotNull(descriptionListenerFactory);

Context errorProneContext = new SubContext(context);
errorProneContext.put(ErrorProneOptions.class, errorProneOptions);
this.context = errorProneContext;
}

@@ -246,6 +251,7 @@ public void finished(TaskEvent taskEvent) {
log.error("proc.cant.access", e.sym, getDetailValue(e), getStackTraceAsString(e));
} finally {
log.useSource(originalSource);
HubSpotMetrics.instance(context).recordTimings(context);
}
}

Original file line number Diff line number Diff line change
@@ -98,7 +98,9 @@ public boolean isDisableAllChecks() {
*/
public enum Severity {
DEFAULT, // whatever is specified in the @BugPattern annotation
DYNAMIC,
OFF,
HIDDEN,
WARN,
ERROR
}
Original file line number Diff line number Diff line change
@@ -16,39 +16,46 @@

package com.google.errorprone;

import static com.google.common.collect.ImmutableList.toImmutableList;
import java.util.ServiceLoader;

import javax.tools.JavaFileManager;
import javax.tools.StandardLocation;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.hubspot.HubSpotUtils;
import com.google.errorprone.scanner.ScannerSupplier;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.Context;
import java.util.ServiceLoader;
import javax.tools.JavaFileManager;
import javax.tools.StandardLocation;

/** Loads custom Error Prone checks from the annotation processor classpath. */
public final class ErrorPronePlugins {

public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) {
public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, ErrorProneOptions options, Context context) {
JavaFileManager fileManager = context.get(JavaFileManager.class);
// Unlike in annotation processor discovery, we never search CLASS_PATH if
// ANNOTATION_PROCESSOR_PATH is unavailable.
if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
return scannerSupplier;

ClassLoader loader;

if (fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
// If the annotation processor path is available, just use that.
JavacProcessingEnvironment processingEnvironment = JavacProcessingEnvironment.instance(context);
loader = processingEnvironment.getProcessorClassLoader();
} else {
loader = ErrorPronePlugins.class.getClassLoader();
}
// 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();
ImmutableList<Class<? extends BugChecker>> extraBugCheckers =
ServiceLoader.load(BugChecker.class, loader).stream()
.map(ServiceLoader.Provider::type)
.collect(toImmutableList());
if (extraBugCheckers.isEmpty()) {

// The upstream version that creates a list throws an exception
// by too-eagerly resolving the bug checkers
Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader);
if (Iterables.isEmpty(extraBugCheckers)) {
return scannerSupplier;
} else if (HubSpotUtils.isErrorHandlingEnabled(options)) {
return scannerSupplier.plus(HubSpotUtils.createScannerSupplier(extraBugCheckers));
} else {
return scannerSupplier.plus(
ScannerSupplier.fromBugCheckerClasses(
Iterables.transform(extraBugCheckers, BugChecker::getClass)));
}
return scannerSupplier.plus(ScannerSupplier.fromBugCheckerClasses(extraBugCheckers));
}

private ErrorPronePlugins() {}
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ public static ImportOrganizer getImportOrganizer(String importOrder) {
case "android-static-first" -> ImportOrganizer.ANDROID_STATIC_FIRST_ORGANIZER;
case "android-static-last" -> ImportOrganizer.ANDROID_STATIC_LAST_ORGANIZER;
case "idea" -> ImportOrganizer.IDEA_ORGANIZER;
case "hubspot" -> ImportOrganizer.HUBSPOT_IMPORT_ORGANIZER;
default -> throw new IllegalStateException("Unknown import order: '" + importOrder + "'");
};
}
Loading