From 40ec9110319d9f0ca2b652e4e29c7f6899c28c85 Mon Sep 17 00:00:00 2001 From: Gijs de Jong Date: Wed, 17 Aug 2022 10:27:05 +0200 Subject: [PATCH] Add `Matchers` to StaticImport check --- .../tech/picnic/errorprone/bugpatterns/StaticImport.java | 1 + .../picnic/errorprone/bugpatterns/StaticImportTest.java | 6 ++++++ .../java/tech/picnic/errorprone/refaster/util/IsArray.java | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index 1edbc9f95c2..cf0ee74e8ee 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -66,6 +66,7 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa "com.google.errorprone.BugPattern.LinkType", "com.google.errorprone.BugPattern.SeverityLevel", "com.google.errorprone.BugPattern.StandardTags", + "com.google.errorprone.matchers.Matchers", "com.google.errorprone.refaster.ImportPolicy", "com.mongodb.client.model.Accumulators", "com.mongodb.client.model.Aggregates", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java index 76730bbcada..7397816f869 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java @@ -46,8 +46,11 @@ void identification() { "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableMultiset;", "import com.google.common.collect.ImmutableSet;", + "import com.google.errorprone.matchers.Matcher;", + "import com.google.errorprone.matchers.Matchers;", "import com.google.errorprone.refaster.ImportPolicy;", "import com.google.errorprone.refaster.annotation.UseImportPolicy;", + "import com.sun.source.tree.AnnotationTree;", "import java.nio.charset.StandardCharsets;", "import java.time.ZoneOffset;", "import java.util.Optional;", @@ -57,6 +60,9 @@ void identification() { "import org.springframework.http.MediaType;", "", "class A {", + " // BUG: Diagnostic contains:", + " private static final Matcher FOO = Matchers.isType(\"org.junit.jupiter.api.Test\");", + "", " void m() {", " // BUG: Diagnostic contains:", " ImmutableMap.toImmutableMap(v -> v, v -> v);", diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/util/IsArray.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/util/IsArray.java index 79cf1945a04..e3d60e6662f 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/util/IsArray.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/util/IsArray.java @@ -1,14 +1,15 @@ package tech.picnic.errorprone.refaster.util; +import static com.google.errorprone.matchers.Matchers.isArrayType; + import com.google.errorprone.VisitorState; import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; import com.sun.source.tree.ExpressionTree; /** A matcher of array-typed expressions, for use with Refaster's {@code @Matches} annotation. */ public final class IsArray implements Matcher { private static final long serialVersionUID = 1L; - private static final Matcher DELEGATE = Matchers.isArrayType(); + private static final Matcher DELEGATE = isArrayType(); @Override public boolean matches(ExpressionTree tree, VisitorState state) {