decompiler: use more TextBuffer methods

master
Egor.Ushakov 10 years ago
parent 56b3edd3ca
commit eb3db8dc8b
  1. 9
      src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
  2. 4
      src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java
  3. 12
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java
  4. 16
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
  5. 25
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
  6. 15
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java
  7. 15
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
  8. 16
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java

@ -258,7 +258,6 @@ public class ClassesProcessor {
TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE);
new ClassWriter().classToJava(root, classBuffer, 0, null);
String lineSeparator = DecompilerContext.getNewLineSeparator();
int total_offset_lines = 0;
int index = cl.qualifiedName.lastIndexOf("/");
@ -269,13 +268,13 @@ public class ClassesProcessor {
buffer.append("package ");
buffer.append(packageName);
buffer.append(";");
buffer.append(lineSeparator);
buffer.append(lineSeparator);
buffer.appendLineSeparator();
buffer.appendLineSeparator();
}
int import_lines_written = importCollector.writeImports(buffer);
if (import_lines_written > 0) {
buffer.append(lineSeparator);
buffer.appendLineSeparator();
total_offset_lines += import_lines_written + 1;
}
//buffer.append(lineSeparator);
@ -287,7 +286,7 @@ public class ClassesProcessor {
BytecodeSourceMapper mapper = DecompilerContext.getBytecodeSourceMapper();
mapper.addTotalOffset(total_offset_lines);
if (DecompilerContext.getOption(IFernflowerPreferences.UNIT_TEST_MODE)) {
buffer.append(lineSeparator);
buffer.appendLineSeparator();
mapper.dumpMapping(buffer, true);
}
}

@ -109,9 +109,7 @@ public class ImportCollector {
}
public int writeImports(TextBuffer buffer) {
int importlines_written = 0;
String new_line_separator = DecompilerContext.getNewLineSeparator();
List<String> imports = packImports();
@ -119,7 +117,7 @@ public class ImportCollector {
buffer.append("import ");
buffer.append(s);
buffer.append(";");
buffer.append(new_line_separator);
buffer.appendLineSeparator();
importlines_written++;
}

@ -49,13 +49,9 @@ public class AnnotationExprent extends Exprent {
@Override
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String new_line_separator = DecompilerContext.getNewLineSeparator();
TextBuffer buffer = new TextBuffer();
String indstr = InterpreterUtil.getIndentString(indent);
buffer.append(indstr);
buffer.appendIndent(indent);
buffer.append("@");
buffer.append(DecompilerContext.getImportCollector().getShortName(ExprProcessor.buildJavaClassName(classname)));
@ -65,10 +61,8 @@ public class AnnotationExprent extends Exprent {
buffer.append(parvalues.get(0).toJava(indent + 1, tracer));
}
else {
String indstr1 = InterpreterUtil.getIndentString(indent + 1);
for (int i = 0; i < parnames.size(); i++) {
buffer.append(new_line_separator).append(indstr1);
buffer.appendLineSeparator().appendIndent(indent + 1);
buffer.append(parnames.get(i));
buffer.append(" = ");
buffer.append(parvalues.get(i).toJava(indent + 2, tracer));
@ -77,7 +71,7 @@ public class AnnotationExprent extends Exprent {
buffer.append(",");
}
}
buffer.append(new_line_separator).append(indstr);
buffer.appendLineSeparator().appendIndent(indent);
}
buffer.append(")");

@ -26,7 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.ArrayList;
import java.util.HashSet;
@ -152,23 +151,20 @@ public class CatchStatement extends Statement {
}
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent);
TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
buf.append(indstr).append("try {").append(new_line_separator);
buf.appendIndent(indent).append("try {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}");
buf.appendIndent(indent).append("}");
for (int i = 1; i < stats.size(); i++) {
List<String> exception_types = exctstrings.get(i - 1);
@ -183,12 +179,12 @@ public class CatchStatement extends Statement {
}
}
buf.append(vars.get(i - 1).toJava(indent, tracer));
buf.append(") {").append(new_line_separator);
buf.append(") {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true, tracer)).append(indstr)
buf.append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true, tracer)).appendIndent(indent)
.append("}");
}
buf.append(new_line_separator);
buf.appendLineSeparator();
tracer.incrementCurrentSourceLine();
return buf;

