summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/modules
diff options
context:
space:
mode:
authorThinkofdeath <thinkofdeath@spigotmc.org>2014-12-09 10:17:27 +0000
committerThinkofdeath <thinkofdeath@spigotmc.org>2014-12-11 14:50:16 +0000
commit1f6417624639de346ffa74351d30b58d30f9e80b (patch)
tree036118b0c09135e1bc579e0a3a51bc0a3ecd861d /src/org/jetbrains/java/decompiler/modules
parentb98e02e557eb7c30d6425ffd9cfa8b7b71b164dc (diff)
downloadfernflower-1f6417624639de346ffa74351d30b58d30f9e80b.tar
fernflower-1f6417624639de346ffa74351d30b58d30f9e80b.tar.gz
fernflower-1f6417624639de346ffa74351d30b58d30f9e80b.tar.lz
fernflower-1f6417624639de346ffa74351d30b58d30f9e80b.tar.xz
fernflower-1f6417624639de346ffa74351d30b58d30f9e80b.zip
Mavenized and fixed formatting to match jacobeformatting
Diffstat (limited to 'src/org/jetbrains/java/decompiler/modules')
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java45
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java6
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java4
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java3
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java6
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java6
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java16
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java39
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java32
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java24
16 files changed, 158 insertions, 35 deletions
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
index 7b2f3a2..2450475 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
@@ -42,6 +42,7 @@ import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.*;
import org.jetbrains.java.decompiler.util.SortUtil;
+import org.jetbrains.java.decompiler.util.Util;
public class ExprProcessor implements CodeConstants {
@@ -758,10 +759,18 @@ public class ExprProcessor implements CodeConstants {
}
public static String jmpWrapper(Statement stat, int indent, boolean semicolon, BytecodeMappingTracer tracer) {
- StringBuilder buf = new StringBuilder(stat.toJava(indent, tracer));
-
String new_line_separator = DecompilerContext.getNewLineSeparator();
+ StringBuilder buf = new StringBuilder();
+ String content = stat.toJava(indent, tracer);
+ if (!(stat instanceof IfStatement) && !(stat instanceof DoStatement) && !(stat instanceof SequenceStatement)) {
+ content = Util.rtrim(content);
+ }
+ buf.append(content);
+ if (!(stat instanceof IfStatement) && !(stat instanceof DoStatement) && !(stat instanceof SequenceStatement) && buf.length() != 0) {
+ buf.append(new_line_separator);
+ }
+
List<StatEdge> lstSuccs = stat.getSuccessorEdges(Statement.STATEDGE_DIRECT_ALL);
if (lstSuccs.size() == 1) {
StatEdge edge = lstSuccs.get(0);
@@ -815,12 +824,39 @@ public class ExprProcessor implements CodeConstants {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder();
- // Spigot Start
+ // Spigot Start
+ boolean inVar = false;
+ boolean bloodySpecialCaseForNewAssignments = false;
for (Iterator<Exprent> iter = SortUtil.sortIndexed(lst.iterator()); iter.hasNext();) {
Exprent expr = iter.next();
// Spigot End
String content = expr.toJava(indent, tracer);
if (content.length() > 0) {
+
+ if (expr instanceof VarExprent || expr instanceof AssignmentExprent) {
+ inVar = true;
+ boolean wasASpecialLittleFlower = bloodySpecialCaseForNewAssignments;
+ bloodySpecialCaseForNewAssignments = expr instanceof VarExprent;
+ if (expr instanceof AssignmentExprent && ((AssignmentExprent) expr).getLeft() instanceof VarExprent) {
+ AssignmentExprent assignmentExprent = (AssignmentExprent) expr;
+ VarExprent var = (VarExprent) assignmentExprent.getLeft();
+ bloodySpecialCaseForNewAssignments = var.isDefinition();
+ }
+ if (wasASpecialLittleFlower && !bloodySpecialCaseForNewAssignments) {
+ buf.append(new_line_separator);
+ }
+ } else if (inVar) {
+ inVar = false;
+ if (!(expr instanceof InvocationExprent
+ || expr instanceof ExitExprent
+ || expr instanceof FunctionExprent
+ )
+ || bloodySpecialCaseForNewAssignments) {
+ bloodySpecialCaseForNewAssignments = false;
+ buf.append(new_line_separator);
+ }
+ }
+
if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassdef()) {
buf.append(indstr);
}
@@ -832,6 +868,7 @@ public class ExprProcessor implements CodeConstants {
buf.append(";");
}
buf.append(new_line_separator);
+
tracer.incrementCurrentSourceLine();
}
}
@@ -895,7 +932,7 @@ public class ExprProcessor implements CodeConstants {
res = "(" + res + ")";
}
- res = "(" + getCastTypeName(leftType) + ")" + res;
+ res = "(" + getCastTypeName(leftType) + ") " + res;
ret = true;
}
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java
index 9553f3f..75f4b75 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java
@@ -148,7 +148,7 @@ public class AssignmentExprent extends Exprent {
res = "(" + res + ")";
}
- res = "(" + ExprProcessor.getCastTypeName(leftType) + ")" + res;
+ res = "(" + ExprProcessor.getCastTypeName(leftType) + ") " + res;
}
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java
index a527918..52f09c2 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java
@@ -470,7 +470,7 @@ public class FunctionExprent extends Exprent {
case FUNCTION_NEG:
return "-" + wrapOperandString(lstOperands.get(0), true, indent, tracer);
case FUNCTION_CAST:
- return "(" + lstOperands.get(1).toJava(indent, tracer) + ")" + wrapOperandString(lstOperands.get(0), true, indent, tracer);
+ return "(" + lstOperands.get(1).toJava(indent, tracer) + ") " + wrapOperandString(lstOperands.get(0), true, indent, tracer);
case FUNCTION_ARRAYLENGTH:
Exprent arr = lstOperands.get(0);
@@ -483,7 +483,7 @@ public class FunctionExprent extends Exprent {
}
return res + ".length";
case FUNCTION_IIF:
- return wrapOperandString(lstOperands.get(0), true, indent, tracer) + "?" + wrapOperandString(lstOperands.get(1), true, indent, tracer) + ":" +
+ return wrapOperandString(lstOperands.get(0), true, indent, tracer) + " ? " + wrapOperandString(lstOperands.get(1), true, indent, tracer) + " : " +
wrapOperandString(lstOperands.get(2), true, indent, tracer);
case FUNCTION_IPP:
return wrapOperandString(lstOperands.get(0), true, indent, tracer) + "++";
@@ -528,7 +528,7 @@ public class FunctionExprent extends Exprent {
}
if (functype <= FUNCTION_I2S) {
- return "(" + ExprProcessor.getTypeName(types[functype - FUNCTION_I2L]) + ")" + wrapOperandString(lstOperands.get(0), true, indent, tracer);
+ return "(" + ExprProcessor.getTypeName(types[functype - FUNCTION_I2L]) + ") " + wrapOperandString(lstOperands.get(0), true, indent, tracer);
}
// return "<unknown function>";
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java
index 32cc19d..4a2fbf5 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java
@@ -115,7 +115,7 @@ public class IfExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
- return "if(" + condition.toJava(indent, tracer) + ")";
+ return "if (" + condition.toJava(indent, tracer) + ")";
}
public boolean equals(Object o) {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
index e9d9064..320cc73 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
@@ -282,7 +282,7 @@ public class InvocationExprent extends Exprent {
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
if (rightType.equals(VarType.VARTYPE_OBJECT) && !leftType.equals(rightType)) {
- buf.append("((").append(ExprProcessor.getCastTypeName(leftType)).append(")");
+ buf.append("((").append(ExprProcessor.getCastTypeName(leftType)).append(") ");
if (instance.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
res = "(" + res + ")";
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java
index 091d424..5a71ce3 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java
@@ -56,7 +56,7 @@ public class MonitorExprent extends Exprent {
tracer.addMapping(bytecode);
if (montype == MONITOR_ENTER) {
- return "synchronized(" + value.toJava(indent, tracer) + ")";
+ return "synchronized (" + value.toJava(indent, tracer) + ")";
}
else {
return "";
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
index bb55e45..8f8f684 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
@@ -275,7 +275,7 @@ public class NewExprent extends Exprent {
VarType leftType = newtype.copy();
leftType.decArrayDim();
- buf.append("{");
+ buf.append("{ ");
for (int i = 0; i < lstArrayElements.size(); i++) {
if (i > 0) {
buf.append(", ");
@@ -369,7 +369,7 @@ public class NewExprent extends Exprent {
VarType leftType = newtype.copy();
leftType.decArrayDim();
- buf.append("{");
+ buf.append(" { ");
for (int i = 0; i < lstArrayElements.size(); i++) {
if (i > 0) {
buf.append(", ");
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java
index 4784eb1..828d06a 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java
@@ -85,7 +85,7 @@ public class SwitchExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
- return "switch(" + value.toJava(indent, tracer) + ")";
+ return "switch (" + value.toJava(indent, tracer) + ")";
}
public boolean equals(Object o) {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java
index 1ff1b2b..2fb809e 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java
@@ -23,6 +23,7 @@ import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
+import org.jetbrains.java.decompiler.util.Util;
public class BasicBlockStatement extends Statement {
@@ -68,7 +69,7 @@ public class BasicBlockStatement extends Statement {
public String toJava(int indent, BytecodeMappingTracer tracer) {
return ExprProcessor.listToJava(varDefinitions, indent, tracer) +
- ExprProcessor.listToJava(exprents, indent, tracer);
+ ExprProcessor.listToJava(exprents, indent, tracer);
}
public Statement getSimpleCopy() {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
index f22d1b1..b993a81 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
@@ -119,7 +119,11 @@ public class CatchAllStatement extends Statement {
StringBuilder buf = new StringBuilder();
- buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
+ String defs = ExprProcessor.listToJava(varDefinitions, indent, tracer);
+ buf.append(defs);
+ if (!defs.isEmpty()) {
+ buf.append(new_line_separator);
+ }
boolean labeled = isLabeled();
if (labeled) {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
index a096258..685a60e 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
@@ -156,7 +156,11 @@ public class CatchStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
- buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
+ String content = ExprProcessor.listToJava(varDefinitions, indent, tracer);
+ buf.append(content);
+ if (!content.isEmpty()) {
+ buf.append(new_line_separator);
+ }
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
index 1ddce1b..81f5ca2 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
@@ -21,6 +21,7 @@ import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
+import org.jetbrains.java.decompiler.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -98,7 +99,11 @@ public class DoStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
- buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
+ String content = ExprProcessor.listToJava(varDefinitions, indent, tracer);
+ buf.append(content);
+ if (!content.isEmpty()) {
+ buf.append(new_line_separator);
+ }
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
@@ -107,7 +112,7 @@ public class DoStatement extends Statement {
switch (looptype) {
case LOOP_DO:
- buf.append(indstr).append("while(true) {").append(new_line_separator);
+ buf.append(indstr).append("while (true) {").append(new_line_separator);
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}").append(new_line_separator);
@@ -117,18 +122,18 @@ public class DoStatement extends Statement {
buf.append(indstr).append("do {").append(new_line_separator);
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
- buf.append(indstr).append("} while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").append(new_line_separator);
+ buf.append(indstr).append("} while (").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").append(new_line_separator);
tracer.incrementCurrentSourceLine();
break;
case LOOP_WHILE:
- buf.append(indstr).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").append(new_line_separator);
+ buf.append(indstr).append("while (").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").append(new_line_separator);
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}").append(new_line_separator);
tracer.incrementCurrentSourceLine();
break;
case LOOP_FOR:
- buf.append(indstr).append("for(").append(initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent, tracer)).append("; ")
+ buf.append(indstr).append("for (").append(initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent, tracer)).append("; ")
.append(conditionExprent.get(0).toJava(indent, tracer)).append("; ").append(incExprent.get(0).toJava(indent, tracer)).append(") {")
.append(new_line_separator);
tracer.incrementCurrentSourceLine();
@@ -137,6 +142,7 @@ public class DoStatement extends Statement {
tracer.incrementCurrentSourceLine();
}
+ // buf.append(new_line_separator);
return buf.toString();
}
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
index ebe2bd7..3e9d368 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
@@ -20,9 +20,9 @@ import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.modules.decompiler.DecHelper;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.IfExprent;
+import org.jetbrains.java.decompiler.modules.decompiler.exps.*;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
+import org.jetbrains.java.decompiler.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -207,7 +207,40 @@ public class IfStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
- buf.append(first.toJava(indent, tracer));
+
+ boolean bloodySpecialCases = false;
+ if (first instanceof BasicBlockStatement) {
+ List<Exprent> exps = first.getExprents();
+ if (exps.size() != 0) {
+ Exprent last = exps.get(exps.size() - 1);
+ if (last instanceof AssignmentExprent) {
+ AssignmentExprent assignmentExprent = (AssignmentExprent) exps.get(exps.size() - 1);
+ bloodySpecialCases = true;
+ if (assignmentExprent.getLeft() instanceof VarExprent) {
+ VarExprent var = (VarExprent) assignmentExprent.getLeft();
+ bloodySpecialCases = !var.isDefinition();
+ }
+ } else if (last instanceof InvocationExprent) {
+ bloodySpecialCases = true;
+ }
+ }
+ }
+
+ if (bloodySpecialCases) {
+ buf.append(Util.rtrim(first.toJava(indent, tracer))).append(new_line_separator);
+ } else {
+ String content = first.toJava(indent, tracer);
+ buf.append(content);
+ if (first instanceof BasicBlockStatement && !content.isEmpty()) {
+ List<Exprent> exps = first.getExprents();
+ if (exps.size() != 0) {
+ Exprent e = exps.get(exps.size() - 1);
+ if (!(e instanceof InvocationExprent || e instanceof FunctionExprent)) {
+ buf.append(new_line_separator);
+ }
+ }
+ }
+ }
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java
index 07009d6..58ec365 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java
@@ -36,7 +36,7 @@ public class RootStatement extends Statement {
public String toJava(int indent, BytecodeMappingTracer tracer) {
return ExprProcessor.listToJava(varDefinitions, indent, tracer) +
- first.toJava(indent, tracer);
+ first.toJava(indent, tracer);
}
public Statement getDummyExit() {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java
index aea44de..b0ec5e3 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java
@@ -23,11 +23,10 @@ import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
import org.jetbrains.java.decompiler.modules.decompiler.DecHelper;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.SwitchExprent;
+import org.jetbrains.java.decompiler.modules.decompiler.exps.*;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
+import org.jetbrains.java.decompiler.util.Util;
import java.util.*;
@@ -114,8 +113,24 @@ public class SwitchStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder();
- buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
- buf.append(first.toJava(indent, tracer));
+ String content = ExprProcessor.listToJava(varDefinitions, indent, tracer);
+ buf.append(content);
+ if (!content.isEmpty()) {
+ buf.append(new_line_separator);
+ }
+ content = first.toJava(indent, tracer);
+ buf.append(content);
+ if (first instanceof BasicBlockStatement && !content.isEmpty()) {
+ List<Exprent> exps = first.getExprents();
+ if (exps.size() != 0) {
+ Exprent e = exps.get(exps.size() - 1);
+ if (!(e instanceof InvocationExprent
+ || e instanceof FunctionExprent
+ || (e instanceof AssignmentExprent && !(((AssignmentExprent) e).getLeft() instanceof VarExprent && ((VarExprent) ((AssignmentExprent) e).getLeft()).isDefinition())))) {
+ buf.append(new_line_separator);
+ }
+ }
+ }
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
@@ -147,7 +162,12 @@ public class SwitchStatement extends Statement {
}
}
- buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer));
+ String c = Util.rtrim(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer));
+ if (!c.isEmpty()) {
+ buf.append(c);
+ buf.append(new_line_separator);
+ }
+ if (i != caseStatements.size() - 1) buf.append(new_line_separator);
}
buf.append(indstr).append("}").append(new_line_separator);
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java
index eb94ddc..3ac68a6 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java
@@ -20,7 +20,7 @@ import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.SequenceHelper;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
-import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
+import org.jetbrains.java.decompiler.modules.decompiler.exps.*;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.ArrayList;
@@ -75,8 +75,26 @@ public class SynchronizedStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder();
- buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
- buf.append(first.toJava(indent, tracer));
+
+ String content = ExprProcessor.listToJava(varDefinitions, indent, tracer);
+ buf.append(content);
+ if (!content.isEmpty()) {
+ buf.append(new_line_separator);
+ }
+
+ content = first.toJava(indent, tracer);
+ buf.append(content);
+ if (first instanceof BasicBlockStatement && !content.isEmpty()) {
+ List<Exprent> exps = first.getExprents();
+ if (exps.size() != 0) {
+ Exprent e = exps.get(exps.size() - 1);
+ if (!(e instanceof InvocationExprent
+ || e instanceof FunctionExprent
+ || (e instanceof AssignmentExprent && !(((AssignmentExprent) e).getLeft() instanceof VarExprent && ((VarExprent) ((AssignmentExprent) e).getLeft()).isDefinition())))) {
+ buf.append(new_line_separator);
+ }
+ }
+ }
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);