Introduce PackagePartSource to store part class name in deserialized descriptors

Not used at the moment, will be in the following commits
This commit is contained in:
Alexander Udalov
2015-12-18 23:14:53 +03:00
parent f4c5289cfc
commit 03606c13aa
14 changed files with 92 additions and 34 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl 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.ModuleMapping
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
@@ -112,7 +113,9 @@ public class IncrementalPackageFragmentProvider(
allParts.filterNot { it in obsoletePackageParts } allParts.filterNot { it in obsoletePackageParts }
} ?: emptyList<String>() } ?: emptyList<String>()
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()) { if (scopes.isEmpty()) {
MemberScope.Empty MemberScope.Empty
@@ -136,13 +139,15 @@ public class IncrementalPackageFragmentProvider(
val partsNames: Collection<String> val partsNames: Collection<String>
) : PackageFragmentDescriptorImpl(moduleDescriptor, multifileClassFqName.parent()) { ) : PackageFragmentDescriptorImpl(moduleDescriptor, multifileClassFqName.parent()) {
val memberScope = storageManager.createLazyValue { 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()) if (partsData.isEmpty())
MemberScope.Empty MemberScope.Empty
else { else {
ChainedMemberScope( ChainedMemberScope(
"Member scope for incremental compilation: union of multifile class parts data for $multifileClassFqName", "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() 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) val packageData = JvmProtoBufUtil.readPackageDataFrom(part.data, part.strings)
return DeserializedPackageMemberScope( return DeserializedPackageMemberScope(
this, packageData.packageProto, packageData.nameResolver, deserializationComponents, { listOf() } this, packageData.packageProto, packageData.nameResolver,
JvmPackagePartSource(JvmClassName.byInternalName(internalName)),
deserializationComponents, { listOf() }
) )
} }
} }
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader; import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader;
import org.jetbrains.kotlin.name.Name; 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.ChainedMemberScope;
import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.serialization.ClassData; import org.jetbrains.kotlin.serialization.ClassData;
@@ -79,8 +80,9 @@ public final class DeserializedDescriptorResolver {
String[] strings = kotlinClass.getClassHeader().getStrings(); String[] strings = kotlinClass.getClassHeader().getStrings();
assert strings != null : "String table not found in " + kotlinClass; assert strings != null : "String table not found in " + kotlinClass;
PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data, strings); PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data, strings);
JvmPackagePartSource source = new JvmPackagePartSource(JvmClassName.byClassId(kotlinClass.getClassId()));
return new DeserializedPackageMemberScope( return new DeserializedPackageMemberScope(
descriptor, packageData.getPackageProto(), packageData.getNameResolver(), components, descriptor, packageData.getPackageProto(), packageData.getNameResolver(), source, components,
new Function0<Collection<Name>>() { new Function0<Collection<Name>>() {
@Override @Override
public Collection<Name> invoke() { public Collection<Name> invoke() {
@@ -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
@@ -56,7 +56,7 @@ public class ClassDeserializer(private val components: DeserializationComponents
if (!fragment.hasTopLevelClass(classId.shortClassName)) return null 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) return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement)
@@ -50,7 +50,8 @@ public abstract class DeserializedPackageFragment(
internal val deserializedMemberScope by storageManager.createLazyValue { internal val deserializedMemberScope by storageManager.createLazyValue {
val packageStream = loadResourceSure(serializedResourcePaths.getPackageFilePath(fqName)) val packageStream = loadResourceSure(serializedResourcePaths.getPackageFilePath(fqName))
val packageProto = ProtoBuf.Package.parseFrom(packageStream, serializedResourcePaths.extensionRegistry) 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 override fun getMemberScope() = deserializedMemberScope
@@ -47,7 +47,8 @@ public class MemberDeserializer(private val c: DeserializationContext) {
Flags.IS_CONST.get(flags), Flags.IS_CONST.get(flags),
proto, proto,
c.nameResolver, c.nameResolver,
c.typeTable c.typeTable,
c.packagePartSource
) )
val local = c.childContext(property, proto.getTypeParameterList()) val local = c.childContext(property, proto.getTypeParameterList())
@@ -142,7 +143,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
else Annotations.EMPTY else Annotations.EMPTY
val function = DeserializedSimpleFunctionDescriptor( val function = DeserializedSimpleFunctionDescriptor(
c.containingDeclaration, /* original = */ null, annotations, c.nameResolver.getName(proto.name), 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) val local = c.childContext(function, proto.typeParameterList)
function.initialize( function.initialize(
@@ -170,7 +171,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
val classDescriptor = c.containingDeclaration as ClassDescriptor val classDescriptor = c.containingDeclaration as ClassDescriptor
val descriptor = DeserializedConstructorDescriptor( val descriptor = DeserializedConstructorDescriptor(
classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION), 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()) val local = c.childContext(descriptor, listOf())
descriptor.initialize( descriptor.initialize(
@@ -243,7 +244,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
} }
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) { 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( is DeserializedClassDescriptor -> ProtoContainer.Class(
classProto, c.nameResolver, c.typeTable, classProto, c.nameResolver, c.typeTable,
isCompanionOfClass = DescriptorUtils.isCompanionObject(this) && isCompanionOfClass = DescriptorUtils.isCompanionObject(this) &&
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource
sealed class ProtoContainer( sealed class ProtoContainer(
val nameResolver: NameResolver, val nameResolver: NameResolver,
@@ -35,7 +36,8 @@ sealed class ProtoContainer(
class Package( class Package(
val fqName: FqName, val fqName: FqName,
nameResolver: NameResolver, nameResolver: NameResolver,
typeTable: TypeTable typeTable: TypeTable,
val packagePartSource: PackagePartSource?
) : ProtoContainer(nameResolver, typeTable) { ) : ProtoContainer(nameResolver, typeTable) {
override fun debugFqName(): FqName = fqName override fun debugFqName(): FqName = fqName
} }
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
class DeserializationComponents( class DeserializationComponents(
@@ -46,9 +47,11 @@ class DeserializationComponents(
fun createContext( fun createContext(
descriptor: PackageFragmentDescriptor, descriptor: PackageFragmentDescriptor,
nameResolver: NameResolver, nameResolver: NameResolver,
typeTable: TypeTable typeTable: TypeTable,
packagePartSource: PackagePartSource?
): DeserializationContext = ): 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 nameResolver: NameResolver,
val containingDeclaration: DeclarationDescriptor, val containingDeclaration: DeclarationDescriptor,
val typeTable: TypeTable, val typeTable: TypeTable,
val packagePartSource: PackagePartSource?,
parentTypeDeserializer: TypeDeserializer?, parentTypeDeserializer: TypeDeserializer?,
typeParameters: List<ProtoBuf.TypeParameter> typeParameters: List<ProtoBuf.TypeParameter>
) { ) {
val typeDeserializer = TypeDeserializer(this, parentTypeDeserializer, typeParameters, val typeDeserializer = TypeDeserializer(this, parentTypeDeserializer, typeParameters,
"Deserializer for ${containingDeclaration.getName()}") "Deserializer for ${containingDeclaration.name}")
val memberDeserializer = MemberDeserializer(this) val memberDeserializer = MemberDeserializer(this)
@@ -73,8 +77,7 @@ class DeserializationContext(
nameResolver: NameResolver = this.nameResolver, nameResolver: NameResolver = this.nameResolver,
typeTable: TypeTable = this.typeTable typeTable: TypeTable = this.typeTable
) = DeserializationContext( ) = DeserializationContext(
components, nameResolver, descriptor, typeTable, components, nameResolver, descriptor, typeTable, this.packagePartSource,
parentTypeDeserializer = this.typeDeserializer, parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
typeParameters = typeParameterProtos
) )
} }
@@ -34,8 +34,14 @@ interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor {
val nameResolver: NameResolver val nameResolver: NameResolver
val typeTable: TypeTable 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( class DeserializedSimpleFunctionDescriptor(
containingDeclaration: DeclarationDescriptor, containingDeclaration: DeclarationDescriptor,
original: SimpleFunctionDescriptor?, original: SimpleFunctionDescriptor?,
@@ -44,7 +50,8 @@ class DeserializedSimpleFunctionDescriptor(
kind: CallableMemberDescriptor.Kind, kind: CallableMemberDescriptor.Kind,
override val proto: ProtoBuf.Function, override val proto: ProtoBuf.Function,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) { SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) {
@@ -56,7 +63,8 @@ class DeserializedSimpleFunctionDescriptor(
preserveSource: Boolean preserveSource: Boolean
): FunctionDescriptorImpl { ): FunctionDescriptorImpl {
return DeserializedSimpleFunctionDescriptor( 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, isConst: Boolean,
override val proto: ProtoBuf.Property, override val proto: ProtoBuf.Property,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations, PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) { modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) {
@@ -88,7 +97,7 @@ class DeserializedPropertyDescriptor(
): PropertyDescriptorImpl { ): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor( return DeserializedPropertyDescriptor(
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst, 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, kind: CallableMemberDescriptor.Kind,
override val proto: ProtoBuf.Constructor, override val proto: ProtoBuf.Constructor,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) { ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) {
@@ -114,7 +124,7 @@ class DeserializedConstructorDescriptor(
): DeserializedConstructorDescriptor { ): DeserializedConstructorDescriptor {
return DeserializedConstructorDescriptor( return DeserializedConstructorDescriptor(
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
proto, nameResolver, typeTable proto, nameResolver, typeTable, packagePartSource
) )
} }
@@ -36,10 +36,11 @@ public open class DeserializedPackageMemberScope(
packageDescriptor: PackageFragmentDescriptor, packageDescriptor: PackageFragmentDescriptor,
proto: ProtoBuf.Package, proto: ProtoBuf.Package,
nameResolver: NameResolver, nameResolver: NameResolver,
packagePartSource: PackagePartSource?,
components: DeserializationComponents, components: DeserializationComponents,
classNames: () -> Collection<Name> classNames: () -> Collection<Name>
) : DeserializedMemberScope( ) : DeserializedMemberScope(
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable)), components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), packagePartSource),
proto.functionList, proto.propertyList proto.functionList, proto.propertyList
) { ) {
private val packageFqName = packageDescriptor.fqName private val packageFqName = packageDescriptor.fqName
@@ -46,7 +46,7 @@ public fun <R> Function<R>.reflect(): KFunction<R>? {
val moduleData = javaClass.getOrCreateModule() val moduleData = javaClass.getOrCreateModule()
val context = DeserializationContext( val context = DeserializationContext(
moduleData.deserialization, nameResolver, moduleData.module, 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) val descriptor = MemberDeserializer(context).loadFunction(proto)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.load.kotlin.*
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.TargetPlatform 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.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.serialization.ClassDataWithSource import org.jetbrains.kotlin.serialization.ClassDataWithSource
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
@@ -79,7 +80,9 @@ public class DeserializerForClassfileDecompiler(
} }
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings) val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings)
val membersScope = DeserializedPackageMemberScope( val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents createDummyPackageFragment(packageFqName), packageProto, nameResolver,
JvmPackagePartSource(JvmClassName.byClassId(binaryClassForPackageClass!!.classId)),
deserializationComponents
) { emptyList() } ) { emptyList() }
return membersScope.getContributedDescriptors().toList() return membersScope.getContributedDescriptors().toList()
} }
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.stubindex.KotlinFileStubForIde import org.jetbrains.kotlin.idea.stubindex.KotlinFileStubForIde
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName 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.KotlinUserTypeStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.impl.* 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.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind
@@ -52,7 +54,7 @@ fun createPackageFacadeStub(
): KotlinFileStubImpl { ): KotlinFileStubImpl {
val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot) val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot)
setupFileStub(fileStub, packageFqName) 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) packageProto.functionList, packageProto.propertyList)
return fileStub return fileStub
} }
@@ -65,8 +67,10 @@ fun createFileFacadeStub(
val packageFqName = facadeFqName.parent() val packageFqName = facadeFqName.parent()
val fileStub = KotlinFileStubForIde.forFileFacadeStub(facadeFqName, packageFqName.isRoot) val fileStub = KotlinFileStubForIde.forFileFacadeStub(facadeFqName, packageFqName.isRoot)
setupFileStub(fileStub, packageFqName) setupFileStub(fileStub, packageFqName)
createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable), val container = ProtoContainer.Package(
packageProto.functionList, packageProto.propertyList) packageFqName, c.nameResolver, c.typeTable, JvmPackagePartSource(JvmClassName.byFqNameWithoutInnerClasses(facadeFqName))
)
createCallableStubs(fileStub, c, container, packageProto.functionList, packageProto.propertyList)
return fileStub return fileStub
} }
@@ -84,8 +88,9 @@ fun createMultifileClassStub(
val partHeader = partFile.classHeader val partHeader = partFile.classHeader
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(partHeader.annotationData!!, partHeader.strings!!) val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(partHeader.annotationData!!, partHeader.strings!!)
val partContext = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable)) val partContext = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
createCallableStubs(fileStub, partContext, ProtoContainer.Package(packageFqName, partContext.nameResolver, partContext.typeTable), val container = ProtoContainer.Package(packageFqName, partContext.nameResolver, partContext.typeTable,
packageProto.functionList, packageProto.propertyList) JvmPackagePartSource(JvmClassName.byClassId(partFile.classId)))
createCallableStubs(fileStub, partContext, container, packageProto.functionList, packageProto.propertyList)
} }
return fileStub return fileStub
} }
@@ -81,7 +81,8 @@ public abstract class DeserializerForDecompilerBase(
val content = file.contentsToByteArray(false) val content = file.contentsToByteArray(false)
val packageProto = content.toPackageProto(paths.extensionRegistry) val packageProto = content.toPackageProto(paths.extensionRegistry)
val membersScope = DeserializedPackageMemberScope( val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents createDummyPackageFragment(packageFqName), packageProto, nameResolver, packagePartSource = null,
components = deserializationComponents
) { emptyList() } ) { emptyList() }
return membersScope.getContributedDescriptors().toList() return membersScope.getContributedDescriptors().toList()
} }