From 3ac415254f64d27003a3c5b7a232a33fd785b1f9 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 19 Feb 2019 02:08:08 +0100 Subject: [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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/delombok/lombok/delombok/PrettyPrinter.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 84c342f0..353bd753 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -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 { -- cgit