[java-decompiler] cleanup (arrays to data classes; formatting; typos; dead code)

This commit is contained in:
Roman Shevchenko
2015-11-10 19:48:44 +01:00
parent 26ab681d56
commit 45a41684e6
7 changed files with 500 additions and 649 deletions

View File

@@ -46,7 +46,6 @@ import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.*;
public class ClassWriter {
private final ClassReference14Processor ref14processor;
private final PoolInterceptor interceptor;
@@ -154,15 +153,6 @@ public class ClassWriter {
DecompilerContext.getLogger().endWriteClass();
}
private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) {
StructLineNumberTableAttribute lineNumberTable =
(StructLineNumberTableAttribute)method.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(lineNumberTable);
DecompilerContext.getBytecodeSourceMapper().addTracer(cls.qualifiedName,
InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor()),
tracer);
}
public void classToJava(ClassNode node, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) {
ClassNode outerNode = (ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE);
DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS_NODE, node);
@@ -183,12 +173,7 @@ public class ClassWriter {
int start_class_def = buffer.length();
writeClassDefinition(node, buffer, indent);
// // count lines in class definition the easiest way
// startLine = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
boolean hasContent = false;
// fields
boolean enumFields = false;
dummy_tracer.incrementCurrentSourceLine(buffer.countLines(start_class_def));
@@ -287,6 +272,13 @@ public class ClassWriter {
DecompilerContext.getLogger().endWriteClass();
}
private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) {
StructLineNumberTableAttribute table = (StructLineNumberTableAttribute)method.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(table);
String key = InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor());
DecompilerContext.getBytecodeSourceMapper().addTracer(cls.qualifiedName, key, tracer);
}
private void writeClassDefinition(ClassNode node, TextBuffer buffer, int indent) {
if (node.type == ClassNode.CLASS_ANONYMOUS) {
buffer.append(" {").appendLineSeparator();
@@ -567,7 +559,7 @@ public class ClassWriter {
}
}
public static String toValidJavaIdentifier(String name) {
private static String toValidJavaIdentifier(String name) {
if (name == null || name.isEmpty()) return name;
boolean changed = false;
@@ -833,8 +825,6 @@ public class ClassWriter {
}
// We do not have line information for method start, lets have it here for now
StructLineNumberTableAttribute lineNumberTable =
(StructLineNumberTableAttribute)mt.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
buffer.append('{').appendLineSeparator();
tracer.incrementCurrentSourceLine();
@@ -842,8 +832,6 @@ public class ClassWriter {
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
try {
int startLine = tracer.getCurrentSourceLine();
TextBuffer code = root.toJava(indent + 1, tracer);
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;
@@ -960,7 +948,6 @@ public class ClassWriter {
StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS, StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS};
private static void appendAnnotations(TextBuffer buffer, StructMember mb, int indent) {
BytecodeMappingTracer tracer_dummy = new BytecodeMappingTracer(); // FIXME: replace with a real one
for (String name : ANNOTATION_ATTRIBUTES) {