Fix nested class context in cls stub builder
Previously two contexts were created for a nested class stub: one with the replaced NameResolver, another with everything else. Now only one is created
This commit is contained in:
+14
-5
@@ -35,23 +35,32 @@ 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.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.deserialization.supertypes
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
fun createClassStub(parent: StubElement<out PsiElement>, classProto: ProtoBuf.Class, classId: ClassId, context: ClsStubBuilderContext) {
|
||||
ClassClsStubBuilder(parent, classProto, classId, context).build()
|
||||
fun createClassStub(
|
||||
parent: StubElement<out PsiElement>,
|
||||
classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver,
|
||||
classId: ClassId,
|
||||
context: ClsStubBuilderContext
|
||||
) {
|
||||
ClassClsStubBuilder(parent, classProto, nameResolver, classId, context).build()
|
||||
}
|
||||
|
||||
private class ClassClsStubBuilder(
|
||||
private val parentStub: StubElement<out PsiElement>,
|
||||
private val classProto: ProtoBuf.Class,
|
||||
private val nameResolver: NameResolver,
|
||||
private val classId: ClassId,
|
||||
private val outerContext: ClsStubBuilderContext
|
||||
) {
|
||||
private val classKind = Flags.CLASS_KIND[classProto.flags]
|
||||
private val c = outerContext.child(classProto.typeParameterList, classKind, classId.shortClassName, TypeTable(classProto.typeTable))
|
||||
private val c = outerContext.child(classProto.typeParameterList, classKind, classId.shortClassName, nameResolver,
|
||||
TypeTable(classProto.typeTable))
|
||||
private val typeStubBuilder = TypeClsStubBuilder(c)
|
||||
private val supertypeIds = run {
|
||||
val supertypeIds = classProto.supertypes(c.typeTable).map { c.nameResolver.getClassId(it.className) }
|
||||
@@ -105,7 +114,7 @@ private class ClassClsStubBuilder(
|
||||
|
||||
private fun doCreateClassOrObjectStub(): StubElement<out PsiElement> {
|
||||
val isCompanionObject = classKind == ProtoBuf.Class.Kind.COMPANION_OBJECT
|
||||
val fqName = outerContext.containerFqName.child(classId.getShortClassName())
|
||||
val fqName = classId.asSingleFqName()
|
||||
val shortName = fqName.shortName().ref()
|
||||
val superTypeRefs = supertypeIds.filterNot {
|
||||
//TODO: filtering function types should go away
|
||||
@@ -254,7 +263,7 @@ private class ClassClsStubBuilder(
|
||||
return
|
||||
}
|
||||
val (nameResolver, classProto) = classDataWithSource.classData
|
||||
createClassStub(classBody, classProto, nestedClassId, c.child(nameResolver, TypeTable(classProto.typeTable)))
|
||||
createClassStub(classBody, classProto, nameResolver, nestedClassId, c)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-12
@@ -77,25 +77,15 @@ internal fun ClsStubBuilderContext.child(
|
||||
typeParameterList: List<ProtoBuf.TypeParameter>,
|
||||
classKind: ProtoBuf.Class.Kind? = null,
|
||||
name: Name? = null,
|
||||
nameResolver: NameResolver = this.nameResolver,
|
||||
typeTable: TypeTable = this.typeTable
|
||||
): ClsStubBuilderContext {
|
||||
return ClsStubBuilderContext(
|
||||
this.components,
|
||||
this.nameResolver,
|
||||
nameResolver,
|
||||
if (name != null) this.containerFqName.child(name) else this.containerFqName,
|
||||
this.typeParameters.child(nameResolver, typeParameterList),
|
||||
typeTable,
|
||||
classKind
|
||||
)
|
||||
}
|
||||
|
||||
internal fun ClsStubBuilderContext.child(nameResolver: NameResolver, typeTable: TypeTable): ClsStubBuilderContext {
|
||||
return ClsStubBuilderContext(
|
||||
this.components,
|
||||
nameResolver,
|
||||
this.containerFqName,
|
||||
this.typeParameters,
|
||||
typeTable,
|
||||
classKind = null
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
|
||||
fun createTopLevelClassStub(classId: ClassId, classProto: ProtoBuf.Class, context: ClsStubBuilderContext): KotlinFileStubImpl {
|
||||
val fileStub = createFileStub(classId.getPackageFqName())
|
||||
createClassStub(fileStub, classProto, classId, context)
|
||||
val fileStub = createFileStub(classId.packageFqName)
|
||||
createClassStub(fileStub, classProto, context.nameResolver, classId, context)
|
||||
return fileStub
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user