diff options
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyPrinter.java | 29 | ||||
-rw-r--r-- | test/pretty/resource/after/ForLoop.java | 7 | ||||
-rw-r--r-- | test/pretty/resource/before/ForLoop.java | 7 |
4 files changed, 43 insertions, 1 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 5ad0464f..05b4819b 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -3,6 +3,7 @@ Lombok Changelog ### v1.16.11 "Edgy Guinea Pig" * v1.16.10 is the latest release +* BUGFIX: delombok: for-loops with initializers that are not local variable would be generated incorrectly [Issue 1076](https://github.com/rzwitserloot/lombok/issues/1076) ### v1.16.10 (July 15th, 2016) * FEATURE: Added support for JBoss logger [Issue #1103](https://github.com/rzwitserloot/lombok/issues/1103) diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 73d6ee90..d1b47c0d 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2016 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.delombok; import static com.sun.tools.javac.code.Flags.*; @@ -1054,6 +1075,7 @@ public class PrettyPrinter extends JCTree.Visitor { @Override public void visitForLoop(JCForLoop tree) { aPrint("for ("); if (tree.init.nonEmpty()) { + // ForInit is either a list of StatementExpressionList or a LocalVariableDeclaration if (tree.init.head instanceof JCVariableDecl) { boolean first = true; int dims = 0; @@ -1075,7 +1097,12 @@ public class PrettyPrinter extends JCTree.Visitor { first = false; } } else { - print(tree.init, ", "); + boolean first = true; + for (JCStatement exprStatement : tree.init) { + if (!first) print(", "); + first = false; + print(((JCExpressionStatement) exprStatement).expr); + } } } print("; "); diff --git a/test/pretty/resource/after/ForLoop.java b/test/pretty/resource/after/ForLoop.java index 615f6e8a..f3b1bf4e 100644 --- a/test/pretty/resource/after/ForLoop.java +++ b/test/pretty/resource/after/ForLoop.java @@ -8,4 +8,11 @@ public class ForLoop { } // after loop } + + { + int i; + for (i = 0; i < 10; i++) { + System.out.println(i); + } + } } diff --git a/test/pretty/resource/before/ForLoop.java b/test/pretty/resource/before/ForLoop.java index 2bed7f9b..8a58cbf2 100644 --- a/test/pretty/resource/before/ForLoop.java +++ b/test/pretty/resource/before/ForLoop.java @@ -9,4 +9,11 @@ public class ForLoop { } // after loop } + + { + int i; + for (i = 0; i < 10; i++) { + System.out.println(i); + } + } } |