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.FileTypeConsumer
|
||||||
import com.intellij.openapi.fileTypes.FileTypeFactory
|
import com.intellij.openapi.fileTypes.FileTypeFactory
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
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.KLIB_METADATA_FILE_EXTENSION
|
||||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
|
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
|
||||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
|
||||||
import org.jetbrains.kotlin.serialization.konan.NullFlexibleTypeDeserializer
|
import org.jetbrains.kotlin.serialization.konan.NullFlexibleTypeDeserializer
|
||||||
|
|
||||||
class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<KotlinNativeMetadataVersion>(
|
class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<KlibMetadataVersion>(
|
||||||
KotlinNativeMetaFileType, { KlibMetadataSerializerProtocol }, NullFlexibleTypeDeserializer,
|
KotlinNativeMetaFileType,
|
||||||
{ KotlinNativeMetadataVersion.DEFAULT_INSTANCE },
|
{ KlibMetadataSerializerProtocol },
|
||||||
{ KotlinNativeMetadataVersion.INVALID_VERSION },
|
NullFlexibleTypeDeserializer,
|
||||||
|
{ KlibMetadataVersion.INSTANCE },
|
||||||
|
{ KlibMetadataVersion.INVALID_VERSION },
|
||||||
KotlinNativeMetaFileType.STUB_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 {
|
object KotlinNativeMetaFileType : FileType {
|
||||||
override fun getName() = "KNM"
|
override fun getName() = "KNM"
|
||||||
override fun getDescription() = "Kotlin/Native Metadata"
|
override fun getDescription() = "Kotlin/Native Metadata"
|
||||||
|
|||||||
+4
-2
@@ -7,6 +7,7 @@
|
|||||||
package org.jetbrains.kotlin.ide.konan.decompiler
|
package org.jetbrains.kotlin.ide.konan.decompiler
|
||||||
|
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
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.DefaultBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
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.DeserializerForDecompilerBase
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolveEverythingToKotlinAnyLocalClassifierResolver
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolveEverythingToKotlinAnyLocalClassifierResolver
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
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.ProtoBuf
|
||||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -38,7 +40,7 @@ class KotlinNativeMetadataDeserializerForDecompiler(
|
|||||||
|
|
||||||
deserializationComponents = DeserializationComponents(
|
deserializationComponents = DeserializationComponents(
|
||||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default,
|
storageManager, moduleDescriptor, DeserializationConfiguration.Default,
|
||||||
KotlinNativeProtoBasedClassDataFinder(proto, nameResolver),
|
KlibMetadataClassDataFinder(proto, nameResolver),
|
||||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, serializerProtocol), packageFragmentProvider,
|
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, serializerProtocol), packageFragmentProvider,
|
||||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), createLoggingErrorReporter(LOG),
|
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), createLoggingErrorReporter(LOG),
|
||||||
LookupTracker.DO_NOTHING, flexibleTypeDeserializer, emptyList(), notFoundClasses, ContractDeserializer.DEFAULT,
|
LookupTracker.DO_NOTHING, flexibleTypeDeserializer, emptyList(), notFoundClasses, ContractDeserializer.DEFAULT,
|
||||||
@@ -55,7 +57,7 @@ class KotlinNativeMetadataDeserializerForDecompiler(
|
|||||||
createDummyPackageFragment(facadeFqName),
|
createDummyPackageFragment(facadeFqName),
|
||||||
proto.`package`,
|
proto.`package`,
|
||||||
nameResolver,
|
nameResolver,
|
||||||
KotlinNativeMetadataVersion.DEFAULT_INSTANCE,
|
KlibMetadataVersion.INSTANCE,
|
||||||
containerSource = null,
|
containerSource = null,
|
||||||
components = deserializationComponents
|
components = deserializationComponents
|
||||||
) { emptyList() }
|
) { 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