Decompiler, minor: fix some strange code
This commit is contained in:
@@ -31,7 +31,11 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
|
||||
public abstract class KtDecompiledFileBase(val provider: KotlinDecompiledFileViewProviderBase) : KtFile(provider, true) {
|
||||
protected abstract val decompiledText: LockedClearableLazyValue<DecompiledText>
|
||||
abstract fun buildDecompiledText(): DecompiledText
|
||||
|
||||
private val decompiledText = LockedClearableLazyValue(Any()) {
|
||||
buildDecompiledText()
|
||||
}
|
||||
|
||||
public fun getDeclarationForDescriptor(descriptor: DeclarationDescriptor): KtDeclaration? {
|
||||
val original = descriptor.getOriginal()
|
||||
|
||||
+2
-2
@@ -51,11 +51,11 @@ public class DeserializerForClassfileDecompiler(
|
||||
|
||||
private val classFinder = DirectoryBasedClassFinder(packageDirectory, directoryPackageFqName)
|
||||
|
||||
override val classDataFinder = DirectoryBasedDataFinder(classFinder, LOG)
|
||||
private val classDataFinder = DirectoryBasedDataFinder(classFinder, LOG)
|
||||
|
||||
private val errorReporter = LoggingErrorReporter(LOG)
|
||||
|
||||
override val annotationAndConstantLoader =
|
||||
private val annotationAndConstantLoader =
|
||||
BinaryClassAnnotationAndConstantLoaderImpl(moduleDescriptor, storageManager, classFinder, errorReporter)
|
||||
|
||||
override val deserializationComponents: DeserializationComponents = DeserializationComponents(
|
||||
|
||||
@@ -36,9 +36,7 @@ import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
import java.util.*
|
||||
|
||||
public class KtClsFile(provider: KotlinDecompiledFileViewProviderBase) : KtDecompiledFileBase(provider) {
|
||||
protected override val decompiledText: LockedClearableLazyValue<DecompiledText> = LockedClearableLazyValue(Any()) {
|
||||
buildDecompiledTextForClassFile(virtualFile)
|
||||
}
|
||||
override fun buildDecompiledText() = buildDecompiledTextForClassFile(virtualFile)
|
||||
}
|
||||
|
||||
private val descriptorRendererForClassFileDecompiler = DescriptorRenderer.withOptions {
|
||||
|
||||
+8
-9
@@ -20,12 +20,14 @@ import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DeserializerForDecompilerBase
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.LoggingErrorReporter
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolveEverythingToKotlinAnyLocalClassResolver
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.serialization.ClassData
|
||||
import org.jetbrains.kotlin.serialization.ClassDataWithSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
@@ -48,13 +50,13 @@ public class KotlinJavaScriptDeserializerForDecompiler(
|
||||
|
||||
private val metaFileFinder = DirectoryBasedKotlinJavaScriptMetaFileFinder(packageDirectory, directoryPackageFqName, nameResolver)
|
||||
|
||||
override val classDataFinder = DirectoryBasedKotlinJavaScriptDataFinder(metaFileFinder, LOG)
|
||||
private val classDataFinder = DirectoryBasedKotlinJavaScriptDataFinder(metaFileFinder, LOG)
|
||||
|
||||
override val annotationAndConstantLoader = KotlinJavascriptAnnotationAndConstantLoader(moduleDescriptor)
|
||||
private val annotationAndConstantLoader = KotlinJavascriptAnnotationAndConstantLoader(moduleDescriptor)
|
||||
|
||||
override val deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassResolver(targetPlatform.builtIns), ErrorReporter.DO_NOTHING,
|
||||
ResolveEverythingToKotlinAnyLocalClassResolver(targetPlatform.builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeCapabilitiesDeserializer.Dynamic, ClassDescriptorFactory.EMPTY
|
||||
)
|
||||
|
||||
@@ -70,10 +72,8 @@ public class KotlinJavaScriptDeserializerForDecompiler(
|
||||
}
|
||||
|
||||
val content = file.contentsToByteArray(false)
|
||||
val (nameResolver, packageProto) = content.toPackageData(nameResolver)
|
||||
|
||||
val membersScope = DeserializedPackageMemberScope(
|
||||
createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents
|
||||
createDummyPackageFragment(packageFqName), content.toPackageProto(), nameResolver, deserializationComponents
|
||||
) { emptyList() }
|
||||
return membersScope.getContributedDescriptors()
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class DirectoryBasedKotlinJavaScriptMetaFileFinder(
|
||||
val packageDirectory: VirtualFile,
|
||||
val directoryPackageFqName: FqName,
|
||||
val nameResolver: NameResolver
|
||||
) {
|
||||
) {
|
||||
fun findKotlinJavascriptMetaFile(classId: ClassId): VirtualFile? {
|
||||
if (classId.getPackageFqName() != directoryPackageFqName) return null
|
||||
|
||||
@@ -104,7 +104,6 @@ class DirectoryBasedKotlinJavaScriptDataFinder(
|
||||
val file = classFinder.findKotlinJavascriptMetaFile(classId) ?: return null
|
||||
|
||||
val content = file.contentsToByteArray(false)
|
||||
val classData = content.toClassData(classFinder.nameResolver)
|
||||
return ClassDataWithSource(classData)
|
||||
return ClassDataWithSource(ClassData(classFinder.nameResolver, content.toClassProto()))
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -31,8 +31,8 @@ import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializedResourcePaths
|
||||
import org.jetbrains.kotlin.serialization.js.toClassData
|
||||
import org.jetbrains.kotlin.serialization.js.toPackageData
|
||||
import org.jetbrains.kotlin.serialization.js.toClassProto
|
||||
import org.jetbrains.kotlin.serialization.js.toPackageProto
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
public class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
|
||||
@@ -61,17 +61,17 @@ public class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
|
||||
val components = createStubBuilderComponents(file, packageFqName, nameResolver)
|
||||
|
||||
if (isPackageHeader) {
|
||||
val packageData = content.toPackageData(nameResolver)
|
||||
val packageProto = content.toPackageProto()
|
||||
val context = components.createContext(
|
||||
packageData.nameResolver, packageFqName, TypeTable(packageData.packageProto.typeTable)
|
||||
nameResolver, packageFqName, TypeTable(packageProto.typeTable)
|
||||
)
|
||||
return createPackageFacadeStub(packageData.packageProto, packageFqName, context)
|
||||
return createPackageFacadeStub(packageProto, packageFqName, context)
|
||||
}
|
||||
else {
|
||||
val classData = content.toClassData(nameResolver)
|
||||
val context = components.createContext(classData.nameResolver, packageFqName, TypeTable(classData.classProto.typeTable))
|
||||
val classProto = content.toClassProto()
|
||||
val context = components.createContext(nameResolver, packageFqName, TypeTable(classProto.typeTable))
|
||||
val classId = JsMetaFileUtils.getClassId(file)
|
||||
return createTopLevelClassStub(classId, classData.classProto, context)
|
||||
return createTopLevelClassStub(classId, classProto, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -30,9 +30,7 @@ import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
import java.util.*
|
||||
|
||||
public class KotlinJavascriptMetaFile(provider: KotlinJavascriptMetaFileViewProvider) : KtDecompiledFileBase(provider) {
|
||||
protected override val decompiledText: LockedClearableLazyValue<DecompiledText> = LockedClearableLazyValue(Any()) {
|
||||
buildDecompiledTextFromJsMetadata(getVirtualFile())
|
||||
}
|
||||
override fun buildDecompiledText() = buildDecompiledTextFromJsMetadata(virtualFile)
|
||||
}
|
||||
|
||||
private val descriptorRendererForKotlinJavascriptDecompiler = DescriptorRenderer.withOptions {
|
||||
|
||||
-4
@@ -46,10 +46,6 @@ public abstract class DeserializerForDecompilerBase(
|
||||
|
||||
protected abstract val targetPlatform: TargetPlatform
|
||||
|
||||
protected abstract val classDataFinder: ClassDataFinder
|
||||
|
||||
protected abstract val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget>
|
||||
|
||||
protected val storageManager: StorageManager = LockBasedStorageManager.NO_LOCKS
|
||||
|
||||
protected val moduleDescriptor: ModuleDescriptorImpl = createDummyModule("module for building decompiled sources")
|
||||
|
||||
@@ -16,21 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.serialization.ClassData
|
||||
import org.jetbrains.kotlin.serialization.PackageData
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
public fun ByteArray.toPackageData(nameResolver: NameResolver): PackageData {
|
||||
public fun ByteArray.toPackageProto(): ProtoBuf.Package {
|
||||
val registry = KotlinJavascriptSerializedResourcePaths.extensionRegistry
|
||||
val packageProto = ProtoBuf.Package.parseFrom(ByteArrayInputStream(this), registry)
|
||||
return PackageData(nameResolver, packageProto)
|
||||
return ProtoBuf.Package.parseFrom(ByteArrayInputStream(this), registry)!!
|
||||
}
|
||||
|
||||
public fun ByteArray.toClassData(nameResolver: NameResolver): ClassData {
|
||||
public fun ByteArray.toClassProto(): ProtoBuf.Class {
|
||||
val registry = KotlinJavascriptSerializedResourcePaths.extensionRegistry
|
||||
val classProto = ProtoBuf.Class.parseFrom(ByteArrayInputStream(this), registry)
|
||||
return ClassData(nameResolver, classProto)
|
||||
return ProtoBuf.Class.parseFrom(ByteArrayInputStream(this), registry)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user