Mavenized and fixed formatting to match jacobe
This commit is contained in:
parent
b98e02e557
commit
1f64176246
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
|||||||
/dist/
|
/dist/
|
||||||
/nbproject/
|
/nbproject/
|
||||||
/build/
|
/build/
|
||||||
|
/target
|
||||||
|
/.idea
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
43
pom.xml
Normal file
43
pom.xml
Normal 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>
|
@ -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.VarType;
|
||||||
import org.jetbrains.java.decompiler.struct.gen.generics.*;
|
import org.jetbrains.java.decompiler.struct.gen.generics.*;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -179,7 +180,17 @@ public class ClassWriter {
|
|||||||
|
|
||||||
// write class definition
|
// write class definition
|
||||||
int start_class_def = buffer.length();
|
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
|
// // count lines in class definition the easiest way
|
||||||
// total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
|
// total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
|
||||||
@ -189,6 +200,7 @@ public class ClassWriter {
|
|||||||
// fields
|
// fields
|
||||||
boolean enumFields = false;
|
boolean enumFields = false;
|
||||||
boolean endEnumWritten = false; // Spigot
|
boolean endEnumWritten = false; // Spigot
|
||||||
|
boolean firstEnum = true;
|
||||||
|
|
||||||
for (StructField fd : cl.getFields()) {
|
for (StructField fd : cl.getFields()) {
|
||||||
boolean hide = fd.isSynthetic() && DecompilerContext.getOption(IFernflowerPreferences.REMOVE_SYNTHETIC) ||
|
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);
|
boolean isEnum = fd.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
|
||||||
if (isEnum) {
|
if (isEnum) {
|
||||||
if (enumFields) {
|
if (enumFields) {
|
||||||
buffer.append(',');
|
buffer.append(", ");
|
||||||
buffer.append(lineSeparator);
|
|
||||||
}
|
}
|
||||||
enumFields = true;
|
enumFields = true;
|
||||||
}
|
}
|
||||||
@ -210,7 +221,14 @@ public class ClassWriter {
|
|||||||
endEnumWritten = true; // Spigot
|
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;
|
hasContent = true;
|
||||||
}
|
}
|
||||||
@ -218,8 +236,6 @@ public class ClassWriter {
|
|||||||
int flags = node.type == ClassNode.CLASS_ROOT ? cl.getAccessFlags() : node.access;
|
int flags = node.type == ClassNode.CLASS_ROOT ? cl.getAccessFlags() : node.access;
|
||||||
boolean isEnum = DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM) && (flags & CodeConstants.ACC_ENUM) != 0;
|
boolean isEnum = DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM) && (flags & CodeConstants.ACC_ENUM) != 0;
|
||||||
if (isEnum && !endEnumWritten) {
|
if (isEnum && !endEnumWritten) {
|
||||||
buffer.append(lineSeparator);
|
|
||||||
buffer.append(lineSeparator);
|
|
||||||
// Spigot End
|
// Spigot End
|
||||||
buffer.append(';');
|
buffer.append(';');
|
||||||
buffer.append(lineSeparator);
|
buffer.append(lineSeparator);
|
||||||
@ -283,12 +299,12 @@ public class ClassWriter {
|
|||||||
DecompilerContext.getLogger().endWriteClass();
|
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();
|
String lineSeparator = DecompilerContext.getNewLineSeparator();
|
||||||
|
|
||||||
if (node.type == ClassNode.CLASS_ANONYMOUS) {
|
if (node.type == ClassNode.CLASS_ANONYMOUS) {
|
||||||
buffer.append(" {");
|
buffer.append(" {");
|
||||||
buffer.append(lineSeparator);
|
if (!empty) buffer.append(lineSeparator);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,9 +406,11 @@ public class ClassWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer.append('{');
|
buffer.append('{');
|
||||||
|
if (!empty) {
|
||||||
buffer.append(lineSeparator);
|
buffer.append(lineSeparator);
|
||||||
buffer.append(lineSeparator); // Spigot
|
buffer.append(lineSeparator); // Spigot
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) {
|
private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) {
|
||||||
String lineSeparator = DecompilerContext.getNewLineSeparator();
|
String lineSeparator = DecompilerContext.getNewLineSeparator();
|
||||||
@ -817,9 +835,10 @@ public class ClassWriter {
|
|||||||
|
|
||||||
//TODO: for now only start line set
|
//TODO: for now only start line set
|
||||||
buffer.setCurrentLine(startLine);
|
buffer.setCurrentLine(startLine);
|
||||||
buffer.append('{').appendLineSeparator();
|
buffer.append('{');
|
||||||
|
|
||||||
RootStatement root = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root;
|
RootStatement root = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root;
|
||||||
|
boolean empty = false;
|
||||||
|
|
||||||
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
|
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
|
||||||
try {
|
try {
|
||||||
@ -827,8 +846,15 @@ public class ClassWriter {
|
|||||||
|
|
||||||
String code = root.toJava(indent + 1, tracer);
|
String code = root.toJava(indent + 1, tracer);
|
||||||
|
|
||||||
|
if (Util.rtrim(code).isEmpty()) code = "";
|
||||||
|
|
||||||
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;
|
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;
|
||||||
|
|
||||||
|
if (!code.isEmpty()) {
|
||||||
|
buffer.appendLineSeparator();
|
||||||
|
} else {
|
||||||
|
empty = true;
|
||||||
|
}
|
||||||
buffer.append(code);
|
buffer.append(code);
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
@ -843,7 +869,10 @@ public class ClassWriter {
|
|||||||
buffer.append(lineSeparator);
|
buffer.append(lineSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.appendIndent(indent).append('}').appendLineSeparator();
|
if (!empty) {
|
||||||
|
buffer.appendIndent(indent);
|
||||||
|
}
|
||||||
|
buffer.append('}').appendLineSeparator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -42,6 +42,7 @@ import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.jetbrains.java.decompiler.util.SortUtil;
|
import org.jetbrains.java.decompiler.util.SortUtil;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
public class ExprProcessor implements CodeConstants {
|
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) {
|
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();
|
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);
|
List<StatEdge> lstSuccs = stat.getSuccessorEdges(Statement.STATEDGE_DIRECT_ALL);
|
||||||
if (lstSuccs.size() == 1) {
|
if (lstSuccs.size() == 1) {
|
||||||
StatEdge edge = lstSuccs.get(0);
|
StatEdge edge = lstSuccs.get(0);
|
||||||
@ -816,11 +825,38 @@ public class ExprProcessor implements CodeConstants {
|
|||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
// Spigot Start
|
// Spigot Start
|
||||||
|
boolean inVar = false;
|
||||||
|
boolean bloodySpecialCaseForNewAssignments = false;
|
||||||
for (Iterator<Exprent> iter = SortUtil.sortIndexed(lst.iterator()); iter.hasNext();) {
|
for (Iterator<Exprent> iter = SortUtil.sortIndexed(lst.iterator()); iter.hasNext();) {
|
||||||
Exprent expr = iter.next();
|
Exprent expr = iter.next();
|
||||||
// Spigot End
|
// Spigot End
|
||||||
String content = expr.toJava(indent, tracer);
|
String content = expr.toJava(indent, tracer);
|
||||||
if (content.length() > 0) {
|
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()) {
|
if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassdef()) {
|
||||||
buf.append(indstr);
|
buf.append(indstr);
|
||||||
}
|
}
|
||||||
@ -832,6 +868,7 @@ public class ExprProcessor implements CodeConstants {
|
|||||||
buf.append(";");
|
buf.append(";");
|
||||||
}
|
}
|
||||||
buf.append(new_line_separator);
|
buf.append(new_line_separator);
|
||||||
|
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -895,7 +932,7 @@ public class ExprProcessor implements CodeConstants {
|
|||||||
res = "(" + res + ")";
|
res = "(" + res + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
res = "(" + getCastTypeName(leftType) + ")" + res;
|
res = "(" + getCastTypeName(leftType) + ") " + res;
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class AssignmentExprent extends Exprent {
|
|||||||
res = "(" + res + ")";
|
res = "(" + res + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
res = "(" + ExprProcessor.getCastTypeName(leftType) + ")" + res;
|
res = "(" + ExprProcessor.getCastTypeName(leftType) + ") " + res;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
|
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
|
||||||
|
@ -470,7 +470,7 @@ public class FunctionExprent extends Exprent {
|
|||||||
case FUNCTION_NEG:
|
case FUNCTION_NEG:
|
||||||
return "-" + wrapOperandString(lstOperands.get(0), true, indent, tracer);
|
return "-" + wrapOperandString(lstOperands.get(0), true, indent, tracer);
|
||||||
case FUNCTION_CAST:
|
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:
|
case FUNCTION_ARRAYLENGTH:
|
||||||
Exprent arr = lstOperands.get(0);
|
Exprent arr = lstOperands.get(0);
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ public class FunctionExprent extends Exprent {
|
|||||||
}
|
}
|
||||||
return res + ".length";
|
return res + ".length";
|
||||||
case FUNCTION_IIF:
|
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);
|
wrapOperandString(lstOperands.get(2), true, indent, tracer);
|
||||||
case FUNCTION_IPP:
|
case FUNCTION_IPP:
|
||||||
return wrapOperandString(lstOperands.get(0), true, indent, tracer) + "++";
|
return wrapOperandString(lstOperands.get(0), true, indent, tracer) + "++";
|
||||||
@ -528,7 +528,7 @@ public class FunctionExprent extends Exprent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (functype <= FUNCTION_I2S) {
|
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>";
|
// return "<unknown function>";
|
||||||
|
@ -115,7 +115,7 @@ public class IfExprent extends Exprent {
|
|||||||
@Override
|
@Override
|
||||||
public String toJava(int indent, BytecodeMappingTracer tracer) {
|
public String toJava(int indent, BytecodeMappingTracer tracer) {
|
||||||
tracer.addMapping(bytecode);
|
tracer.addMapping(bytecode);
|
||||||
return "if(" + condition.toJava(indent, tracer) + ")";
|
return "if (" + condition.toJava(indent, tracer) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -282,7 +282,7 @@ public class InvocationExprent extends Exprent {
|
|||||||
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
|
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
|
||||||
|
|
||||||
if (rightType.equals(VarType.VARTYPE_OBJECT) && !leftType.equals(rightType)) {
|
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)) {
|
if (instance.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
|
||||||
res = "(" + res + ")";
|
res = "(" + res + ")";
|
||||||
|
@ -56,7 +56,7 @@ public class MonitorExprent extends Exprent {
|
|||||||
tracer.addMapping(bytecode);
|
tracer.addMapping(bytecode);
|
||||||
|
|
||||||
if (montype == MONITOR_ENTER) {
|
if (montype == MONITOR_ENTER) {
|
||||||
return "synchronized(" + value.toJava(indent, tracer) + ")";
|
return "synchronized (" + value.toJava(indent, tracer) + ")";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "";
|
return "";
|
||||||
|
@ -275,7 +275,7 @@ public class NewExprent extends Exprent {
|
|||||||
VarType leftType = newtype.copy();
|
VarType leftType = newtype.copy();
|
||||||
leftType.decArrayDim();
|
leftType.decArrayDim();
|
||||||
|
|
||||||
buf.append("{");
|
buf.append("{ ");
|
||||||
for (int i = 0; i < lstArrayElements.size(); i++) {
|
for (int i = 0; i < lstArrayElements.size(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
@ -369,7 +369,7 @@ public class NewExprent extends Exprent {
|
|||||||
VarType leftType = newtype.copy();
|
VarType leftType = newtype.copy();
|
||||||
leftType.decArrayDim();
|
leftType.decArrayDim();
|
||||||
|
|
||||||
buf.append("{");
|
buf.append(" { ");
|
||||||
for (int i = 0; i < lstArrayElements.size(); i++) {
|
for (int i = 0; i < lstArrayElements.size(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
|
@ -85,7 +85,7 @@ public class SwitchExprent extends Exprent {
|
|||||||
@Override
|
@Override
|
||||||
public String toJava(int indent, BytecodeMappingTracer tracer) {
|
public String toJava(int indent, BytecodeMappingTracer tracer) {
|
||||||
tracer.addMapping(bytecode);
|
tracer.addMapping(bytecode);
|
||||||
return "switch(" + value.toJava(indent, tracer) + ")";
|
return "switch (" + value.toJava(indent, tracer) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -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.BytecodeMappingTracer;
|
||||||
import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
|
import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
public class BasicBlockStatement extends Statement {
|
public class BasicBlockStatement extends Statement {
|
||||||
|
|
||||||
|
@ -119,7 +119,11 @@ public class CatchAllStatement extends Statement {
|
|||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
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();
|
boolean labeled = isLabeled();
|
||||||
if (labeled) {
|
if (labeled) {
|
||||||
|
@ -156,7 +156,11 @@ public class CatchStatement extends Statement {
|
|||||||
|
|
||||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
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()) {
|
if (isLabeled()) {
|
||||||
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
||||||
|
@ -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.StatEdge;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -98,7 +99,11 @@ public class DoStatement extends Statement {
|
|||||||
|
|
||||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
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()) {
|
if (isLabeled()) {
|
||||||
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
||||||
@ -107,7 +112,7 @@ public class DoStatement extends Statement {
|
|||||||
|
|
||||||
switch (looptype) {
|
switch (looptype) {
|
||||||
case LOOP_DO:
|
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();
|
tracer.incrementCurrentSourceLine();
|
||||||
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
||||||
buf.append(indstr).append("}").append(new_line_separator);
|
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);
|
buf.append(indstr).append("do {").append(new_line_separator);
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
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();
|
tracer.incrementCurrentSourceLine();
|
||||||
break;
|
break;
|
||||||
case LOOP_WHILE:
|
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();
|
tracer.incrementCurrentSourceLine();
|
||||||
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
||||||
buf.append(indstr).append("}").append(new_line_separator);
|
buf.append(indstr).append("}").append(new_line_separator);
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
break;
|
break;
|
||||||
case LOOP_FOR:
|
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(conditionExprent.get(0).toJava(indent, tracer)).append("; ").append(incExprent.get(0).toJava(indent, tracer)).append(") {")
|
||||||
.append(new_line_separator);
|
.append(new_line_separator);
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
@ -137,6 +142,7 @@ public class DoStatement extends Statement {
|
|||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buf.append(new_line_separator);
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.DecHelper;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
|
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.modules.decompiler.exps.IfExprent;
|
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -207,7 +207,40 @@ public class IfStatement extends Statement {
|
|||||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||||
|
|
||||||
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
|
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()) {
|
if (isLabeled()) {
|
||||||
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
||||||
|
@ -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.DecHelper;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
|
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.*;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
|
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.SwitchExprent;
|
|
||||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
import org.jetbrains.java.decompiler.util.Util;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -114,8 +113,24 @@ public class SwitchStatement extends Statement {
|
|||||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
|
String content = ExprProcessor.listToJava(varDefinitions, indent, tracer);
|
||||||
buf.append(first.toJava(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()) {
|
if (isLabeled()) {
|
||||||
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
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);
|
buf.append(indstr).append("}").append(new_line_separator);
|
||||||
|
@ -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.ExprProcessor;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.SequenceHelper;
|
import org.jetbrains.java.decompiler.modules.decompiler.SequenceHelper;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
|
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 org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -75,8 +75,26 @@ public class SynchronizedStatement extends Statement {
|
|||||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
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()) {
|
if (isLabeled()) {
|
||||||
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
|
||||||
|
12
src/org/jetbrains/java/decompiler/util/Util.java
Normal file
12
src/org/jetbrains/java/decompiler/util/Util.java
Normal 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("");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user