decompiler: track lines in anonymous classes as well

master
Egor.Ushakov 10 years ago
parent 7bb0f5ba7e
commit 46c36636bc
  1. 2
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 92
      src/org/jetbrains/java/decompiler/main/TextBuffer.java
  3. 24
      src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
  4. 7
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java
  5. 11
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/ArrayExprent.java
  6. 7
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssertExprent.java
  7. 15
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java
  8. 43
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java
  9. 8
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/ExitExprent.java
  10. 3
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java
  11. 6
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java
  12. 97
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java
  13. 5
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java
  14. 12
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  15. 7
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/MonitorExprent.java
  16. 23
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
  17. 5
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/SwitchExprent.java
  18. 4
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java
  19. 6
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/BasicBlockStatement.java
  20. 14
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
  21. 9
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
  22. 15
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
  23. 9
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java
  24. 17
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
  25. 6
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/RootStatement.java
  26. 13
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/SequenceStatement.java
  27. 5
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java
  28. 9
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java
  29. 9
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java

@ -814,7 +814,7 @@ public class ClassWriter {
try { try {
tracer.incrementCurrentSourceLine(buffer.count(lineSeparator, start_index_method)); tracer.incrementCurrentSourceLine(buffer.count(lineSeparator, start_index_method));
String code = root.toJava(indent + 1, tracer); TextBuffer code = root.toJava(indent + 1, tracer);
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0; hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;

@ -17,10 +17,7 @@ package org.jetbrains.java.decompiler.main;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** /**
* Allows to connect text with resulting lines * Allows to connect text with resulting lines
@ -32,7 +29,6 @@ public class TextBuffer {
private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING); private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);
private final StringBuilder myStringBuilder; private final StringBuilder myStringBuilder;
private Map<Integer, Integer> myLineToOffsetMapping = null; private Map<Integer, Integer> myLineToOffsetMapping = null;
private boolean myTrackLines = true;
public TextBuffer() { public TextBuffer() {
myStringBuilder = new StringBuilder(); myStringBuilder = new StringBuilder();
@ -42,12 +38,12 @@ public class TextBuffer {
myStringBuilder = new StringBuilder(size); myStringBuilder = new StringBuilder(size);
} }
public void setTrackLines(boolean trackLines) { public TextBuffer(String text) {
myTrackLines = false; myStringBuilder = new StringBuilder(text);
} }
public void setCurrentLine(int line) { public void setCurrentLine(int line) {
if (myTrackLines && line >= 0) { if (line >= 0) {
checkMapCreated(); checkMapCreated();
myLineToOffsetMapping.put(line, myStringBuilder.length()+1); myLineToOffsetMapping.put(line, myStringBuilder.length()+1);
} }
@ -75,6 +71,26 @@ public class TextBuffer {
return this; return this;
} }
public TextBuffer prepend(String s) {
insert(0, s);
return this;
}
public TextBuffer enclose(String left, String right) {
prepend(left);
append(right);
return this;
}
public boolean containsOnlyWhitespaces() {
for (int i = 0; i < myStringBuilder.length(); i++) {
if (myStringBuilder.charAt(i) != ' ') {
return false;
}
}
return true;
}
@Override @Override
public String toString() { public String toString() {
String original = myStringBuilder.toString(); String original = myStringBuilder.toString();
@ -117,9 +133,10 @@ public class TextBuffer {
private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) {
if (to - from > requiredLineNumber) { if (to - from > requiredLineNumber) {
List<String> strings = compactLines(Arrays.asList(srcLines).subList(from, to) ,requiredLineNumber);
int separatorsRequired = requiredLineNumber - 1; int separatorsRequired = requiredLineNumber - 1;
for (int i = from; i < to; i++) { for (String s : strings) {
res.append(srcLines[i]); res.append(s);
if (separatorsRequired-- > 0) { if (separatorsRequired-- > 0) {
res.append(myLineSeparator); res.append(myLineSeparator);
} }
@ -144,8 +161,23 @@ public class TextBuffer {
return myStringBuilder.substring(start); return myStringBuilder.substring(start);
} }
public TextBuffer setStart(int position) {
myStringBuilder.delete(0, position);
shiftMapping(0, -position);
return this;
}
public void setLength(int position) { public void setLength(int position) {
myStringBuilder.setLength(position); myStringBuilder.setLength(position);
if (myLineToOffsetMapping != null) {
HashMap<Integer, Integer> newMap = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : myLineToOffsetMapping.entrySet()) {
if (entry.getValue() <= position) {
newMap.put(entry.getKey(), entry.getValue());
}
}
myLineToOffsetMapping = newMap;
}
} }
public TextBuffer append(TextBuffer buffer) { public TextBuffer append(TextBuffer buffer) {
@ -161,11 +193,17 @@ public class TextBuffer {
private void shiftMapping(int startOffset, int shiftOffset) { private void shiftMapping(int startOffset, int shiftOffset) {
if (myLineToOffsetMapping != null) { if (myLineToOffsetMapping != null) {
HashMap<Integer, Integer> newMap = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : myLineToOffsetMapping.entrySet()) { for (Map.Entry<Integer, Integer> entry : myLineToOffsetMapping.entrySet()) {
if (entry.getValue() >= startOffset) { int newValue = entry.getValue();
myLineToOffsetMapping.put(entry.getKey(), entry.getValue() + shiftOffset); if (newValue >= startOffset) {
newValue += shiftOffset;
}
if (newValue >= 0) {
newMap.put(entry.getKey(), newValue);
} }
} }
myLineToOffsetMapping = newMap;
} }
} }
@ -189,4 +227,34 @@ public class TextBuffer {
} }
return count; return count;
} }
private static List<String> compactLines(List<String> srcLines, int requiredLineNumber) {
if (srcLines.size() < 2 || srcLines.size() <= requiredLineNumber) {
return srcLines;
}
List<String> res = new LinkedList<String>(srcLines);
// first join lines with a single { or }
for (int i = res.size()-1; i > 0 ; i--) {
String s = res.get(i);
if (s.trim().equals("{") || s.trim().equals("}")) {
res.set(i-1, res.get(i-1).concat(s));
res.remove(i);
}
if (res.size() <= requiredLineNumber) {
return res;
}
}
// now join empty lines
for (int i = res.size()-1; i > 0 ; i--) {
String s = res.get(i);
if (s.trim().isEmpty()) {
res.set(i-1, res.get(i-1).concat(s));
res.remove(i);
}
if (res.size() <= requiredLineNumber) {
return res;
}
}
return res;
}
} }

@ -756,8 +756,8 @@ public class ExprProcessor implements CodeConstants {
.isClassdef())); .isClassdef()));
} }
public static String jmpWrapper(Statement stat, int indent, boolean semicolon, BytecodeMappingTracer tracer) { public static TextBuffer jmpWrapper(Statement stat, int indent, boolean semicolon, BytecodeMappingTracer tracer) {
StringBuilder buf = new StringBuilder(stat.toJava(indent, tracer)); TextBuffer buf = stat.toJava(indent, tracer);
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
@ -776,7 +776,7 @@ public class ExprProcessor implements CodeConstants {
} }
if (edge.labeled) { if (edge.labeled) {
buf.append(" label").append(edge.closure.id); buf.append(" label").append(edge.closure.id.toString());
} }
buf.append(";").append(new_line_separator); buf.append(";").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
@ -788,7 +788,7 @@ public class ExprProcessor implements CodeConstants {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
return buf.toString(); return buf;
} }
public static String buildJavaClassName(String name) { public static String buildJavaClassName(String name) {
@ -805,18 +805,18 @@ public class ExprProcessor implements CodeConstants {
return res; return res;
} }
public static String listToJava(List<Exprent> lst, int indent, BytecodeMappingTracer tracer) { public static TextBuffer listToJava(List<Exprent> lst, int indent, BytecodeMappingTracer tracer) {
if (lst == null || lst.isEmpty()) { if (lst == null || lst.isEmpty()) {
return ""; return new TextBuffer();
} }
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
for (Exprent expr : lst) { for (Exprent expr : lst) {
String content = expr.toJava(indent, tracer); TextBuffer content = expr.toJava(indent, tracer);
if (content.length() > 0) { if (content.length() > 0) {
if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassdef()) { if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassdef()) {
buf.append(indstr); buf.append(indstr);
@ -833,7 +833,7 @@ public class ExprProcessor implements CodeConstants {
} }
} }
return buf.toString(); return buf;
} }
public static ConstExprent getDefaultArrayValue(VarType arrtype) { public static ConstExprent getDefaultArrayValue(VarType arrtype) {
@ -873,7 +873,7 @@ public class ExprProcessor implements CodeConstants {
boolean ret = false; boolean ret = false;
VarType rightType = exprent.getExprType(); VarType rightType = exprent.getExprType();
String res = exprent.toJava(indent, tracer); TextBuffer res = exprent.toJava(indent, tracer);
boolean cast = boolean cast =
!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT); !leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT);
@ -889,10 +889,10 @@ public class ExprProcessor implements CodeConstants {
if (cast) { if (cast) {
if (exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) { if (exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
res = "(" + res + ")"; res.enclose("(", ")");
} }
res = "(" + getCastTypeName(leftType) + ")" + res; res.prepend("(" + getCastTypeName(leftType) + ")");
ret = true; ret = true;
} }

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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.util.InterpreterUtil; import org.jetbrains.java.decompiler.util.InterpreterUtil;
@ -47,11 +48,11 @@ public class AnnotationExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buffer = new StringBuilder(); TextBuffer buffer = new TextBuffer();
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
buffer.append(indstr); buffer.append(indstr);
@ -82,7 +83,7 @@ public class AnnotationExprent extends Exprent {
buffer.append(")"); buffer.append(")");
} }
return buffer.toString(); return buffer;
} }
public int getAnnotationType() { public int getAnnotationType() {

@ -15,6 +15,7 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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.vars.CheckTypesResult; import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
@ -81,11 +82,11 @@ public class ArrayExprent extends Exprent {
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String res = array.toJava(indent, tracer); TextBuffer res = array.toJava(indent, tracer);
if (array.getPrecedence() > getPrecedence()) { // array precedence equals 0 if (array.getPrecedence() > getPrecedence()) { // array precedence equals 0
res = "(" + res + ")"; res.enclose("(", ")");
} }
VarType arrtype = array.getExprType(); VarType arrtype = array.getExprType();
@ -93,12 +94,12 @@ public class ArrayExprent extends Exprent {
VarType objarr = VarType.VARTYPE_OBJECT.copy(); VarType objarr = VarType.VARTYPE_OBJECT.copy();
objarr.arraydim = 1; // type family does not change objarr.arraydim = 1; // type family does not change
res = "((" + ExprProcessor.getCastTypeName(objarr) + ")" + res + ")"; res.enclose("((" + ExprProcessor.getCastTypeName(objarr) + ")", ")");
} }
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
return res + "[" + index.toJava(indent, tracer) + "]"; return res.append("[").append(index.toJava(indent, tracer)).append("]");
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.exps;
import java.util.List; import java.util.List;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
public class AssertExprent extends Exprent { public class AssertExprent extends Exprent {
@ -32,9 +33,9 @@ public class AssertExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
StringBuilder buffer = new StringBuilder(); TextBuffer buffer = new TextBuffer();
buffer.append("assert "); buffer.append("assert ");
@ -52,6 +53,6 @@ public class AssertExprent extends Exprent {
buffer.append(parameters.get(1).toJava(indent, tracer)); buffer.append(parameters.get(1).toJava(indent, tracer));
} }
return buffer.toString(); return buffer;
} }
} }

@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode; import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
@ -105,7 +106,7 @@ public class AssignmentExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
VarType leftType = left.getExprType(); VarType leftType = left.getExprType();
VarType rightType = right.getExprType(); VarType rightType = right.getExprType();
@ -127,10 +128,10 @@ public class AssignmentExprent extends Exprent {
} }
if (hiddenField) { if (hiddenField) {
return ""; return new TextBuffer();
} }
StringBuilder buffer = new StringBuilder(); TextBuffer buffer = new TextBuffer();
if (fieldInClassInit) { if (fieldInClassInit) {
buffer.append(((FieldExprent)left).getName()); buffer.append(((FieldExprent)left).getName());
@ -139,23 +140,23 @@ public class AssignmentExprent extends Exprent {
buffer.append(left.toJava(indent, tracer)); buffer.append(left.toJava(indent, tracer));
} }
String res = right.toJava(indent, tracer); TextBuffer res = right.toJava(indent, tracer);
if (condtype == CONDITION_NONE && if (condtype == CONDITION_NONE &&
!leftType.isSuperset(rightType) && !leftType.isSuperset(rightType) &&
(rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) { (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) {
if (right.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) { if (right.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
res = "(" + res + ")"; res.enclose("(", ")");
} }
res = "(" + ExprProcessor.getCastTypeName(leftType) + ")" + res; res.prepend("(" + ExprProcessor.getCastTypeName(leftType) + ")");
} }
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res); buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
return buffer.toString(); return buffer;
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
@ -108,19 +109,19 @@ public class ConstExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
boolean literal = DecompilerContext.getOption(IFernflowerPreferences.LITERALS_AS_IS); boolean literal = DecompilerContext.getOption(IFernflowerPreferences.LITERALS_AS_IS);
boolean ascii = DecompilerContext.getOption(IFernflowerPreferences.ASCII_STRING_CHARACTERS); boolean ascii = DecompilerContext.getOption(IFernflowerPreferences.ASCII_STRING_CHARACTERS);
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
if (consttype.type != CodeConstants.TYPE_NULL && value == null) { if (consttype.type != CodeConstants.TYPE_NULL && value == null) {
return ExprProcessor.getCastTypeName(consttype); return new TextBuffer(ExprProcessor.getCastTypeName(consttype));
} }
else { else {
switch (consttype.type) { switch (consttype.type) {
case CodeConstants.TYPE_BOOLEAN: case CodeConstants.TYPE_BOOLEAN:
return Boolean.toString(((Integer)value).intValue() != 0); return new TextBuffer(Boolean.toString(((Integer)value).intValue() != 0));
case CodeConstants.TYPE_CHAR: case CodeConstants.TYPE_CHAR:
Integer val = (Integer)value; Integer val = (Integer)value;
String ret = escapes.get(val); String ret = escapes.get(val);
@ -133,7 +134,7 @@ public class ConstExprent extends Exprent {
ret = InterpreterUtil.charToUnicodeLiteral(c); ret = InterpreterUtil.charToUnicodeLiteral(c);
} }
} }
return "\'" + ret + "\'"; return new TextBuffer(ret).enclose("\'", "\'");
case CodeConstants.TYPE_BYTE: case CodeConstants.TYPE_BYTE:
case CodeConstants.TYPE_BYTECHAR: case CodeConstants.TYPE_BYTECHAR:
case CodeConstants.TYPE_SHORT: case CodeConstants.TYPE_SHORT:
@ -143,7 +144,7 @@ public class ConstExprent extends Exprent {
String intfield; String intfield;
if (literal) { if (literal) {
return value.toString(); return new TextBuffer(value.toString());
} }
else if (ival == Integer.MAX_VALUE) { else if (ival == Integer.MAX_VALUE) {
intfield = "MAX_VALUE"; intfield = "MAX_VALUE";
@ -152,7 +153,7 @@ public class ConstExprent extends Exprent {
intfield = "MIN_VALUE"; intfield = "MIN_VALUE";
} }
else { else {
return value.toString(); return new TextBuffer(value.toString());
} }
return new FieldExprent(intfield, "java/lang/Integer", true, null, FieldDescriptor.INTEGER_DESCRIPTOR).toJava(0, tracer); return new FieldExprent(intfield, "java/lang/Integer", true, null, FieldDescriptor.INTEGER_DESCRIPTOR).toJava(0, tracer);
case CodeConstants.TYPE_LONG: case CodeConstants.TYPE_LONG:
@ -160,7 +161,7 @@ public class ConstExprent extends Exprent {
String longfield; String longfield;
if (literal) { if (literal) {
return value.toString() + "L"; return new TextBuffer(value.toString()).append("L");
} }
else if (lval == Long.MAX_VALUE) { else if (lval == Long.MAX_VALUE) {
longfield = "MAX_VALUE"; longfield = "MAX_VALUE";
@ -169,7 +170,7 @@ public class ConstExprent extends Exprent {
longfield = "MIN_VALUE"; longfield = "MIN_VALUE";
} }
else { else {
return value.toString() + "L"; return new TextBuffer(value.toString()).append("L");
} }
return new FieldExprent(longfield, "java/lang/Long", true, null, FieldDescriptor.LONG_DESCRIPTOR).toJava(0, tracer); return new FieldExprent(longfield, "java/lang/Long", true, null, FieldDescriptor.LONG_DESCRIPTOR).toJava(0, tracer);
case CodeConstants.TYPE_DOUBLE: case CodeConstants.TYPE_DOUBLE:
@ -178,16 +179,16 @@ public class ConstExprent extends Exprent {
String doublefield; String doublefield;
if (literal) { if (literal) {
if (Double.isNaN(dval)) { if (Double.isNaN(dval)) {
return "0.0D / 0.0"; return new TextBuffer("0.0D / 0.0");
} }
else if (dval == Double.POSITIVE_INFINITY) { else if (dval == Double.POSITIVE_INFINITY) {
return "1.0D / 0.0"; return new TextBuffer("1.0D / 0.0");
} }
else if (dval == Double.NEGATIVE_INFINITY) { else if (dval == Double.NEGATIVE_INFINITY) {
return "-1.0D / 0.0"; return new TextBuffer("-1.0D / 0.0");
} }
else { else {
return value.toString() + "D"; return new TextBuffer(value.toString()).append("D");
} }
} }
else if (Double.isNaN(dval)) { else if (Double.isNaN(dval)) {
@ -206,7 +207,7 @@ public class ConstExprent extends Exprent {
doublefield = "MIN_VALUE"; doublefield = "MIN_VALUE";
} }
else { else {
return value.toString() + "D"; return new TextBuffer(value.toString()).append("D");
} }
return new FieldExprent(doublefield, "java/lang/Double", true, null, FieldDescriptor.DOUBLE_DESCRIPTOR).toJava(0, tracer); return new FieldExprent(doublefield, "java/lang/Double", true, null, FieldDescriptor.DOUBLE_DESCRIPTOR).toJava(0, tracer);
case CodeConstants.TYPE_FLOAT: case CodeConstants.TYPE_FLOAT:
@ -215,16 +216,16 @@ public class ConstExprent extends Exprent {
String floatfield; String floatfield;
if (literal) { if (literal) {
if (Double.isNaN(fval)) { if (Double.isNaN(fval)) {
return "0.0F / 0.0"; return new TextBuffer("0.0F / 0.0");
} }
else if (fval == Double.POSITIVE_INFINITY) { else if (fval == Double.POSITIVE_INFINITY) {
return "1.0F / 0.0"; return new TextBuffer("1.0F / 0.0");
} }
else if (fval == Double.NEGATIVE_INFINITY) { else if (fval == Double.NEGATIVE_INFINITY) {
return "-1.0F / 0.0"; return new TextBuffer("-1.0F / 0.0");
} }
else { else {
return value.toString() + "F"; return new TextBuffer(value.toString()).append("F");
} }
} }
else if (Float.isNaN(fval)) { else if (Float.isNaN(fval)) {
@ -243,14 +244,14 @@ public class ConstExprent extends Exprent {
floatfield = "MIN_VALUE"; floatfield = "MIN_VALUE";
} }
else { else {
return value.toString() + "F"; return new TextBuffer(value.toString()).append("F");
} }
return new FieldExprent(floatfield, "java/lang/Float", true, null, FieldDescriptor.FLOAT_DESCRIPTOR).toJava(0, tracer); return new FieldExprent(floatfield, "java/lang/Float", true, null, FieldDescriptor.FLOAT_DESCRIPTOR).toJava(0, tracer);
case CodeConstants.TYPE_NULL: case CodeConstants.TYPE_NULL:
return "null"; return new TextBuffer("null");
case CodeConstants.TYPE_OBJECT: case CodeConstants.TYPE_OBJECT:
if (consttype.equals(VarType.VARTYPE_STRING)) { if (consttype.equals(VarType.VARTYPE_STRING)) {
return "\"" + convertStringToJava(value.toString(), ascii) + "\""; return new TextBuffer(convertStringToJava(value.toString(), ascii)).enclose("\"", "\"");
} }
else if (consttype.equals(VarType.VARTYPE_CLASS)) { else if (consttype.equals(VarType.VARTYPE_CLASS)) {
String strval = value.toString(); String strval = value.toString();
@ -263,7 +264,7 @@ public class ConstExprent extends Exprent {
classtype = new VarType(strval, true); classtype = new VarType(strval, true);
} }
return ExprProcessor.getCastTypeName(classtype) + ".class"; return new TextBuffer(ExprProcessor.getCastTypeName(classtype)).append(".class");
} }
} }
} }

@ -77,7 +77,7 @@ public class ExitExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
@ -89,7 +89,7 @@ public class ExitExprent extends Exprent {
ExprProcessor.getCastedExprent(value, rettype, buffer, indent, false, tracer); ExprProcessor.getCastedExprent(value, rettype, buffer, indent, false, tracer);
} }
return "return" + buffer.toString(); return buffer.prepend("return");
} }
else { else {
@ -119,12 +119,12 @@ public class ExitExprent extends Exprent {
TextBuffer buffer = new TextBuffer(); TextBuffer buffer = new TextBuffer();
ExprProcessor.getCastedExprent(value, exctype, buffer, indent, false, tracer); ExprProcessor.getCastedExprent(value, exctype, buffer, indent, false, tracer);
return "throw " + buffer.toString(); return buffer.prepend("throw ");
} }
} }
} }
return "throw " + value.toJava(indent, tracer); return value.toJava(indent, tracer).prepend("throw ");
} }
} }

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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.vars.CheckTypesResult; import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
@ -128,7 +129,7 @@ public class Exprent {
throw new RuntimeException("not implemented"); throw new RuntimeException("not implemented");
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
throw new RuntimeException("not implemented"); throw new RuntimeException("not implemented");
} }

@ -96,8 +96,8 @@ public class FieldExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
if (isStatic) { if (isStatic) {
@ -162,7 +162,7 @@ public class FieldExprent extends Exprent {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
return buf.toString(); return buf;
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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.vars.CheckTypesResult; import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
@ -448,87 +449,87 @@ public class FunctionExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
if (functype <= FUNCTION_USHR) { if (functype <= FUNCTION_USHR) {
return wrapOperandString(lstOperands.get(0), false, indent, tracer) + operators[functype] + return wrapOperandString(lstOperands.get(0), false, indent, tracer)
wrapOperandString(lstOperands.get(1), true, indent, tracer); .append(operators[functype])
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
} }
if (functype >= FUNCTION_EQ) { if (functype >= FUNCTION_EQ) {
return wrapOperandString(lstOperands.get(0), false, indent, tracer) + operators[functype - FUNCTION_EQ + 11] + return wrapOperandString(lstOperands.get(0), false, indent, tracer)
wrapOperandString(lstOperands.get(1), true, indent, tracer); .append(operators[functype - FUNCTION_EQ + 11])
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
} }
switch (functype) { switch (functype) {
case FUNCTION_BITNOT: case FUNCTION_BITNOT:
return "~" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("~");
case FUNCTION_BOOLNOT: case FUNCTION_BOOLNOT:
return "!" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("!");
case FUNCTION_NEG: case FUNCTION_NEG:
return "-" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("-");
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).enclose("(", ")").append(wrapOperandString(lstOperands.get(0), true, indent, tracer));
case FUNCTION_ARRAYLENGTH: case FUNCTION_ARRAYLENGTH:
Exprent arr = lstOperands.get(0); Exprent arr = lstOperands.get(0);
String res = wrapOperandString(arr, false, indent, tracer); TextBuffer res = wrapOperandString(arr, false, indent, tracer);
if (arr.getExprType().arraydim == 0) { if (arr.getExprType().arraydim == 0) {
VarType objarr = VarType.VARTYPE_OBJECT.copy(); VarType objarr = VarType.VARTYPE_OBJECT.copy();
objarr.arraydim = 1; // type family does not change objarr.arraydim = 1; // type family does not change
res = "((" + ExprProcessor.getCastTypeName(objarr) + ")" + res + ")"; res.enclose("((" + ExprProcessor.getCastTypeName(objarr) + ")", ")");
} }
return res + ".length"; return res.append(".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(2), true, indent, tracer); .append("?")
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
.append(":")
.append(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).append("++");
case FUNCTION_PPI: case FUNCTION_PPI:
return "++" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("++");
case FUNCTION_IMM: case FUNCTION_IMM:
return wrapOperandString(lstOperands.get(0), true, indent, tracer) + "--"; return wrapOperandString(lstOperands.get(0), true, indent, tracer).append("--");
case FUNCTION_MMI: case FUNCTION_MMI:
return "--" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("--");
case FUNCTION_INSTANCEOF: case FUNCTION_INSTANCEOF:
return wrapOperandString(lstOperands.get(0), true, indent, tracer) + " instanceof " + wrapOperandString(lstOperands.get(1), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).append(" instanceof ").append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
case FUNCTION_LCMP: // shouldn't appear in the final code case FUNCTION_LCMP: // shouldn't appear in the final code
return "__lcmp__(" + return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("__lcmp__(")
wrapOperandString(lstOperands.get(0), true, indent, tracer) + .append(",")
"," + .append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
wrapOperandString(lstOperands.get(1), true, indent, tracer) + .append(")");
")";
case FUNCTION_FCMPL: // shouldn't appear in the final code case FUNCTION_FCMPL: // shouldn't appear in the final code
return "__fcmpl__(" + return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("__fcmpl__(")
wrapOperandString(lstOperands.get(0), true, indent, tracer) + .append(",")
"," + .append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
wrapOperandString(lstOperands.get(1), true, indent, tracer) + .append(")");
")";
case FUNCTION_FCMPG: // shouldn't appear in the final code case FUNCTION_FCMPG: // shouldn't appear in the final code
return "__fcmpg__(" + return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("__fcmpg__(")
wrapOperandString(lstOperands.get(0), true, indent, tracer) + .append(",")
"," + .append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
wrapOperandString(lstOperands.get(1), true, indent, tracer) + .append(")");
")";
case FUNCTION_DCMPL: // shouldn't appear in the final code case FUNCTION_DCMPL: // shouldn't appear in the final code
return "__dcmpl__(" + return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("__dcmpl__(")
wrapOperandString(lstOperands.get(0), true, indent, tracer) + .append(",")
"," + .append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
wrapOperandString(lstOperands.get(1), true, indent, tracer) + .append(")");
")";
case FUNCTION_DCMPG: // shouldn't appear in the final code case FUNCTION_DCMPG: // shouldn't appear in the final code
return "__dcmpg__(" + return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("__dcmpg__(")
wrapOperandString(lstOperands.get(0), true, indent, tracer) + .append(",")
"," + .append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
wrapOperandString(lstOperands.get(1), true, indent, tracer) + .append(")");
")";
} }
if (functype <= FUNCTION_I2S) { if (functype <= FUNCTION_I2S) {
return "(" + ExprProcessor.getTypeName(types[functype - FUNCTION_I2L]) + ")" + wrapOperandString(lstOperands.get(0), true, indent, tracer); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("(" + ExprProcessor.getTypeName(types[functype - FUNCTION_I2L]) + ")");
} }
// return "<unknown function>"; // return "<unknown function>";
@ -547,7 +548,7 @@ public class FunctionExprent extends Exprent {
return types[functype - FUNCTION_I2L]; return types[functype - FUNCTION_I2L];
} }
private String wrapOperandString(Exprent expr, boolean eq, int indent, BytecodeMappingTracer tracer) { private TextBuffer wrapOperandString(Exprent expr, boolean eq, int indent, BytecodeMappingTracer tracer) {
int myprec = getPrecedence(); int myprec = getPrecedence();
int exprprec = expr.getPrecedence(); int exprprec = expr.getPrecedence();
@ -563,10 +564,10 @@ public class FunctionExprent extends Exprent {
} }
} }
String res = expr.toJava(indent, tracer); TextBuffer res = expr.toJava(indent, tracer);
if (parentheses) { if (parentheses) {
res = "(" + res + ")"; res.enclose("(", ")");
} }
return res; return res;

@ -15,6 +15,7 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
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;
@ -113,9 +114,9 @@ public class IfExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
return "if(" + condition.toJava(indent, tracer) + ")"; return condition.toJava(indent, tracer).enclose("if(", ")");
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -189,8 +189,8 @@ public class InvocationExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
StringBuilder buf = new StringBuilder(""); TextBuffer buf = new TextBuffer();
String super_qualifier = null; String super_qualifier = null;
boolean isInstanceThis = false; boolean isInstanceThis = false;
@ -276,7 +276,7 @@ public class InvocationExprent extends Exprent {
buf.append("super"); buf.append("super");
} }
else { else {
String res = instance.toJava(indent, tracer); TextBuffer res = instance.toJava(indent, tracer);
VarType rightType = instance.getExprType(); VarType rightType = instance.getExprType();
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname); VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
@ -285,7 +285,7 @@ public class InvocationExprent extends Exprent {
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.enclose("(", ")");
} }
buf.append(res).append(")"); buf.append(res).append(")");
} }
@ -302,7 +302,7 @@ public class InvocationExprent extends Exprent {
switch (functype) { switch (functype) {
case TYP_GENERAL: case TYP_GENERAL:
if (VarExprent.VAR_NAMELESS_ENCLOSURE.equals(buf.toString())) { if (VarExprent.VAR_NAMELESS_ENCLOSURE.equals(buf.toString())) {
buf = new StringBuilder(""); buf = new TextBuffer();
} }
if (buf.length() > 0) { if (buf.length() > 0) {
@ -370,7 +370,7 @@ public class InvocationExprent extends Exprent {
} }
buf.append(")"); buf.append(")");
return buf.toString(); return buf;
} }
private Set<Integer> getAmbiguousParameters() { private Set<Integer> getAmbiguousParameters() {

@ -15,6 +15,7 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.util.InterpreterUtil; import org.jetbrains.java.decompiler.util.InterpreterUtil;
@ -51,15 +52,15 @@ public class MonitorExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
if (montype == MONITOR_ENTER) { if (montype == MONITOR_ENTER) {
return "synchronized(" + value.toJava(indent, tracer) + ")"; return value.toJava(indent, tracer).enclose("synchronized(", ")");
} }
else { else {
return ""; return new TextBuffer();
} }
} }

@ -172,7 +172,7 @@ public class NewExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
TextBuffer buf = new TextBuffer(); TextBuffer buf = new TextBuffer();
if (anonymous) { if (anonymous) {
@ -247,10 +247,10 @@ public class NewExprent extends Exprent {
typename = typename.substring(typename.lastIndexOf('.') + 1); typename = typename.substring(typename.lastIndexOf('.') + 1);
} }
} }
buf.insert(0, "new " + typename); buf.prepend("new " + typename);
if (enclosing != null) { if (enclosing != null) {
buf.insert(0, enclosing + "."); buf.prepend(enclosing + ".");
} }
} }
@ -268,10 +268,7 @@ public class NewExprent extends Exprent {
new ClassWriter().classLambdaToJava(child, buf, methodObject, indent); new ClassWriter().classLambdaToJava(child, buf, methodObject, indent);
} }
else { else {
// do not track lines in sub classes for now
buf.setTrackLines(false);
new ClassWriter().classToJava(child, buf, indent); new ClassWriter().classToJava(child, buf, indent);
buf.setTrackLines(true);
} }
} }
else if (directArrayInit) { else if (directArrayInit) {
@ -349,10 +346,10 @@ public class NewExprent extends Exprent {
typename = typename.substring(typename.lastIndexOf('.') + 1); typename = typename.substring(typename.lastIndexOf('.') + 1);
} }
} }
buf.insert(0, "new " + typename); buf.prepend("new " + typename);
if (enclosing != null) { if (enclosing != null) {
buf.insert(0, enclosing + "."); buf.prepend(enclosing + ".");
} }
} }
} }
@ -361,7 +358,11 @@ public class NewExprent extends Exprent {
if (lstArrayElements.isEmpty()) { if (lstArrayElements.isEmpty()) {
for (int i = 0; i < newtype.arraydim; i++) { for (int i = 0; i < newtype.arraydim; i++) {
buf.append("[").append(i < lstDims.size() ? lstDims.get(i).toJava(indent, tracer) : "").append("]"); buf.append("[");
if (i < lstDims.size()) {
buf.append(lstDims.get(i).toJava(indent, tracer));
}
buf.append("]");
} }
} }
else { else {
@ -386,7 +387,7 @@ public class NewExprent extends Exprent {
} }
} }
} }
return buf.toString(); return buf;
} }
private static String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent, BytecodeMappingTracer tracer) { private static String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent, BytecodeMappingTracer tracer) {
@ -414,7 +415,7 @@ public class NewExprent extends Exprent {
} }
if (isQualifiedNew) { if (isQualifiedNew) {
return enclosing.toJava(indent, tracer); return enclosing.toJava(indent, tracer).toString();
} }
} }
} }

@ -15,6 +15,7 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.exps; package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult; import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
import org.jetbrains.java.decompiler.struct.gen.VarType; import org.jetbrains.java.decompiler.struct.gen.VarType;
@ -83,9 +84,9 @@ public class SwitchExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
return "switch(" + value.toJava(indent, tracer) + ")"; return value.toJava(indent, tracer).enclose("switch(", ")");
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -83,7 +83,7 @@ public class VarExprent extends Exprent {
} }
@Override @Override
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
TextBuffer buffer = new TextBuffer(); TextBuffer buffer = new TextBuffer();
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
@ -107,7 +107,7 @@ public class VarExprent extends Exprent {
buffer.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name); buffer.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);
} }
return buffer.toString(); return buffer;
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -20,6 +20,7 @@ import org.jetbrains.java.decompiler.code.Instruction;
import org.jetbrains.java.decompiler.code.SimpleInstructionSequence; import org.jetbrains.java.decompiler.code.SimpleInstructionSequence;
import org.jetbrains.java.decompiler.code.cfg.BasicBlock; import org.jetbrains.java.decompiler.code.cfg.BasicBlock;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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;
@ -66,9 +67,8 @@ public class BasicBlockStatement extends Statement {
// public methods // public methods
// ***************************************************************************** // *****************************************************************************
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
return ExprProcessor.listToJava(varDefinitions, indent, tracer) + return ExprProcessor.listToJava(varDefinitions, indent, tracer).append(ExprProcessor.listToJava(exprents, indent, tracer));
ExprProcessor.listToJava(exprents, indent, tracer);
} }
public Statement getSimpleCopy() { public Statement getSimpleCopy() {

@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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.DecHelper; import org.jetbrains.java.decompiler.modules.decompiler.DecHelper;
@ -111,28 +112,27 @@ public class CatchAllStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
String indstr1 = null; String indstr1 = null;
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
boolean labeled = isLabeled(); boolean labeled = isLabeled();
if (labeled) { if (labeled) {
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
List<StatEdge> lstSuccs = first.getSuccessorEdges(STATEDGE_DIRECT_ALL); List<StatEdge> lstSuccs = first.getSuccessorEdges(STATEDGE_DIRECT_ALL);
if (first.type == TYPE_TRYCATCH && first.varDefinitions.isEmpty() && isFinally && if (first.type == TYPE_TRYCATCH && first.varDefinitions.isEmpty() && isFinally &&
!labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) { !labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) {
String content = ExprProcessor.jmpWrapper(first, indent, true, tracer); TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer);
content = content.substring(0, content.length() - new_line_separator.length()); content.setStart(content.length() - new_line_separator.length());
buf.append(content); buf.append(content);
} }
else { else {
@ -162,7 +162,7 @@ public class CatchAllStatement extends Statement {
buf.append(indstr).append("}").append(new_line_separator); buf.append(indstr).append("}").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf.toString(); return buf;
} }
public void replaceStatement(Statement oldstat, Statement newstat) { public void replaceStatement(Statement oldstat, Statement newstat) {

@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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.DecHelper; import org.jetbrains.java.decompiler.modules.decompiler.DecHelper;
@ -150,16 +151,16 @@ public class CatchStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
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));
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.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -191,7 +192,7 @@ public class CatchStatement extends Statement {
buf.append(new_line_separator); buf.append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf.toString(); return buf;
} }
public Statement getSimpleCopy() { public Statement getSimpleCopy() {

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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.StatEdge; import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
@ -92,16 +93,16 @@ public class DoStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
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));
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.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -128,7 +129,11 @@ public class DoStatement extends Statement {
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(");
if (initExprent.get(0) != null) {
buf.append(initExprent.get(0).toJava(indent, tracer));
}
buf.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,7 +142,7 @@ public class DoStatement extends Statement {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
return buf.toString(); return buf;
} }
public List<Object> getSequentialObjects() { public List<Object> getSequentialObjects() {

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.util.InterpreterUtil; import org.jetbrains.java.decompiler.util.InterpreterUtil;
@ -54,14 +55,14 @@ public class GeneralStatement extends Statement {
// public methods // public methods
// ***************************************************************************** // *****************************************************************************
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
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.toString()).append(":").append(new_line_separator);
} }
buf.append(indstr).append("abstract statement {").append(new_line_separator); buf.append(indstr).append("abstract statement {").append(new_line_separator);
@ -70,6 +71,6 @@ public class GeneralStatement extends Statement {
} }
buf.append(indstr).append("}"); buf.append(indstr).append("}");
return buf.toString(); return buf;
} }
} }

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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;
@ -200,9 +201,9 @@ public class IfStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
@ -210,7 +211,7 @@ public class IfStatement extends Statement {
buf.append(first.toJava(indent, tracer)); buf.append(first.toJava(indent, tracer));
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.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -231,7 +232,7 @@ public class IfStatement extends Statement {
} }
if (ifedge.labeled) { if (ifedge.labeled) {
buf.append(" label").append(ifedge.closure.id); buf.append(" label").append(ifedge.closure.id.toString());
} }
} }
buf.append(";").append(new_line_separator); buf.append(";").append(new_line_separator);
@ -249,8 +250,8 @@ public class IfStatement extends Statement {
!elsestat.isLabeled() && !elsestat.isLabeled() &&
(elsestat.getSuccessorEdges(STATEDGE_DIRECT_ALL).isEmpty() (elsestat.getSuccessorEdges(STATEDGE_DIRECT_ALL).isEmpty()
|| !elsestat.getSuccessorEdges(STATEDGE_DIRECT_ALL).get(0).explicit)) { // else if || !elsestat.getSuccessorEdges(STATEDGE_DIRECT_ALL).get(0).explicit)) { // else if
String content = ExprProcessor.jmpWrapper(elsestat, indent, false, tracer); TextBuffer content = ExprProcessor.jmpWrapper(elsestat, indent, false, tracer);
content = content.substring(indstr.length()); content.setStart(indstr.length());
buf.append(indstr).append("} else "); buf.append(indstr).append("} else ");
buf.append(content); buf.append(content);
@ -259,7 +260,7 @@ public class IfStatement extends Statement {
} }
else { else {
BytecodeMappingTracer else_tracer = new BytecodeMappingTracer(tracer.getCurrentSourceLine()); BytecodeMappingTracer else_tracer = new BytecodeMappingTracer(tracer.getCurrentSourceLine());
String content = ExprProcessor.jmpWrapper(elsestat, indent + 1, false, else_tracer); TextBuffer content = ExprProcessor.jmpWrapper(elsestat, indent + 1, false, else_tracer);
if (content.length() > 0) { if (content.length() > 0) {
buf.append(indstr).append("} else {").append(new_line_separator); buf.append(indstr).append("} else {").append(new_line_separator);
@ -278,7 +279,7 @@ public class IfStatement extends Statement {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
return buf.toString(); return buf;
} }
public void initExprents() { public void initExprents() {

@ -15,6 +15,7 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
@ -34,9 +35,8 @@ public class RootStatement extends Statement {
first.setParent(this); first.setParent(this);
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
return ExprProcessor.listToJava(varDefinitions, indent, tracer) + return ExprProcessor.listToJava(varDefinitions, indent, tracer).append(first.toJava(indent, tracer));
first.toJava(indent, tracer);
} }
public Statement getDummyExit() { public Statement getDummyExit() {

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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;
@ -99,9 +100,9 @@ public class SequenceStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
String indstr = null; String indstr = null;
boolean islabeled = isLabeled(); boolean islabeled = isLabeled();
@ -113,7 +114,7 @@ public class SequenceStatement extends Statement {
if (islabeled) { if (islabeled) {
indstr = InterpreterUtil.getIndentString(indent); indstr = InterpreterUtil.getIndentString(indent);
indent++; indent++;
buf.append(indstr).append("label").append(this.id).append(": {").append(new_line_separator); buf.append(indstr).append("label").append(this.id.toString()).append(": {").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -128,10 +129,10 @@ public class SequenceStatement extends Statement {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
String str = ExprProcessor.jmpWrapper(st, indent, false, tracer); TextBuffer str = ExprProcessor.jmpWrapper(st, indent, false, tracer);
buf.append(str); buf.append(str);
notempty = (str.trim().length() > 0); notempty = !str.containsOnlyWhitespaces();
} }
if (islabeled) { if (islabeled) {
@ -139,7 +140,7 @@ public class SequenceStatement extends Statement {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
return buf.toString(); return buf;
} }
public Statement getSimpleCopy() { public Statement getSimpleCopy() {

@ -18,6 +18,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.code.InstructionSequence; import org.jetbrains.java.decompiler.code.InstructionSequence;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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.StatEdge; import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
@ -489,11 +490,11 @@ public class Statement {
} }
// to be overwritten // to be overwritten
public String toJava() { public TextBuffer toJava() {
return toJava(0, new BytecodeMappingTracer()); return toJava(0, new BytecodeMappingTracer());
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
throw new RuntimeException("not implemented"); throw new RuntimeException("not implemented");
} }

@ -18,6 +18,7 @@ package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.SwitchInstruction; import org.jetbrains.java.decompiler.code.SwitchInstruction;
import org.jetbrains.java.decompiler.code.cfg.BasicBlock; import org.jetbrains.java.decompiler.code.cfg.BasicBlock;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
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.DecHelper; import org.jetbrains.java.decompiler.modules.decompiler.DecHelper;
@ -107,18 +108,18 @@ public class SwitchStatement extends Statement {
return null; return null;
} }
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
buf.append(first.toJava(indent, tracer)); buf.append(first.toJava(indent, tracer));
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.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -153,7 +154,7 @@ public class SwitchStatement extends Statement {
buf.append(indstr).append("}").append(new_line_separator); buf.append(indstr).append("}").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf.toString(); return buf;
} }
public void initExprents() { public void initExprents() {

@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; 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;
@ -69,17 +70,17 @@ public class SynchronizedStatement extends Statement {
// public methods // public methods
// ***************************************************************************** // *****************************************************************************
public String toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder(); TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
buf.append(first.toJava(indent, tracer)); buf.append(first.toJava(indent, tracer));
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.toString()).append(":").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -92,7 +93,7 @@ public class SynchronizedStatement extends Statement {
buf.append(indstr).append("}").append(new_line_separator); buf.append(indstr).append("}").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf.toString(); return buf;
} }
public void initExprents() { public void initExprents() {

Loading…
Cancel
Save