Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't count identifier expressions as variable usages in StrictUnusedVariable check #2304

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import com.sun.source.tree.ReturnTree;
import com.sun.source.tree.StatementTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.TryTree;
import com.sun.source.tree.UnaryTree;
import com.sun.source.tree.VariableTree;
Expand Down Expand Up @@ -1054,7 +1055,9 @@ public Void visitIdentifier(IdentifierTree tree, Void unused) {

@Override
public Void visitMemberSelect(MemberSelectTree memberSelectTree, Void unused) {
usageSites.put(getSymbol(memberSelectTree), getCurrentPath());
if (!memberSelectTree.getExpression().getKind().equals(Kind.IDENTIFIER)) {
usageSites.put(getSymbol(memberSelectTree), getCurrentPath());
}
return super.visitMemberSelect(memberSelectTree, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public void handles_classes() {
.doTest();
}

@Test
public void handles_classes_ignoresIdentifierExpressions() {
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" private final String _field;",
" public Test(String value) {",
" this._field = value;",
" }",
"}")
.doTest();
}

@Test
public void handles_enums() {
compilationHelper
Expand Down
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-2304.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Don't count identifier expressions as variable usages in `StrictUnusedVariable`
check
links:
- https://github.com/palantir/gradle-baseline/pull/2304