|
|
|
@ -302,55 +302,65 @@ public class ClassesProcessor implements CodeConstants { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean packageInfo = cl.isSynthetic() && "package-info".equals(root.simpleName); |
|
|
|
|
boolean moduleInfo = cl.hasModifier(CodeConstants.ACC_MODULE) && cl.hasAttribute(StructGeneralAttribute.ATTRIBUTE_MODULE); |
|
|
|
|
|
|
|
|
|
DecompilerContext.getLogger().startReadingClass(cl.qualifiedName); |
|
|
|
|
try { |
|
|
|
|
ImportCollector importCollector = new ImportCollector(root); |
|
|
|
|
DecompilerContext.startClass(importCollector); |
|
|
|
|
|
|
|
|
|
new LambdaProcessor().processClass(root); |
|
|
|
|
if (packageInfo) { |
|
|
|
|
ClassWriter.packageInfoToJava(cl, buffer); |
|
|
|
|
|
|
|
|
|
// add simple class names to implicit import
|
|
|
|
|
addClassnameToImport(root, importCollector); |
|
|
|
|
importCollector.writeImports(buffer, false); |
|
|
|
|
} |
|
|
|
|
else if (moduleInfo) { |
|
|
|
|
TextBuffer moduleBuffer = new TextBuffer(AVERAGE_CLASS_SIZE); |
|
|
|
|
ClassWriter.moduleInfoToJava(cl, moduleBuffer); |
|
|
|
|
|
|
|
|
|
// build wrappers for all nested classes (that's where actual processing takes place)
|
|
|
|
|
initWrappers(root); |
|
|
|
|
importCollector.writeImports(buffer, true); |
|
|
|
|
|
|
|
|
|
new NestedClassProcessor().processClass(root, root); |
|
|
|
|
buffer.append(moduleBuffer); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
new LambdaProcessor().processClass(root); |
|
|
|
|
|
|
|
|
|
new NestedMemberAccess().propagateMemberAccess(root); |
|
|
|
|
// add simple class names to implicit import
|
|
|
|
|
addClassNameToImport(root, importCollector); |
|
|
|
|
|
|
|
|
|
TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE); |
|
|
|
|
new ClassWriter().classToJava(root, classBuffer, 0, null); |
|
|
|
|
// build wrappers for all nested classes (that's where actual processing takes place)
|
|
|
|
|
initWrappers(root); |
|
|
|
|
|
|
|
|
|
int index = cl.qualifiedName.lastIndexOf("/"); |
|
|
|
|
if (index >= 0) { |
|
|
|
|
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.'); |
|
|
|
|
new NestedClassProcessor().processClass(root, root); |
|
|
|
|
|
|
|
|
|
buffer.append("package "); |
|
|
|
|
buffer.append(packageName); |
|
|
|
|
buffer.append(";"); |
|
|
|
|
buffer.appendLineSeparator(); |
|
|
|
|
buffer.appendLineSeparator(); |
|
|
|
|
} |
|
|
|
|
new NestedMemberAccess().propagateMemberAccess(root); |
|
|
|
|
|
|
|
|
|
int import_lines_written = importCollector.writeImports(buffer); |
|
|
|
|
if (import_lines_written > 0) { |
|
|
|
|
buffer.appendLineSeparator(); |
|
|
|
|
} |
|
|
|
|
TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE); |
|
|
|
|
new ClassWriter().classToJava(root, classBuffer, 0, null); |
|
|
|
|
|
|
|
|
|
int offsetLines = buffer.countLines(); |
|
|
|
|
int index = cl.qualifiedName.lastIndexOf('/'); |
|
|
|
|
if (index >= 0) { |
|
|
|
|
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.'); |
|
|
|
|
buffer.append("package ").append(packageName).append(';').appendLineSeparator().appendLineSeparator(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buffer.append(classBuffer); |
|
|
|
|
importCollector.writeImports(buffer, true); |
|
|
|
|
|
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) { |
|
|
|
|
BytecodeSourceMapper mapper = DecompilerContext.getBytecodeSourceMapper(); |
|
|
|
|
mapper.addTotalOffset(offsetLines); |
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_ORIGINAL_LINES)) { |
|
|
|
|
buffer.dumpOriginalLineNumbers(mapper.getOriginalLinesMapping()); |
|
|
|
|
} |
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.UNIT_TEST_MODE)) { |
|
|
|
|
buffer.appendLineSeparator(); |
|
|
|
|
mapper.dumpMapping(buffer, true); |
|
|
|
|
int offsetLines = buffer.countLines(); |
|
|
|
|
|
|
|
|
|
buffer.append(classBuffer); |
|
|
|
|
|
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) { |
|
|
|
|
BytecodeSourceMapper mapper = DecompilerContext.getBytecodeSourceMapper(); |
|
|
|
|
mapper.addTotalOffset(offsetLines); |
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_ORIGINAL_LINES)) { |
|
|
|
|
buffer.dumpOriginalLineNumbers(mapper.getOriginalLinesMapping()); |
|
|
|
|
} |
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.UNIT_TEST_MODE)) { |
|
|
|
|
buffer.appendLineSeparator(); |
|
|
|
|
mapper.dumpMapping(buffer, true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -375,13 +385,13 @@ public class ClassesProcessor implements CodeConstants { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void addClassnameToImport(ClassNode node, ImportCollector imp) { |
|
|
|
|
private static void addClassNameToImport(ClassNode node, ImportCollector imp) { |
|
|
|
|
if (node.simpleName != null && node.simpleName.length() > 0) { |
|
|
|
|
imp.getShortName(node.type == ClassNode.CLASS_ROOT ? node.classStruct.qualifiedName : node.simpleName, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (ClassNode nd : node.nested) { |
|
|
|
|
addClassnameToImport(nd, imp); |
|
|
|
|
addClassNameToImport(nd, imp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|