Skip to content

Commit

Permalink
Suppress FieldCanBeLocal based on unused prefices.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 496985585
  • Loading branch information
graememorgan authored and Error Prone Team committed Dec 21, 2022
1 parent fd1748d commit 4a5fd7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public Void visitVariable(VariableTree variableTree, Void unused) {
if (symbol.getKind() == ElementKind.FIELD
&& symbol.isPrivate()
&& canBeLocal(variableTree)
&& !shouldKeep(variableTree)) {
&& !shouldKeep(variableTree)
&& !symbol.getSimpleName().toString().startsWith("unused")) {
potentialFields.put(symbol, getCurrentPath());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public void simplePositive() {
.doTest();
}

@Test
public void suppressedByUnusedPrefix() {
helper
.addSourceLines(
"Test.java",
"class Test {",
" private int unusedA;",
" int foo() {",
" unusedA = 1;",
" return unusedA;",
" }",
"}")
.doTest();
}

@Test
public void multipleAssignments() {
refactoringTestHelper
Expand Down

0 comments on commit 4a5fd7b

Please sign in to comment.