Kotlin/Native IDE plugin clean-up
- Drop KotlinNativeMetadataVersion in favor of KlibMetadataVersion - Drop KotlinNativeProtoBasedClassDataFinder in favor of KlibMetadataClassDataFinder
This commit is contained in:
+7
-17
@@ -9,15 +9,17 @@ import com.intellij.openapi.fileTypes.FileType
|
||||
import com.intellij.openapi.fileTypes.FileTypeConsumer
|
||||
import com.intellij.openapi.fileTypes.FileTypeFactory
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
|
||||
import org.jetbrains.kotlin.library.KLIB_METADATA_FILE_EXTENSION
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.serialization.konan.NullFlexibleTypeDeserializer
|
||||
|
||||
class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<KotlinNativeMetadataVersion>(
|
||||
KotlinNativeMetaFileType, { KlibMetadataSerializerProtocol }, NullFlexibleTypeDeserializer,
|
||||
{ KotlinNativeMetadataVersion.DEFAULT_INSTANCE },
|
||||
{ KotlinNativeMetadataVersion.INVALID_VERSION },
|
||||
class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<KlibMetadataVersion>(
|
||||
KotlinNativeMetaFileType,
|
||||
{ KlibMetadataSerializerProtocol },
|
||||
NullFlexibleTypeDeserializer,
|
||||
{ KlibMetadataVersion.INSTANCE },
|
||||
{ KlibMetadataVersion.INVALID_VERSION },
|
||||
KotlinNativeMetaFileType.STUB_VERSION
|
||||
) {
|
||||
|
||||
@@ -27,18 +29,6 @@ class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<Kotlin
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinNativeMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
override fun isCompatible(): Boolean = true //todo: ?
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val DEFAULT_INSTANCE = KotlinNativeMetadataVersion(1, 1, 0)
|
||||
|
||||
@JvmField
|
||||
val INVALID_VERSION = KotlinNativeMetadataVersion()
|
||||
}
|
||||
}
|
||||
|
||||
object KotlinNativeMetaFileType : FileType {
|
||||
override fun getName() = "KNM"
|
||||
override fun getDescription() = "Kotlin/Native Metadata"
|
||||
|
||||
+4
-2
@@ -7,6 +7,7 @@
|
||||
package org.jetbrains.kotlin.ide.konan.decompiler
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -15,6 +16,7 @@ import org.jetbrains.kotlin.ide.konan.createLoggingErrorReporter
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DeserializerForDecompilerBase
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolveEverythingToKotlinAnyLocalClassifierResolver
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataClassDataFinder
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -38,7 +40,7 @@ class KotlinNativeMetadataDeserializerForDecompiler(
|
||||
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default,
|
||||
KotlinNativeProtoBasedClassDataFinder(proto, nameResolver),
|
||||
KlibMetadataClassDataFinder(proto, nameResolver),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, serializerProtocol), packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), createLoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, flexibleTypeDeserializer, emptyList(), notFoundClasses, ContractDeserializer.DEFAULT,
|
||||
@@ -55,7 +57,7 @@ class KotlinNativeMetadataDeserializerForDecompiler(
|
||||
createDummyPackageFragment(facadeFqName),
|
||||
proto.`package`,
|
||||
nameResolver,
|
||||
KotlinNativeMetadataVersion.DEFAULT_INSTANCE,
|
||||
KlibMetadataVersion.INSTANCE,
|
||||
containerSource = null,
|
||||
components = deserializationComponents
|
||||
) { emptyList() }
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ide.konan.decompiler
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassData
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
|
||||
class KotlinNativeProtoBasedClassDataFinder(
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
private val nameResolver: NameResolver,
|
||||
private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE }
|
||||
) : ClassDataFinder {
|
||||
private val classIdToProto =
|
||||
proto.class_List.associateBy { klass ->
|
||||
nameResolver.getClassId(klass.fqName)
|
||||
}
|
||||
|
||||
internal val allClassIds: Collection<ClassId> get() = classIdToProto.keys
|
||||
|
||||
override fun findClassData(classId: ClassId): ClassData? {
|
||||
val classProto = classIdToProto[classId] ?: return null
|
||||
return ClassData(nameResolver, classProto, KotlinNativeMetadataVersion.DEFAULT_INSTANCE, classSource(classId))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user