From 6c2d9e3215642daf011105cc04063c06b54f6947 Mon Sep 17 00:00:00 2001 From: Austin Richardson Date: Thu, 7 Dec 2023 14:50:16 +0100 Subject: [PATCH] StaticImport: add `com.fasterxml.jackson.annotation.JsonCreator.Mode` --- .../errorprone/bugpatterns/StaticImport.java | 1 + .../bugpatterns/StaticImportTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) 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 3adb431a9c7..7bba20c7b9a 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 @@ -57,6 +57,7 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa @VisibleForTesting static final ImmutableSet STATIC_IMPORT_CANDIDATE_TYPES = ImmutableSet.of( + "com.fasterxml.jackson.annotation.JsonCreator.Mode", "com.google.common.base.Preconditions", "com.google.common.base.Predicates", "com.google.common.base.Verify", 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 bcfb097d399..29165a57121 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 @@ -40,6 +40,7 @@ void identification() { "import static java.util.function.Predicate.not;", "import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableMultiset;", @@ -109,6 +110,12 @@ void identification() { " @UseImportPolicy(ImportPolicy.IMPORT_TOP_LEVEL)", " void refasterAfterTemplate() {}", "", + " // BUG: Diagnostic contains:", + " @JsonCreator(mode = JsonCreator.Mode.DELEGATING)", + " private static A create(int a) {", + " return new A();", + " }", + "", " void toImmutableMultiset() {}", "}") .doTest(); @@ -121,6 +128,7 @@ void replacement() { "A.java", "import static java.util.function.Predicate.not;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableSet;", @@ -186,9 +194,16 @@ void replacement() { "", " @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)", " final class Test {}", + "", + " @JsonCreator(mode = JsonCreator.Mode.DELEGATING)", + " private static A create(int a) {", + " return new A();", + " }", + "", "}") .addOutputLines( "A.java", + "import static com.fasterxml.jackson.annotation.JsonCreator.Mode.DELEGATING;", "import static com.google.common.collect.ImmutableMap.toImmutableMap;", "import static com.google.common.collect.ImmutableSet.toImmutableSet;", "import static com.google.errorprone.BugPattern.LinkType.NONE;", @@ -208,6 +223,7 @@ void replacement() { "import static org.springframework.http.MediaType.APPLICATION_XHTML_XML;", "import static org.springframework.http.MediaType.TEXT_HTML;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableSet;", @@ -266,6 +282,12 @@ void replacement() { "", " @SpringBootTest(webEnvironment = RANDOM_PORT)", " final class Test {}", + "", + " @JsonCreator(mode = DELEGATING)", + " private static A create(int a) {", + " return new A();", + " }", + "", "}") .doTest(TestMode.TEXT_MATCH); }