Store outer class in ProtoContainer instead of only its kind
This commit is contained in:
+6
-4
@@ -215,10 +215,12 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
return kotlinClassFinder.findKotlinClass(implClassName)
|
||||
}
|
||||
|
||||
if (field && container.kind == ProtoBuf.Class.Kind.COMPANION_OBJECT &&
|
||||
(container.outerClassKind == ClassKind.CLASS || container.outerClassKind == ClassKind.ENUM_CLASS)) {
|
||||
// Backing fields of properties of a companion object in a class are generated in the outer class
|
||||
return kotlinClassFinder.findKotlinClass(container.classId.outerClassId)
|
||||
if (field && container.kind == ProtoBuf.Class.Kind.COMPANION_OBJECT) {
|
||||
val outerClass = container.outerClass
|
||||
if (outerClass != null && (outerClass.kind == ProtoBuf.Class.Kind.CLASS || outerClass.kind == ProtoBuf.Class.Kind.ENUM_CLASS)) {
|
||||
// Backing fields of properties of a companion object in a class are generated in the outer class
|
||||
return outerClass.toBinaryClass()
|
||||
}
|
||||
}
|
||||
|
||||
return containerBinaryClass
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -33,7 +32,7 @@ sealed class ProtoContainer(
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
source: SourceElement?,
|
||||
val outerClassKind: ClassKind?
|
||||
val outerClass: ProtoContainer.Class?
|
||||
) : ProtoContainer(nameResolver, typeTable, source) {
|
||||
val classId: ClassId = nameResolver.getClassId(classProto.fqName)
|
||||
|
||||
|
||||
+3
-2
@@ -73,8 +73,9 @@ class DeserializedClassDescriptor(
|
||||
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
|
||||
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
|
||||
|
||||
internal val thisAsProtoContainer = ProtoContainer.Class(
|
||||
classProto, c.nameResolver, c.typeTable, sourceElement, (containingDeclaration as? ClassDescriptor)?.kind
|
||||
internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class(
|
||||
classProto, c.nameResolver, c.typeTable, sourceElement,
|
||||
(containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer
|
||||
)
|
||||
|
||||
private val annotations =
|
||||
|
||||
+12
-8
@@ -37,7 +37,10 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinObjectStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.deserialization.supertypes
|
||||
|
||||
fun createClassStub(
|
||||
parent: StubElement<out PsiElement>,
|
||||
@@ -58,9 +61,14 @@ private class ClassClsStubBuilder(
|
||||
private val source: SourceElement?,
|
||||
private val outerContext: ClsStubBuilderContext
|
||||
) {
|
||||
private val classKind = Flags.CLASS_KIND[classProto.flags]
|
||||
private val c = outerContext.child(classProto.typeParameterList, classKind, classId.shortClassName, nameResolver,
|
||||
TypeTable(classProto.typeTable))
|
||||
private val thisAsProtoContainer = ProtoContainer.Class(
|
||||
classProto, nameResolver, TypeTable(classProto.typeTable), source, outerContext.protoContainer
|
||||
)
|
||||
private val classKind = thisAsProtoContainer.kind
|
||||
|
||||
private val c = outerContext.child(
|
||||
classProto.typeParameterList, classId.shortClassName, nameResolver, thisAsProtoContainer.typeTable, thisAsProtoContainer
|
||||
)
|
||||
private val typeStubBuilder = TypeClsStubBuilder(c)
|
||||
private val supertypeIds = run {
|
||||
val supertypeIds = classProto.supertypes(c.typeTable).map { c.nameResolver.getClassId(it.className) }
|
||||
@@ -76,10 +84,6 @@ private class ClassClsStubBuilder(
|
||||
private val companionObjectName =
|
||||
if (classProto.hasCompanionObjectName()) c.nameResolver.getName(classProto.companionObjectName) else null
|
||||
|
||||
private val thisAsProtoContainer = ProtoContainer.Class(
|
||||
classProto, c.nameResolver, c.typeTable, source, outerContext.classKind?.let { Deserialization.classKind(it) }
|
||||
)
|
||||
|
||||
private val classOrObjectStub = createClassOrObjectStubAndModifierListStub()
|
||||
|
||||
fun build() {
|
||||
|
||||
+6
-9
@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantLoader
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
|
||||
data class ClassIdWithTarget(val classId: ClassId, val target: AnnotationUseSiteTarget?)
|
||||
|
||||
@@ -39,7 +36,7 @@ class ClsStubBuilderComponents(
|
||||
packageFqName: FqName,
|
||||
typeTable: TypeTable
|
||||
): ClsStubBuilderContext {
|
||||
return ClsStubBuilderContext(this, nameResolver, packageFqName, EmptyTypeParameters, typeTable, classKind = null)
|
||||
return ClsStubBuilderContext(this, nameResolver, packageFqName, EmptyTypeParameters, typeTable, protoContainer = null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,15 +67,15 @@ class ClsStubBuilderContext(
|
||||
val containerFqName: FqName,
|
||||
val typeParameters: TypeParameters,
|
||||
val typeTable: TypeTable,
|
||||
val classKind: ProtoBuf.Class.Kind?
|
||||
val protoContainer: ProtoContainer.Class?
|
||||
)
|
||||
|
||||
internal fun ClsStubBuilderContext.child(
|
||||
typeParameterList: List<ProtoBuf.TypeParameter>,
|
||||
classKind: ProtoBuf.Class.Kind? = null,
|
||||
name: Name? = null,
|
||||
nameResolver: NameResolver = this.nameResolver,
|
||||
typeTable: TypeTable = this.typeTable
|
||||
typeTable: TypeTable = this.typeTable,
|
||||
protoContainer: ProtoContainer.Class? = this.protoContainer
|
||||
): ClsStubBuilderContext {
|
||||
return ClsStubBuilderContext(
|
||||
this.components,
|
||||
@@ -86,6 +83,6 @@ internal fun ClsStubBuilderContext.child(
|
||||
if (name != null) this.containerFqName.child(name) else this.containerFqName,
|
||||
this.typeParameters.child(nameResolver, typeParameterList),
|
||||
typeTable,
|
||||
classKind
|
||||
protoContainer
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user