From 68b079d3129c8201fcffb898bf6155efdc393d0a Mon Sep 17 00:00:00 2001 From: peichhorn Date: Thu, 14 Jul 2011 10:38:16 +0200 Subject: fixed Issue 233: Javac parser handles ";" (empty statements) as empty blocks with an invalid position. Thats why delomok replaces ";" with "{}". This gets an issue when you use this in an interface, since interfaces are not allowed to have initializer blocks. --- .../lombok/delombok/PrettyCommentsPrinter.java | 21 +++++++++++++-------- test/pretty/resource/after/Enum.java | 1 + test/pretty/resource/after/Interfaces.java | 8 ++++++++ test/pretty/resource/before/Enum.java | 2 +- test/pretty/resource/before/Interfaces.java | 8 ++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index edff8637..c0f61650 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -103,6 +103,7 @@ import com.sun.tools.javac.tree.JCTree.TypeBoundKind; import com.sun.tools.javac.util.Convert; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Position; /** Prints out a tree as an indented Java source program. * @@ -480,14 +481,18 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { /** Print a block. */ public void printBlock(List stats, JCTree container) throws IOException { - print("{"); - println(); - indent(); - printStats(stats); - consumeComments(endPos(container)); - undent(); - align(); - print("}"); + if ((Position.NOPOS == container.pos) && stats.isEmpty()) { + print(";"); + } else { + print("{"); + println(); + indent(); + printStats(stats); + consumeComments(endPos(container)); + undent(); + align(); + print("}"); + } } /** Print a block. diff --git a/test/pretty/resource/after/Enum.java b/test/pretty/resource/after/Enum.java index dd738b5b..9968b457 100644 --- a/test/pretty/resource/after/Enum.java +++ b/test/pretty/resource/after/Enum.java @@ -3,6 +3,7 @@ enum Ranks { HEARTS, DIAMONDS, SPADES; + ; } enum Complex { RED("ff0000"), diff --git a/test/pretty/resource/after/Interfaces.java b/test/pretty/resource/after/Interfaces.java index c5008f2b..b620e038 100644 --- a/test/pretty/resource/after/Interfaces.java +++ b/test/pretty/resource/after/Interfaces.java @@ -1,5 +1,13 @@ @SuppressWarnings("all") interface Interfaces { + enum Ranks { + CLUBS, + HEARTS, + DIAMONDS, + SPADES; + } + ; + ; int x = 10; void y(); int a = 20; diff --git a/test/pretty/resource/before/Enum.java b/test/pretty/resource/before/Enum.java index c1185d53..1cb979d0 100644 --- a/test/pretty/resource/before/Enum.java +++ b/test/pretty/resource/before/Enum.java @@ -1,5 +1,5 @@ enum Ranks { - CLUBS, HEARTS, DIAMONDS, SPADES + CLUBS, HEARTS, DIAMONDS, SPADES;; } enum Complex { diff --git a/test/pretty/resource/before/Interfaces.java b/test/pretty/resource/before/Interfaces.java index c8a5cca4..360657ff 100644 --- a/test/pretty/resource/before/Interfaces.java +++ b/test/pretty/resource/before/Interfaces.java @@ -1,5 +1,13 @@ @SuppressWarnings("all") interface Interfaces { + enum Ranks { + CLUBS, + HEARTS, + DIAMONDS, + SPADES; + } + ; + ; int x = 10; void y(); public static final int a = 20; -- cgit