From 4ce9f92489a88b2fd01551c2c92185a3ec34a4f0 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 30 Oct 2023 10:46:50 +0100 Subject: [PATCH] Disallow static import of `BugCheckerRefasctoringTestHelper.TestMode` members (#862) --- .../tech/picnic/errorprone/bugpatterns/NonStaticImport.java | 6 +++++- .../errorprone/refaster/test/RefasterRuleCollection.java | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java index 4c84992619..f913b93e09 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java @@ -58,7 +58,11 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit */ @VisibleForTesting static final ImmutableSet NON_STATIC_IMPORT_CANDIDATE_TYPES = - ImmutableSet.of("com.google.common.base.Strings", "java.time.Clock", "java.time.ZoneOffset"); + ImmutableSet.of( + "com.google.common.base.Strings", + "com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode", + "java.time.Clock", + "java.time.ZoneOffset"); /** * Type members that should never be statically imported. diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index e784140407..150a606429 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -4,7 +4,6 @@ import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet; -import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static java.util.Comparator.naturalOrder; import static tech.picnic.errorprone.refaster.runner.Refaster.INCLUDED_RULES_PATTERN_FLAG; @@ -19,6 +18,7 @@ import com.google.common.collect.Range; import com.google.common.collect.Sets; import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.BugPattern; import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.SubContext; @@ -126,7 +126,7 @@ public static void validate(Class clazz) { .setArgs(ImmutableList.of("-XepOpt:" + RULE_COLLECTION_FLAG + '=' + className)) .addInput(className + "TestInput.java") .addOutput(className + "TestOutput.java") - .doTest(TEXT_MATCH); + .doTest(TestMode.TEXT_MATCH); } @Override