Cleanup (formatting; typos)

master
Roman Shevchenko 9 years ago
parent debe6cc338
commit aa480480e9
  1. 84
      src/org/jetbrains/java/decompiler/main/ClassesProcessor.java

@ -47,10 +47,10 @@ public class ClassesProcessor {
public ClassesProcessor(StructContext context) { public ClassesProcessor(StructContext context) {
HashMap<String, Object[]> mapInnerClasses = new HashMap<String, Object[]>(); Map<String, Object[]> mapInnerClasses = new HashMap<String, Object[]>();
HashMap<String, HashSet<String>> mapNestedClassReferences = new HashMap<String, HashSet<String>>(); Map<String, Set<String>> mapNestedClassReferences = new HashMap<String, Set<String>>();
HashMap<String, HashSet<String>> mapEnclosingClassReferences = new HashMap<String, HashSet<String>>(); Map<String, Set<String>> mapEnclosingClassReferences = new HashMap<String, Set<String>>();
HashMap<String, String> mapNewSimpleNames = new HashMap<String, String>(); Map<String, String> mapNewSimpleNames = new HashMap<String, String>();
boolean bDecompileInner = DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_INNER); boolean bDecompileInner = DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_INNER);
@ -65,18 +65,16 @@ public class ClassesProcessor {
for (int i = 0; i < inner.getClassEntries().size(); i++) { for (int i = 0; i < inner.getClassEntries().size(); i++) {
int[] entry = inner.getClassEntries().get(i); int[] entry = inner.getClassEntries().get(i);
String[] strentry = inner.getStringEntries().get(i); String[] strEntry = inner.getStringEntries().get(i);
Object[] arr = new Object[4]; // arr[0] not used Object[] arr = new Object[4]; // arr[0] not used
String innerName = strEntry[0];
String innername = strentry[0];
// nested class type // nested class type
arr[2] = entry[1] == 0 ? (entry[2] == 0 ? ClassNode.CLASS_ANONYMOUS : ClassNode.CLASS_LOCAL) : ClassNode.CLASS_MEMBER; arr[2] = entry[1] == 0 ? (entry[2] == 0 ? ClassNode.CLASS_ANONYMOUS : ClassNode.CLASS_LOCAL) : ClassNode.CLASS_MEMBER;
// original simple name // original simple name
String simpleName = strentry[2]; String simpleName = strEntry[2];
String savedName = mapNewSimpleNames.get(innername); String savedName = mapNewSimpleNames.get(innerName);
if (savedName != null) { if (savedName != null) {
simpleName = savedName; simpleName = savedName;
@ -84,8 +82,8 @@ public class ClassesProcessor {
else if (simpleName != null && DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) { else if (simpleName != null && DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) {
IIdentifierRenamer renamer = DecompilerContext.getPoolInterceptor().getHelper(); IIdentifierRenamer renamer = DecompilerContext.getPoolInterceptor().getHelper();
if (renamer.toBeRenamed(IIdentifierRenamer.Type.ELEMENT_CLASS, simpleName, null, null)) { if (renamer.toBeRenamed(IIdentifierRenamer.Type.ELEMENT_CLASS, simpleName, null, null)) {
simpleName = renamer.getNextClassName(innername, simpleName); simpleName = renamer.getNextClassName(innerName, simpleName);
mapNewSimpleNames.put(innername, simpleName); mapNewSimpleNames.put(innerName, simpleName);
} }
} }
@ -97,36 +95,36 @@ public class ClassesProcessor {
// enclosing class // enclosing class
String enclClassName; String enclClassName;
if (entry[1] != 0) { if (entry[1] != 0) {
enclClassName = strentry[1]; enclClassName = strEntry[1];
} }
else { else {
enclClassName = cl.qualifiedName; enclClassName = cl.qualifiedName;
} }
if (!innername.equals(enclClassName)) { // self reference if (!innerName.equals(enclClassName)) { // self reference
StructClass enclosing_class = context.getClasses().get(enclClassName); StructClass enclosing_class = context.getClasses().get(enclClassName);
if (enclosing_class != null && enclosing_class.isOwn()) { // own classes only if (enclosing_class != null && enclosing_class.isOwn()) { // own classes only
Object[] arrold = mapInnerClasses.get(innername); Object[] arrOld = mapInnerClasses.get(innerName);
if (arrold == null) { if (arrOld == null) {
mapInnerClasses.put(innername, arr); mapInnerClasses.put(innerName, arr);
} }
else if (!InterpreterUtil.equalObjectArrays(arrold, arr)) { else if (!InterpreterUtil.equalObjectArrays(arrOld, arr)) {
String message = "Inconsistent inner class entries for " + innername + "!"; String message = "Inconsistent inner class entries for " + innerName + "!";
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
} }
// reference to the nested class // reference to the nested class
HashSet<String> set = mapNestedClassReferences.get(enclClassName); Set<String> set = mapNestedClassReferences.get(enclClassName);
if (set == null) { if (set == null) {
mapNestedClassReferences.put(enclClassName, set = new HashSet<String>()); mapNestedClassReferences.put(enclClassName, set = new HashSet<String>());
} }
set.add(innername); set.add(innerName);
// reference to the enclosing class // reference to the enclosing class
set = mapEnclosingClassReferences.get(innername); set = mapEnclosingClassReferences.get(innerName);
if (set == null) { if (set == null) {
mapEnclosingClassReferences.put(innername, set = new HashSet<String>()); mapEnclosingClassReferences.put(innerName, set = new HashSet<String>());
} }
set.add(enclClassName); set.add(enclClassName);
} }
@ -174,8 +172,8 @@ public class ClassesProcessor {
continue; continue;
} }
ClassNode nestednode = mapRootClasses.get(nestedClass); ClassNode nestedNode = mapRootClasses.get(nestedClass);
if (nestednode == null) { if (nestedNode == null) {
DecompilerContext.getLogger().writeMessage("Nested class " + nestedClass + " missing!", IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage("Nested class " + nestedClass + " missing!", IFernflowerLogger.Severity.WARN);
continue; continue;
} }
@ -186,16 +184,16 @@ public class ClassesProcessor {
// FIXME: check for consistent naming // FIXME: check for consistent naming
//} //}
nestednode.type = (Integer)arr[2]; nestedNode.type = (Integer)arr[2];
nestednode.simpleName = (String)arr[1]; nestedNode.simpleName = (String)arr[1];
nestednode.access = (Integer)arr[3]; nestedNode.access = (Integer)arr[3];
if (nestednode.type == ClassNode.CLASS_ANONYMOUS) { if (nestedNode.type == ClassNode.CLASS_ANONYMOUS) {
StructClass cl = nestednode.classStruct; StructClass cl = nestedNode.classStruct;
// remove static if anonymous class // remove static if anonymous class
// a common compiler bug // a common compiler bug
nestednode.access &= ~CodeConstants.ACC_STATIC; nestedNode.access &= ~CodeConstants.ACC_STATIC;
int[] interfaces = cl.getInterfaces(); int[] interfaces = cl.getInterfaces();
@ -204,22 +202,22 @@ public class ClassesProcessor {
String message = "Inconsistent anonymous class definition: " + cl.qualifiedName; String message = "Inconsistent anonymous class definition: " + cl.qualifiedName;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
} }
nestednode.anonymousClassType = new VarType(cl.getInterface(0), true); nestedNode.anonymousClassType = new VarType(cl.getInterface(0), true);
} }
else { else {
nestednode.anonymousClassType = new VarType(cl.superClass.getString(), true); nestedNode.anonymousClassType = new VarType(cl.superClass.getString(), true);
} }
} }
else if (nestednode.type == ClassNode.CLASS_LOCAL) { else if (nestedNode.type == ClassNode.CLASS_LOCAL) {
// only abstract and final are permitted // only abstract and final are permitted
// a common compiler bug // a common compiler bug
nestednode.access &= (CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_FINAL); nestedNode.access &= (CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_FINAL);
} }
superNode.nested.add(nestednode); superNode.nested.add(nestedNode);
nestednode.parent = superNode; nestedNode.parent = superNode;
nestednode.enclosingClasses.addAll(mapEnclosingClassReferences.get(nestedClass)); nestedNode.enclosingClasses.addAll(mapEnclosingClassReferences.get(nestedClass));
stack.add(nestedClass); stack.add(nestedClass);
} }
@ -258,11 +256,8 @@ public class ClassesProcessor {
TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE); TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE);
new ClassWriter().classToJava(root, classBuffer, 0, null); new ClassWriter().classToJava(root, classBuffer, 0, null);
int total_offset_lines = 0;
int index = cl.qualifiedName.lastIndexOf("/"); int index = cl.qualifiedName.lastIndexOf("/");
if (index >= 0) { if (index >= 0) {
total_offset_lines+=2;
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.'); String packageName = cl.qualifiedName.substring(0, index).replace('/', '.');
buffer.append("package "); buffer.append("package ");
@ -275,16 +270,15 @@ public class ClassesProcessor {
int import_lines_written = importCollector.writeImports(buffer); int import_lines_written = importCollector.writeImports(buffer);
if (import_lines_written > 0) { if (import_lines_written > 0) {
buffer.appendLineSeparator(); buffer.appendLineSeparator();
total_offset_lines += import_lines_written + 1;
} }
//buffer.append(lineSeparator);
total_offset_lines = buffer.countLines(); int offsetLines = buffer.countLines();
buffer.append(classBuffer); buffer.append(classBuffer);
if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) { if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) {
BytecodeSourceMapper mapper = DecompilerContext.getBytecodeSourceMapper(); BytecodeSourceMapper mapper = DecompilerContext.getBytecodeSourceMapper();
mapper.addTotalOffset(total_offset_lines); mapper.addTotalOffset(offsetLines);
if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_ORIGINAL_LINES)) { if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_ORIGINAL_LINES)) {
buffer.dumpOriginalLineNumbers(mapper.getOriginalLinesMapping()); buffer.dumpOriginalLineNumbers(mapper.getOriginalLinesMapping());
} }

Loading…
Cancel
Save