Fixed issue 459: Delombok would choke on try-with-resources.

This commit is contained in:
Reinier Zwitserloot committed 2013-03-18 23:57:09 +01:00
1 parent 0ecc23766f
commit 66f32d5073
4 files changed
+47

No files matched your search

+1
View File
@@ -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.
@@ -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);
@@ -0,0 +1,9 @@
//version 7:
import java.io.PrintWriter;
public class TryWithResources {
{
try (final PrintWriter pw = new PrintWriter(System.out);) {
pw.println();
}
}
}
@@ -0,0 +1,9 @@
//version 7:
import java.io.PrintWriter;
public class TryWithResources {
{
try (PrintWriter pw = new PrintWriter(System.out)) {
pw.println();
}
}
}