Mavenized and fixed formatting to match jacobe

This commit is contained in:
Thinkofdeath 2014-12-09 10:17:27 +00:00
parent b98e02e557
commit 1f64176246
21 changed files with 260 additions and 49 deletions

6
.gitignore vendored
View File

@ -1,3 +1,7 @@
/dist/
/nbproject/
/build/
/build/
/target
/.idea
*.iml

43
pom.xml Normal file
View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.spigotmc</groupId>
<artifactId>fernflower</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>./src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<mainClass>org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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 {

View File

@ -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, " ");
}});
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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>";

View File

@ -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) {

View File

@ -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 + ")";

View File

@ -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 "";

View File

@ -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(", ");

View File

@ -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) {

View File

@ -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() {

View File

@ -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) {

View File

@ -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);

View File

@ -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();
}

View File

@ -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);

View File

@ -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() {

View File

@ -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);

View File

@ -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);

View File

@ -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("");
}
}