Skip to content

Commit

Permalink
BadImport: flag static import of newInstance methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Jan 8, 2023
1 parent 181f991 commit 40f116b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class BadImport extends BugChecker implements ImportTreeMatcher {
"getDefaultInstance",
"INSTANCE",
"newBuilder",
"newInstance",
"of",
"valueOf");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ public void positive_static_simpleCase() {
.doTest();
}

@Test
public void positive_identifiers() {
compilationTestHelper
.addSourceLines(
"Test.java",
"import static com.google.errorprone.CompilationTestHelper.newInstance;",
"import com.google.errorprone.CompilationTestHelper;",
"import com.google.errorprone.bugpatterns.BugChecker;",
"",
"class Test {",
" private final CompilationTestHelper compilationTestHelper =",
" // BUG: Diagnostic contains: CompilationTestHelper.newInstance",
" newInstance(BugChecker.class, getClass());",
"}")
.doTest();
}

@Test
public void msg() {
compilationTestHelper
Expand Down

0 comments on commit 40f116b

Please sign in to comment.