Skip to content

Commit

Permalink
StaticImport: add com.fasterxml.jackson.annotation.JsonCreator.Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
arichapn committed Dec 7, 2023
1 parent ff3f963 commit 6c2d9e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa
@VisibleForTesting
static final ImmutableSet<String> 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down Expand Up @@ -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();
Expand All @@ -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;",
Expand Down Expand Up @@ -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;",
Expand All @@ -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;",
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6c2d9e3

Please sign in to comment.