Skip to content

Commit

Permalink
StaticImport: add com.google.errorprone.BugPattern.* candidates
Browse files Browse the repository at this point in the history
To be specific: `LinkType`, `SeverityLevel`, and `StandardTags`.
  • Loading branch information
rickie committed Jan 22, 2022
1 parent 63b4fae commit ba00870
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package tech.picnic.errorprone.bugpatterns;

import static com.google.errorprone.BugPattern.LinkType.NONE;
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION;
import static java.util.Objects.requireNonNull;

import com.google.auto.service.AutoService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.errorprone.BugPattern;
import com.google.errorprone.BugPattern.LinkType;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.errorprone.BugPattern.StandardTags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.MemberSelectTreeMatcher;
Expand Down Expand Up @@ -47,9 +47,9 @@
@BugPattern(
name = "StaticImport",
summary = "Identifier should be statically imported",
linkType = LinkType.NONE,
severity = SeverityLevel.SUGGESTION,
tags = StandardTags.SIMPLIFICATION)
linkType = NONE,
severity = SUGGESTION,
tags = SIMPLIFICATION)
public final class StaticImportCheck extends BugChecker implements MemberSelectTreeMatcher {
private static final long serialVersionUID = 1L;

Expand All @@ -64,6 +64,9 @@ public final class StaticImportCheck extends BugChecker implements MemberSelectT
"com.google.common.base.Predicates",
"com.google.common.base.Verify",
"com.google.common.collect.MoreCollectors",
"com.google.errorprone.BugPattern.LinkType",
"com.google.errorprone.BugPattern.SeverityLevel",
"com.google.errorprone.BugPattern.StandardTags",
"com.mongodb.client.model.Accumulators",
"com.mongodb.client.model.Aggregates",
"com.mongodb.client.model.Filters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void replacement() {
"import com.google.common.base.Predicates;",
"import com.google.common.collect.ImmutableMap;",
"import com.google.common.collect.ImmutableSet;",
"import com.google.errorprone.BugPattern;",
"import com.google.errorprone.BugPattern.SeverityLevel;",
"import java.nio.charset.StandardCharsets;",
"import java.util.Objects;",
"import org.junit.jupiter.params.provider.Arguments;",
Expand Down Expand Up @@ -155,13 +157,24 @@ void replacement() {
" @DateTimeFormat(iso = ISO.DATE_TIME) String dateTime,",
" @DateTimeFormat(iso = ISO.TIME) String time) {}",
"",
" @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)",
" final class Test {}",
" @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)",
" final class Test {}",
"",
" @BugPattern(",
" name = \"TestBugChecker\",",
" summary = \"\",",
" linkType = BugPattern.LinkType.NONE,",
" severity = SeverityLevel.SUGGESTION,",
" tags = BugPattern.StandardTags.SIMPLIFICATION)",
" static class TestBugChecker {}",
"}")
.addOutputLines(
"out/A.java",
"import static com.google.common.collect.ImmutableMap.toImmutableMap;",
"import static com.google.common.collect.ImmutableSet.toImmutableSet;",
"import static com.google.errorprone.BugPattern.LinkType.NONE;",
"import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;",
"import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION;",
"import static java.nio.charset.StandardCharsets.UTF_8;",
"import static java.util.Objects.requireNonNull;",
"import static java.util.function.Predicate.not;",
Expand All @@ -176,6 +189,8 @@ void replacement() {
"import com.google.common.base.Predicates;",
"import com.google.common.collect.ImmutableMap;",
"import com.google.common.collect.ImmutableSet;",
"import com.google.errorprone.BugPattern;",
"import com.google.errorprone.BugPattern.SeverityLevel;",
"import java.nio.charset.StandardCharsets;",
"import java.util.Objects;",
"import org.junit.jupiter.params.provider.Arguments;",
Expand Down Expand Up @@ -219,8 +234,16 @@ void replacement() {
" @DateTimeFormat(iso = DATE_TIME) String dateTime,",
" @DateTimeFormat(iso = TIME) String time) {}",
"",
" @SpringBootTest(webEnvironment = RANDOM_PORT)",
" final class Test {}",
" @SpringBootTest(webEnvironment = RANDOM_PORT)",
" final class Test {}",
"",
" @BugPattern(",
" name = \"TestBugChecker\",",
" summary = \"\",",
" linkType = NONE,",
" severity = SUGGESTION,",
" tags = SIMPLIFICATION)",
" static class TestBugChecker {}",
"}")
.doTest(TestMode.TEXT_MATCH);
}
Expand Down

0 comments on commit ba00870

Please sign in to comment.