From 03606c13aada2884024618ecc8acdb20e9d3978f Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 18 Dec 2015 23:14:53 +0300 Subject: [PATCH] Introduce PackagePartSource to store part class name in deserialized descriptors Not used at the moment, will be in the following commits --- .../IncrementalPackageFragmentProvider.kt | 17 +++++++++----- .../DeserializedDescriptorResolver.java | 4 +++- .../load/kotlin/JvmPackagePartSource.kt | 22 +++++++++++++++++++ .../deserialization/ClassDeserializer.kt | 2 +- .../DeserializedPackageFragment.kt | 3 ++- .../deserialization/MemberDeserializer.kt | 9 ++++---- .../deserialization/ProtoContainer.kt | 4 +++- .../serialization/deserialization/context.kt | 15 ++++++++----- .../DeserializedCallableMemberDescriptor.kt | 22 ++++++++++++++----- .../DeserializedPackageMemberScope.kt | 3 ++- .../src/kotlin/reflect/jvm/reflectLambda.kt | 2 +- .../DeserializerForClassfileDecompiler.kt | 5 ++++- .../decompiler/stubBuilder/clsStubBuilding.kt | 15 ++++++++----- .../DeserializerForDecompilerBase.kt | 3 ++- 14 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmPackagePartSource.kt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt index d7aec4b175f..87e5d4241ea 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl +import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource import org.jetbrains.kotlin.load.kotlin.ModuleMapping import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache @@ -112,7 +113,9 @@ public class IncrementalPackageFragmentProvider( allParts.filterNot { it in obsoletePackageParts } } ?: emptyList() - val scopes = actualPackagePartFiles.mapNotNull { incrementalCache.getPackagePartData(it) }.map { createPackageScope(it) } + val scopes = actualPackagePartFiles.mapNotNull { internalName -> + incrementalCache.getPackagePartData(internalName)?.let { internalName to it } + }.map { createPackageScope(it.first, it.second) } if (scopes.isEmpty()) { MemberScope.Empty @@ -136,13 +139,15 @@ public class IncrementalPackageFragmentProvider( val partsNames: Collection ) : PackageFragmentDescriptorImpl(moduleDescriptor, multifileClassFqName.parent()) { val memberScope = storageManager.createLazyValue { - val partsData = partsNames.mapNotNull { incrementalCache.getPackagePartData(it) } + val partsData = partsNames.mapNotNull { internalName -> + incrementalCache.getPackagePartData(internalName)?.let { internalName to it } + } if (partsData.isEmpty()) MemberScope.Empty else { ChainedMemberScope( "Member scope for incremental compilation: union of multifile class parts data for $multifileClassFqName", - partsData.map { createPackageScope(it) } + partsData.map { createPackageScope(it.first, it.second) } ) } } @@ -150,10 +155,12 @@ public class IncrementalPackageFragmentProvider( override fun getMemberScope(): MemberScope = memberScope() } - fun createPackageScope(part: JvmPackagePartProto): DeserializedPackageMemberScope { + fun createPackageScope(internalName: String, part: JvmPackagePartProto): DeserializedPackageMemberScope { val packageData = JvmProtoBufUtil.readPackageDataFrom(part.data, part.strings) return DeserializedPackageMemberScope( - this, packageData.packageProto, packageData.nameResolver, deserializationComponents, { listOf() } + this, packageData.packageProto, packageData.nameResolver, + JvmPackagePartSource(JvmClassName.byInternalName(internalName)), + deserializationComponents, { listOf() } ) } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.java index c47aa3da316..413424f4fe1 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.java @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader; import org.jetbrains.kotlin.name.Name; +import org.jetbrains.kotlin.resolve.jvm.JvmClassName; import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope; import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.serialization.ClassData; @@ -79,8 +80,9 @@ public final class DeserializedDescriptorResolver { String[] strings = kotlinClass.getClassHeader().getStrings(); assert strings != null : "String table not found in " + kotlinClass; PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data, strings); + JvmPackagePartSource source = new JvmPackagePartSource(JvmClassName.byClassId(kotlinClass.getClassId())); return new DeserializedPackageMemberScope( - descriptor, packageData.getPackageProto(), packageData.getNameResolver(), components, + descriptor, packageData.getPackageProto(), packageData.getNameResolver(), source, components, new Function0>() { @Override public Collection invoke() { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmPackagePartSource.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmPackagePartSource.kt new file mode 100644 index 00000000000..0155fb07883 --- /dev/null +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmPackagePartSource.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.load.kotlin + +import org.jetbrains.kotlin.resolve.jvm.JvmClassName +import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource + +class JvmPackagePartSource(val className: JvmClassName) : PackagePartSource diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt index 6cbb3270a3f..8a2d42051a2 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt @@ -56,7 +56,7 @@ public class ClassDeserializer(private val components: DeserializationComponents if (!fragment.hasTopLevelClass(classId.shortClassName)) return null } - components.createContext(fragment, nameResolver, TypeTable(classProto.typeTable)) + components.createContext(fragment, nameResolver, TypeTable(classProto.typeTable), packagePartSource = null) } return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt index 95c90f28365..4322b188b2a 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt @@ -50,7 +50,8 @@ public abstract class DeserializedPackageFragment( internal val deserializedMemberScope by storageManager.createLazyValue { val packageStream = loadResourceSure(serializedResourcePaths.getPackageFilePath(fqName)) val packageProto = ProtoBuf.Package.parseFrom(packageStream, serializedResourcePaths.extensionRegistry) - DeserializedPackageMemberScope(this, packageProto, nameResolver, components, classNames = { loadClassNames(packageProto) }) + DeserializedPackageMemberScope(this, packageProto, nameResolver, packagePartSource = null, components = components, + classNames = { loadClassNames(packageProto) }) } override fun getMemberScope() = deserializedMemberScope diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index 6f43be3241c..feff5369c51 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -47,7 +47,8 @@ public class MemberDeserializer(private val c: DeserializationContext) { Flags.IS_CONST.get(flags), proto, c.nameResolver, - c.typeTable + c.typeTable, + c.packagePartSource ) val local = c.childContext(property, proto.getTypeParameterList()) @@ -142,7 +143,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { else Annotations.EMPTY val function = DeserializedSimpleFunctionDescriptor( c.containingDeclaration, /* original = */ null, annotations, c.nameResolver.getName(proto.name), - Deserialization.memberKind(Flags.MEMBER_KIND.get(proto.flags)), proto, c.nameResolver, c.typeTable + Deserialization.memberKind(Flags.MEMBER_KIND.get(proto.flags)), proto, c.nameResolver, c.typeTable, c.packagePartSource ) val local = c.childContext(function, proto.typeParameterList) function.initialize( @@ -170,7 +171,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { val classDescriptor = c.containingDeclaration as ClassDescriptor val descriptor = DeserializedConstructorDescriptor( classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION), - isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable + isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable, c.packagePartSource ) val local = c.childContext(descriptor, listOf()) descriptor.initialize( @@ -243,7 +244,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { } private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) { - is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable) + is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.packagePartSource) is DeserializedClassDescriptor -> ProtoContainer.Class( classProto, c.nameResolver, c.typeTable, isCompanionOfClass = DescriptorUtils.isCompanionObject(this) && diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt index 10353e6d29c..1050da9ca79 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.serialization.deserialization import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.serialization.ProtoBuf +import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource sealed class ProtoContainer( val nameResolver: NameResolver, @@ -35,7 +36,8 @@ sealed class ProtoContainer( class Package( val fqName: FqName, nameResolver: NameResolver, - typeTable: TypeTable + typeTable: TypeTable, + val packagePartSource: PackagePartSource? ) : ProtoContainer(nameResolver, typeTable) { override fun debugFqName(): FqName = fqName } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt index 8fafe95f25e..76cec4ba2af 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.serialization.ProtoBuf +import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource import org.jetbrains.kotlin.storage.StorageManager class DeserializationComponents( @@ -46,9 +47,11 @@ class DeserializationComponents( fun createContext( descriptor: PackageFragmentDescriptor, nameResolver: NameResolver, - typeTable: TypeTable + typeTable: TypeTable, + packagePartSource: PackagePartSource? ): DeserializationContext = - DeserializationContext(this, nameResolver, descriptor, typeTable, parentTypeDeserializer = null, typeParameters = listOf()) + DeserializationContext(this, nameResolver, descriptor, typeTable, packagePartSource, + parentTypeDeserializer = null, typeParameters = listOf()) } @@ -57,11 +60,12 @@ class DeserializationContext( val nameResolver: NameResolver, val containingDeclaration: DeclarationDescriptor, val typeTable: TypeTable, + val packagePartSource: PackagePartSource?, parentTypeDeserializer: TypeDeserializer?, typeParameters: List ) { val typeDeserializer = TypeDeserializer(this, parentTypeDeserializer, typeParameters, - "Deserializer for ${containingDeclaration.getName()}") + "Deserializer for ${containingDeclaration.name}") val memberDeserializer = MemberDeserializer(this) @@ -73,8 +77,7 @@ class DeserializationContext( nameResolver: NameResolver = this.nameResolver, typeTable: TypeTable = this.typeTable ) = DeserializationContext( - components, nameResolver, descriptor, typeTable, - parentTypeDeserializer = this.typeDeserializer, - typeParameters = typeParameterProtos + components, nameResolver, descriptor, typeTable, this.packagePartSource, + parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos ) } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedCallableMemberDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedCallableMemberDescriptor.kt index 68db5756473..1de4e9bbae1 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedCallableMemberDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedCallableMemberDescriptor.kt @@ -34,8 +34,14 @@ interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor { val nameResolver: NameResolver val typeTable: TypeTable + + // Information about the origin of this top-level callable or null, if it's not top-level or there's no such information. + // On JVM, this is JvmPackagePartSource which contains the internal name of the package part class + val packagePartSource: PackagePartSource? } +interface PackagePartSource + class DeserializedSimpleFunctionDescriptor( containingDeclaration: DeclarationDescriptor, original: SimpleFunctionDescriptor?, @@ -44,7 +50,8 @@ class DeserializedSimpleFunctionDescriptor( kind: CallableMemberDescriptor.Kind, override val proto: ProtoBuf.Function, override val nameResolver: NameResolver, - override val typeTable: TypeTable + override val typeTable: TypeTable, + override val packagePartSource: PackagePartSource? ) : DeserializedCallableMemberDescriptor, SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) { @@ -56,7 +63,8 @@ class DeserializedSimpleFunctionDescriptor( preserveSource: Boolean ): FunctionDescriptorImpl { return DeserializedSimpleFunctionDescriptor( - newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, proto, nameResolver, typeTable + newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, + proto, nameResolver, typeTable, packagePartSource ) } } @@ -74,7 +82,8 @@ class DeserializedPropertyDescriptor( isConst: Boolean, override val proto: ProtoBuf.Property, override val nameResolver: NameResolver, - override val typeTable: TypeTable + override val typeTable: TypeTable, + override val packagePartSource: PackagePartSource? ) : DeserializedCallableMemberDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) { @@ -88,7 +97,7 @@ class DeserializedPropertyDescriptor( ): PropertyDescriptorImpl { return DeserializedPropertyDescriptor( newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst, - proto, nameResolver, typeTable + proto, nameResolver, typeTable, packagePartSource ) } } @@ -101,7 +110,8 @@ class DeserializedConstructorDescriptor( kind: CallableMemberDescriptor.Kind, override val proto: ProtoBuf.Constructor, override val nameResolver: NameResolver, - override val typeTable: TypeTable + override val typeTable: TypeTable, + override val packagePartSource: PackagePartSource? ) : DeserializedCallableMemberDescriptor, ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) { @@ -114,7 +124,7 @@ class DeserializedConstructorDescriptor( ): DeserializedConstructorDescriptor { return DeserializedConstructorDescriptor( newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, - proto, nameResolver, typeTable + proto, nameResolver, typeTable, packagePartSource ) } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt index c50ac705892..766d3cac7e7 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt @@ -36,10 +36,11 @@ public open class DeserializedPackageMemberScope( packageDescriptor: PackageFragmentDescriptor, proto: ProtoBuf.Package, nameResolver: NameResolver, + packagePartSource: PackagePartSource?, components: DeserializationComponents, classNames: () -> Collection ) : DeserializedMemberScope( - components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable)), + components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), packagePartSource), proto.functionList, proto.propertyList ) { private val packageFqName = packageDescriptor.fqName diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/reflectLambda.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/reflectLambda.kt index 7b61e9de39f..e23c2b93546 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/reflectLambda.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/reflectLambda.kt @@ -46,7 +46,7 @@ public fun Function.reflect(): KFunction? { val moduleData = javaClass.getOrCreateModule() val context = DeserializationContext( moduleData.deserialization, nameResolver, moduleData.module, - typeTable = TypeTable(proto.typeTable), parentTypeDeserializer = null, typeParameters = listOf() + typeTable = TypeTable(proto.typeTable), packagePartSource = null, parentTypeDeserializer = null, typeParameters = listOf() ) val descriptor = MemberDeserializer(context).loadFunction(proto) @Suppress("UNCHECKED_CAST") diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt index 0c07c1b4c6a..c42bceb48ff 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.load.kotlin.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.TargetPlatform +import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.serialization.ClassDataWithSource import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder @@ -79,7 +80,9 @@ public class DeserializerForClassfileDecompiler( } val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings) val membersScope = DeserializedPackageMemberScope( - createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents + createDummyPackageFragment(packageFqName), packageProto, nameResolver, + JvmPackagePartSource(JvmClassName.byClassId(binaryClassForPackageClass!!.classId)), + deserializationComponents ) { emptyList() } return membersScope.getContributedDescriptors().toList() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt index b6806f94736..7d9e88473b1 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.stubindex.KotlinFileStubForIde import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -32,6 +33,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.impl.* +import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.serialization.Flags import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind @@ -52,7 +54,7 @@ fun createPackageFacadeStub( ): KotlinFileStubImpl { val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot) setupFileStub(fileStub, packageFqName) - createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable), + createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable, packagePartSource = null), packageProto.functionList, packageProto.propertyList) return fileStub } @@ -65,8 +67,10 @@ fun createFileFacadeStub( val packageFqName = facadeFqName.parent() val fileStub = KotlinFileStubForIde.forFileFacadeStub(facadeFqName, packageFqName.isRoot) setupFileStub(fileStub, packageFqName) - createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable), - packageProto.functionList, packageProto.propertyList) + val container = ProtoContainer.Package( + packageFqName, c.nameResolver, c.typeTable, JvmPackagePartSource(JvmClassName.byFqNameWithoutInnerClasses(facadeFqName)) + ) + createCallableStubs(fileStub, c, container, packageProto.functionList, packageProto.propertyList) return fileStub } @@ -84,8 +88,9 @@ fun createMultifileClassStub( val partHeader = partFile.classHeader val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(partHeader.annotationData!!, partHeader.strings!!) val partContext = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable)) - createCallableStubs(fileStub, partContext, ProtoContainer.Package(packageFqName, partContext.nameResolver, partContext.typeTable), - packageProto.functionList, packageProto.propertyList) + val container = ProtoContainer.Package(packageFqName, partContext.nameResolver, partContext.typeTable, + JvmPackagePartSource(JvmClassName.byClassId(partFile.classId))) + createCallableStubs(fileStub, partContext, container, packageProto.functionList, packageProto.propertyList) } return fileStub } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt index 315600d3310..bc09643b3c8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt @@ -81,7 +81,8 @@ public abstract class DeserializerForDecompilerBase( val content = file.contentsToByteArray(false) val packageProto = content.toPackageProto(paths.extensionRegistry) val membersScope = DeserializedPackageMemberScope( - createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents + createDummyPackageFragment(packageFqName), packageProto, nameResolver, packagePartSource = null, + components = deserializationComponents ) { emptyList() } return membersScope.getContributedDescriptors().toList() }