@ -15,13 +15,11 @@
*/
package org.jetbrains.java.decompiler.modules.decompiler.stats;
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.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.ArrayList;
import java.util.List;
@ -94,51 +92,48 @@ public class DoStatement extends Statement {
}
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent);
TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
switch (looptype) {
case LOOP_DO:
buf.append(indstr).append("while(true) {").append(new_line_separator);
buf.appendIndent(indent).append("while(true) {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}").append(new_line_separator);
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
case LOOP_DOWHILE:
buf.append(indstr).append("do {").append(new_line_separator);
buf.appendIndent(indent).append("do {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("} while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").append(new_line_separator);
buf.appendIndent(indent).append("} while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
case LOOP_WHILE:
buf.append(indstr).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").append(new_line_separator);
buf.appendIndent(indent).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}").append(new_line_separator);
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
case LOOP_FOR:
buf.append(indstr).append("for(");
buf.appendIndent(indent).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(new_line_separator);
.appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}").append(new_line_separator);
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

@ -15,10 +15,8 @@
*/
package org.jetbrains.java.decompiler.modules.decompiler.stats;
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.util.InterpreterUtil;
import java.util.Collection;
import java.util.HashSet;
@ -56,20 +54,17 @@ public class GeneralStatement extends Statement {
// *****************************************************************************
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent);
TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator();
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
}
buf.append(indstr).append("abstract statement {").append(new_line_separator);
for (int i = 0; i < stats.size(); i++) {
buf.append(stats.get(i).toJava(indent + 1, tracer));
buf.appendIndent(indent).append("abstract statement {").appendLineSeparator();
for (Statement stat : stats) {
buf.append(stat.toJava(indent + 1, tracer));
}
buf.append(indstr).append("}");
buf.appendIndent(indent).append("}");
return buf;
}

@ -15,7 +15,6 @@
*/
package org.jetbrains.java.decompiler.modules.decompiler.stats;
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.modules.decompiler.DecHelper;
@ -205,17 +204,15 @@ public class IfStatement extends Statement {
String indstr = InterpreterUtil.getIndentString(indent);
TextBuffer buf = new TextBuffer();
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
buf.append(first.toJava(indent, tracer));
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
buf.append(indstr).append(headexprent.get(0).toJava(indent, tracer)).append(" {").append(new_line_separator);
buf.appendIndent(indent).append(headexprent.get(0).toJava(indent, tracer)).append(" {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
if (ifstat == null) {
@ -235,7 +232,7 @@ public class IfStatement extends Statement {
buf.append(" label").append(ifedge.closure.id.toString());
}
}
buf.append(";").append(new_line_separator);
buf.append(";").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
else {
@ -253,7 +250,7 @@ public class IfStatement extends Statement {
TextBuffer content = ExprProcessor.jmpWrapper(elsestat, indent, false, tracer);
content.setStart(indstr.length());
buf.append(indstr).append("} else ");
buf.appendIndent(indent).append("} else ");
buf.append(content);
elseif = true;
@ -263,7 +260,7 @@ public class IfStatement extends Statement {
TextBuffer content = ExprProcessor.jmpWrapper(elsestat, indent + 1, false, else_tracer);
if (content.length() > 0) {
buf.append(indstr).append("} else {").append(new_line_separator);
buf.appendIndent(indent).append("} else {").appendLineSeparator();
else_tracer.shiftSourceLines(1);
tracer.setCurrentSourceLine(else_tracer.getCurrentSourceLine() + 1);
@ -275,7 +272,7 @@ public class IfStatement extends Statement {
}
if (!elseif) {
buf.append(indstr).append("}").append(new_line_separator);
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

@ -28,7 +28,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.SwitchExprent;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.*;
@ -109,21 +108,16 @@ public class SwitchStatement extends Statement {
}
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent);
String new_line_separator = DecompilerContext.getNewLineSeparator();
TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
buf.append(first.toJava(indent, tracer));
if (isLabeled()) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
buf.append(indstr).append(headexprent.get(0).toJava(indent, tracer)).append(" {").append(new_line_separator);
buf.appendIndent(indent).append(headexprent.get(0).toJava(indent, tracer)).append(" {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
VarType switch_type = headexprent.get(0).getExprType();
@ -136,14 +130,14 @@ public class SwitchStatement extends Statement {
for (int j = 0; j < edges.size(); j++) {
if (edges.get(j) == default_edge) {
buf.append(indstr).append("default:").append(new_line_separator);
buf.appendIndent(indent).append("default:").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
else {
ConstExprent value = (ConstExprent)values.get(j).copy();
value.setConsttype(switch_type);
buf.append(indstr).append("case ").append(value.toJava(indent, tracer)).append(":").append(new_line_separator);
buf.appendIndent(indent).append("case ").append(value.toJava(indent, tracer)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
}
@ -151,7 +145,7 @@ public class SwitchStatement extends Statement {
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer));
}
buf.append(indstr).append("}").append(new_line_separator);
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
return buf;

Loading…
Cancel
Save