diff options
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 28 | ||||
-rw-r--r-- | test/pretty/resource/after/TryWithResources.java | 9 | ||||
-rw-r--r-- | test/pretty/resource/before/TryWithResources.java | 9 |
4 files changed, 47 insertions, 0 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a3ac5ea4..043e524e 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -7,6 +7,7 @@ Lombok Changelog * FEATURE: Added support for Log4j v2.0 via `@Log4j2` [Issue #432](http://code.google.com/p/projectlombok/issues/detail?id=432) * ENHANCEMENT: The Lombok installer can now find and install lombok into [JBoss Developer Studio](http://www.redhat.com/products/jbossenterprisemiddleware/developer-studio/). The installer will now also look for eclipse and eclipse variants in your home directory. [Issue #434](http://code.google.com/p/projectlombok/issues/detail?id=432) * BUGFIX: `@ExtensionMethods` no longer causes `VerifyError` exceptions when running eclipse-compiled code if extension methods are called on expressions which are method calls whose return type is a type variable. For example, `someList.get(i).extensionMethod()` would fail that way. [Issue #436](http://code.google.com/p/projectlombok/issues/detail?id=436) +* BUGFIX: java 7's try-with-resources statement did not delombok correctly. [Issue #459](http://code.google.com/p/projectlombok/issues/detail?id=459) ### v0.11.6 (October 30th, 2012) * FEATURE: Lombok can be disabled entirely for any given compile run by using JVM switch `-Dlombok.disable`. This might be useful for code style checkers and such. diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index 6e9a1c94..9c6a2bd7 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -22,6 +22,11 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ + +/* + * Code derived from com.sun.tools.javac.tree.Pretty, from the langtools project. + * A version can be found at, for example, http://hg.openjdk.java.net/jdk7/build/langtools + */ package lombok.delombok; import static com.sun.tools.javac.code.Flags.ANNOTATION; @@ -981,6 +986,29 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitTry(JCTry tree) { try { print("try "); + List<?> resources = null; + try { + Field f = JCTry.class.getField("resources"); + resources = (List<?>) f.get(tree); + } catch (Exception ignore) { + // In JDK6 and down this field does not exist; resources will retain its initializer value which is what we want. + } + + if (resources != null && resources.nonEmpty()) { + boolean first = true; + print("("); + for (Object var0 : resources) { + JCTree var = (JCTree) var0; + if (!first) { + println(); + indent(); + } + printStat(var); + first = false; + } + print(") "); + } + printStat(tree.body); for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { printStat(l.head); diff --git a/test/pretty/resource/after/TryWithResources.java b/test/pretty/resource/after/TryWithResources.java new file mode 100644 index 00000000..1a8b82e2 --- /dev/null +++ b/test/pretty/resource/after/TryWithResources.java @@ -0,0 +1,9 @@ +//version 7: +import java.io.PrintWriter; +public class TryWithResources { + { + try (final PrintWriter pw = new PrintWriter(System.out);) { + pw.println(); + } + } +} diff --git a/test/pretty/resource/before/TryWithResources.java b/test/pretty/resource/before/TryWithResources.java new file mode 100644 index 00000000..eb622f2c --- /dev/null +++ b/test/pretty/resource/before/TryWithResources.java @@ -0,0 +1,9 @@ +//version 7: +import java.io.PrintWriter; +public class TryWithResources { + { + try (PrintWriter pw = new PrintWriter(System.out)) { + pw.println(); + } + } +} |