Fix compilation of KotlinBytecodeToolWindow
This commit is contained in:
+24
-19
@@ -36,28 +36,33 @@ import java.util.jar.Manifest
|
||||
class KotlinDecompilerServiceImpl : KotlinDecompilerService {
|
||||
override fun decompile(file: KtFile): String? {
|
||||
|
||||
val bytecodeMap = when {
|
||||
file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile)
|
||||
!file.isCompiled -> bytecodeMapForSourceFile(file)
|
||||
else -> return null
|
||||
}
|
||||
val resultSaver = KotlinResultSaver()
|
||||
val options = hashMapOf<String, Any>(
|
||||
IFernflowerPreferences.REMOVE_BRIDGE to "0"
|
||||
)
|
||||
try {
|
||||
val bytecodeMap = when {
|
||||
file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile)
|
||||
!file.isCompiled -> bytecodeMapForSourceFile(file)
|
||||
else -> return null
|
||||
}
|
||||
val resultSaver = KotlinResultSaver()
|
||||
val options = hashMapOf<String, Any>(
|
||||
IFernflowerPreferences.REMOVE_BRIDGE to "0"
|
||||
)
|
||||
|
||||
val bytecodeProvider = IBytecodeProvider {
|
||||
externalPath, _ ->
|
||||
val path = File(FileUtil.toSystemIndependentName(externalPath))
|
||||
bytecodeMap[path]?.invoke()
|
||||
}
|
||||
val bytecodeProvider = IBytecodeProvider {
|
||||
externalPath, _ ->
|
||||
val path = File(FileUtil.toSystemIndependentName(externalPath))
|
||||
bytecodeMap[path]?.invoke()
|
||||
}
|
||||
|
||||
val decompiler = BaseDecompiler(bytecodeProvider, resultSaver, options, IdeaLogger())
|
||||
for (path in bytecodeMap.keys) {
|
||||
decompiler.addSpace(path, true)
|
||||
val decompiler = BaseDecompiler(bytecodeProvider, resultSaver, options, IdeaLogger())
|
||||
for (path in bytecodeMap.keys) {
|
||||
decompiler.addSpace(path, true)
|
||||
}
|
||||
decompiler.decompileContext()
|
||||
return resultSaver.resultText
|
||||
}
|
||||
catch (ex: IdeaLogger.InternalException) {
|
||||
throw DecompileFailedException(ex.message ?: "Unknown error", ex)
|
||||
}
|
||||
decompiler.decompileContext()
|
||||
return resultSaver.resultText
|
||||
}
|
||||
|
||||
private fun bytecodeMapForExistingClassfile(file: VirtualFile): Map<File, () -> ByteArray> {
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.util.Alarm;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.java.decompiler.IdeaLogger;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory;
|
||||
@@ -213,7 +212,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
try {
|
||||
KotlinDecompilerAdapterKt.showDecompiledCode(file);
|
||||
}
|
||||
catch (IdeaLogger.InternalException ex) {
|
||||
catch (DecompileFailedException ex) {
|
||||
LOG.info(ex);
|
||||
Messages.showErrorDialog(myProject, "Failed to decompile " + file.getName() + ": " + ex, "Kotlin Bytecode Decompiler");
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.internal
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
class DecompileFailedException(message: String, cause: Throwable) : RuntimeException(message, cause)
|
||||
|
||||
interface KotlinDecompilerService {
|
||||
fun decompile(file: KtFile): String?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user