Skip to content

Commit

Permalink
Add support in ASTHelpersSuggestions for getEnclosedElements
Browse files Browse the repository at this point in the history
See #4026.  `Symbol.getEnclosedElements()` is another method that can cause compatibility issues across JDK versions (#3895).

Fixes #4027

COPYBARA_INTEGRATE_REVIEW=#4027 from msridhar:asthelperssuggestions-getenclosedelements b4c01ba
PiperOrigin-RevId: 552510760
  • Loading branch information
msridhar authored and Error Prone Team committed Jul 31, 2023
1 parent 29b0e54 commit bbf7cd9
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 bbf7cd9

Please sign in to comment.