Skip to content

Commit

Permalink
Add support for getEnclosedElements
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Jul 31, 2023
1 parent 29b0e54 commit b4c01ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}
}

0 comments on commit b4c01ba

Please sign in to comment.