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

Add support in ASTHelpersSuggestions for getEnclosedElements #4027

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -50,7 +50,8 @@ public class ASTHelpersSuggestions extends BugChecker implements MethodInvocatio
anyOf(
instanceMethod()
.onDescendantOf("com.sun.tools.javac.code.Symbol")
.namedAnyOf("isDirectlyOrIndirectlyLocal", "isLocal", "packge"),
.namedAnyOf(
"isDirectlyOrIndirectlyLocal", "isLocal", "packge", "getEnclosedElements"),
instanceMethod()
.onClass((t, s) -> isSubtype(MODULE_SYMBOL.get(s), t, s))
.namedAnyOf("isStatic"));
Expand Down
Expand Up @@ -87,4 +87,29 @@ public void onSymbolSubtype() {
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
}

@Test
public void symbolGetEnclosedElements() {
testHelper
.addInputLines(
"Test.java",
"import com.sun.tools.javac.code.Symbol.ClassSymbol;",
"class Test {",
" void f(ClassSymbol s) {",
" s.getEnclosedElements();",
" }",
"}")
.addOutputLines(
"Test.java",
"import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;",
"import com.sun.tools.javac.code.Symbol.ClassSymbol;",
"class Test {",
" void f(ClassSymbol s) {",
" getEnclosedElements(s);",
" }",
"}")
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
}
}