diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestions.java b/core/src/main/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestions.java index 22272064bd0c..413af6938a9a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestions.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestions.java @@ -42,7 +42,7 @@ public class ASTHelpersSuggestions extends BugChecker implements MethodInvocatio private static final Matcher 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 SCOPE = diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestionsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestionsTest.java index cc6b1a40f95c..eef7cf305835 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestionsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ASTHelpersSuggestionsTest.java @@ -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(); + } }