[fixes #1997] try-with-resources where the thing you’re guarding is just a variable ref instead of a full decl (legal since JDK9) would break delombok

This commit is contained in:
Reinier Zwitserloot committed 2019-02-19 02:08:14 +01:00
1 parent 8479edb426
commit 3ac415254f
3 files changed
+33 -5

No files matched your search

@@ -1268,9 +1268,14 @@ public class PrettyPrinter extends JCTree.Visitor {
break;
case 1:
print("(");
JCVariableDecl decl = (JCVariableDecl) resources.get(0);
flagMod = -1L & ~FINAL;
printVarDefInline(decl);
JCTree resource = (JCTree) resources.get(0);
if (resource instanceof JCVariableDecl) {
JCVariableDecl decl = (JCVariableDecl) resource;
flagMod = -1L & ~FINAL;
printVarDefInline(decl);
} else {
print(resource);
}
print(") ");
break;
default:
@@ -1279,8 +1284,12 @@ public class PrettyPrinter extends JCTree.Visitor {
int c = 0;
for (Object i : resources) {
align();
flagMod = -1L & ~FINAL;
printVarDefInline((JCVariableDecl) i);
if (i instanceof JCVariableDecl) {
flagMod = -1L & ~FINAL;
printVarDefInline((JCVariableDecl) i);
} else {
print((JCTree) i);
}
if (++c == len) {
print(") ");
} else {
@@ -0,0 +1,9 @@
import java.io.PrintWriter;
public class TryWithResourcesVarRef {
{
PrintWriter pw = new PrintWriter(System.out);
try (pw) {
pw.println();
}
}
}
@@ -0,0 +1,10 @@
//version 9:
import java.io.PrintWriter;
public class TryWithResourcesVarRef {
{
PrintWriter pw = new PrintWriter(System.out);
try (pw) {
pw.println();
}
}
}