summaryrefslogtreecommitdiffstats
path: root/src
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
parentb98e02e557eb7c30d6425ffd9cfa8b7b71b164dc (diff)
downloadfernflower-formatting.tar
fernflower-formatting.tar.gz
fernflower-formatting.tar.lz
fernflower-formatting.tar.xz
fernflower-formatting.zip
Mavenized and fixed formatting to match jacobeformatting
Diffstat (limited to 'src')
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassWriter.java53
-rw-r--r--src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java2
-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
-rw-r--r--src/org/jetbrains/java/decompiler/util/Util.java12
19 files changed, 212 insertions, 48 deletions
diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
index 7d3e66d..df4511e 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
@@ -42,6 +42,7 @@ import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.struct.gen.generics.*;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
+import org.jetbrains.java.decompiler.util.Util;
import java.util.LinkedHashMap;
import java.util.List;
@@ -179,7 +180,17 @@ public class ClassWriter {
// write class definition
int start_class_def = buffer.length();
- writeClassDefinition(node, buffer, indent);
+ boolean empty = cl.getFields().isEmpty() && cl.getMethods().isEmpty();
+ if (cl.hasModifier(CodeConstants.ACC_ENUM)) {
+ empty = true;
+ for (StructField fd : cl.getFields()) {
+ if (fd.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM)) {
+ empty = false;
+ break;
+ }
+ }
+ }
+ writeClassDefinition(node, buffer, indent, empty);
// // count lines in class definition the easiest way
// total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
@@ -189,6 +200,7 @@ public class ClassWriter {
// fields
boolean enumFields = false;
boolean endEnumWritten = false; // Spigot
+ boolean firstEnum = true;
for (StructField fd : cl.getFields()) {
boolean hide = fd.isSynthetic() && DecompilerContext.getOption(IFernflowerPreferences.REMOVE_SYNTHETIC) ||
@@ -198,8 +210,7 @@ public class ClassWriter {
boolean isEnum = fd.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
if (isEnum) {
if (enumFields) {
- buffer.append(',');
- buffer.append(lineSeparator);
+ buffer.append(", ");
}
enumFields = true;
}
@@ -210,7 +221,14 @@ public class ClassWriter {
endEnumWritten = true; // Spigot
}
- fieldToJava(wrapper, cl, fd, buffer, indent + 1, dummy_tracer); // FIXME: insert real tracer
+ int ind = indent + 1;
+ if (isEnum) {
+ if (!firstEnum) {
+ ind = 0;
+ }
+ firstEnum = false;
+ }
+ fieldToJava(wrapper, cl, fd, buffer, ind, dummy_tracer); // FIXME: insert real tracer
hasContent = true;
}
@@ -218,8 +236,6 @@ public class ClassWriter {
int flags = node.type == ClassNode.CLASS_ROOT ? cl.getAccessFlags() : node.access;
boolean isEnum = DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM) && (flags & CodeConstants.ACC_ENUM) != 0;
if (isEnum && !endEnumWritten) {
- buffer.append(lineSeparator);
- buffer.append(lineSeparator);
// Spigot End
buffer.append(';');
buffer.append(lineSeparator);
@@ -283,12 +299,12 @@ public class ClassWriter {
DecompilerContext.getLogger().endWriteClass();
}
- private void writeClassDefinition(ClassNode node, TextBuffer buffer, int indent) {
+ private void writeClassDefinition(ClassNode node, TextBuffer buffer, int indent, boolean empty) {
String lineSeparator = DecompilerContext.getNewLineSeparator();
if (node.type == ClassNode.CLASS_ANONYMOUS) {
buffer.append(" {");
- buffer.append(lineSeparator);
+ if (!empty) buffer.append(lineSeparator);
return;
}
@@ -390,8 +406,10 @@ public class ClassWriter {
}
buffer.append('{');
- buffer.append(lineSeparator);
- buffer.append(lineSeparator); // Spigot
+ if (!empty) {
+ buffer.append(lineSeparator);
+ buffer.append(lineSeparator); // Spigot
+ }
}
private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) {
@@ -817,9 +835,10 @@ public class ClassWriter {
//TODO: for now only start line set
buffer.setCurrentLine(startLine);
- buffer.append('{').appendLineSeparator();
+ buffer.append('{');
RootStatement root = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root;
+ boolean empty = false;
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
try {
@@ -827,8 +846,15 @@ public class ClassWriter {
String code = root.toJava(indent + 1, tracer);
+ if (Util.rtrim(code).isEmpty()) code = "";
+
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;
+ if (!code.isEmpty()) {
+ buffer.appendLineSeparator();
+ } else {
+ empty = true;
+ }
buffer.append(code);
}
catch (Throwable ex) {
@@ -843,7 +869,10 @@ public class ClassWriter {
buffer.append(lineSeparator);
}
- buffer.appendIndent(indent).append('}').appendLineSeparator();
+ if (!empty) {
+ buffer.appendIndent(indent);
+ }
+ buffer.append('}').appendLineSeparator();
}
}
finally {
diff --git a/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java b/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java
index 677d05d..7d96e62 100644
--- a/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java
+++ b/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java
@@ -91,6 +91,6 @@ public interface IFernflowerPreferences {
put(MAX_PROCESSING_METHOD, "0");
put(RENAME_ENTITIES, "0");
put(NEW_LINE_SEPARATOR, (InterpreterUtil.IS_WINDOWS ? "0" : "1"));
- put(INDENT_STRING, " ");
+ put(INDENT_STRING, " ");
}});
}
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);
diff --git a/src/org/jetbrains/java/decompiler/util/Util.java b/src/org/jetbrains/java/decompiler/util/Util.java
new file mode 100644
index 0000000..5ade232
--- /dev/null
+++ b/src/org/jetbrains/java/decompiler/util/Util.java
@@ -0,0 +1,12 @@
+package org.jetbrains.java.decompiler.util;
+
+import java.util.regex.Pattern;
+
+public class Util {
+
+ private final static Pattern RTRIM = Pattern.compile("\\s+$");
+
+ public static String rtrim(String s) {
+ return RTRIM.matcher(s).replaceAll("");
+ }
+}