aboutsummaryrefslogtreecommitdiff
path: root/src/delombok
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2013-11-19 23:09:01 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-12-11 22:40:47 +0100
commit1025ffb8baa26a0a843318b3b5e70c717bb36c9a (patch)
tree85a02c86aa89ddd52aa9733ceaef30d34706a317 /src/delombok
parent083817732242cce815b9d78659e68520abdb5021 (diff)
downloadlombok-1025ffb8baa26a0a843318b3b5e70c717bb36c9a.tar.gz
lombok-1025ffb8baa26a0a843318b3b5e70c717bb36c9a.tar.bz2
lombok-1025ffb8baa26a0a843318b3b5e70c717bb36c9a.zip
[Pretty] Fix labeled statements and try-with-resources
Diffstat (limited to 'src/delombok')
-rw-r--r--src/delombok/lombok/delombok/PrettyCommentsPrinter.java48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
index f9152e68..72e7e745 100644
--- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
@@ -183,6 +183,8 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
private boolean needsNewLine = false;
private boolean needsAlign = false;
+ private final String indentation = "\t";
+
public PrettyCommentsPrinter(Writer out, JCCompilationUnit cu, List<CommentInfo> comments) {
this.out = out;
this.comments = comments;
@@ -297,7 +299,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
onNewLine = false;
aligned = true;
needsAlign = false;
- for (int i = 0; i < lmargin; i++) out.write("\t");
+ for (int i = 0; i < lmargin; i++) out.write(indentation);
}
/** Increase left margin by indentation width.
@@ -452,11 +454,22 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
*/
public void printStats(List<? extends JCTree> trees) throws IOException {
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
+ if (isSuppressed(l.head)) continue;
align();
printStat(l.head);
println();
}
}
+
+ private boolean isSuppressed(JCTree tree) {
+ if (isEmptyStat(tree)) {
+ return true;
+ }
+ if (tree instanceof JCExpressionStatement) {
+ return isNoArgsSuperCall(((JCExpressionStatement)tree).expr);
+ }
+ return false;
+ }
/** Print a set of modifiers.
*/
@@ -906,8 +919,17 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
public void visitLabelled(JCLabeledStatement tree) {
try {
- print(tree.label + ": ");
- printStat(tree.body);
+ print(tree.label + ":");
+ if (isEmptyStat(tree.body) || tree.body instanceof JCSkip) {
+ print(" ;");
+ } else if (tree.body instanceof JCBlock) {
+ print(" ");
+ printStat(tree.body);
+ } else {
+ println();
+ align();
+ printStat(tree.body);
+ }
} catch (IOException e) {
throw new UncheckedIOException(e);
}
@@ -981,18 +1003,22 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
}
if (resources != null && resources.nonEmpty()) {
- boolean first = true;
print("(");
- for (Object var0 : resources) {
- JCTree var = (JCTree) var0;
- if (!first) {
+ if (resources.size() == 1) {
+ JCTree var = (JCTree) resources.get(0);
+ printStat(var);
+ print(") ");
+ } else {
+ indent(); indent();
+ for (Object var0 : resources) {
println();
- indent();
+ align();
+ JCTree var = (JCTree) var0;
+ printStat(var);
}
- printStat(var);
- first = false;
+ print(") ");
+ undent(); undent();
}
- print(") ");
}
printStat(tree.body);