Skip to content

Commit

Permalink
Have ASTHelpersSuggestions handle subtypes of Symbol too.
Browse files Browse the repository at this point in the history
Fixes external #3482

PiperOrigin-RevId: 481926050
graememorgan authored and Error Prone Team committed Oct 18, 2022
1 parent db6459d commit 081f67e
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public class ASTHelpersSuggestions extends BugChecker implements MethodInvocatio

private static final Matcher<ExpressionTree> SYMBOL =
instanceMethod()
.onExactClass("com.sun.tools.javac.code.Symbol")
.onDescendantOf("com.sun.tools.javac.code.Symbol")
.namedAnyOf("isDirectlyOrIndirectlyLocal", "isLocal", "packge", "isStatic");

private static final Matcher<ExpressionTree> SCOPE =
Original file line number Diff line number Diff line change
@@ -56,4 +56,35 @@ public void positive() {
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
}

@Test
public void onSymbolSubtyle() {
testHelper
.addInputLines(
"Test.java",
"import com.sun.tools.javac.code.Symbol.VarSymbol;",
"class Test {",
" void f(VarSymbol s) {",
" s.isStatic();",
" s.packge();",
" s.members().anyMatch(x -> x.isStatic());",
" }",
"}")
.addOutputLines(
"Test.java",
"import static com.google.errorprone.util.ASTHelpers.enclosingPackage;",
"import static com.google.errorprone.util.ASTHelpers.isStatic;",
"import static com.google.errorprone.util.ASTHelpers.scope;",
"import com.sun.tools.javac.code.Symbol.VarSymbol;",
"class Test {",
" void f(VarSymbol s) {",
" isStatic(s);",
" enclosingPackage(s);",
" scope(s.members()).anyMatch(x -> isStatic(x));",
" }",
"}")
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
}
}

0 comments on commit 081f67e

Please sign in to comment.