Fix stub-psi mismatch exception on restoring annotation for nullable types
(cherry picked from commit 1aa37f11258dde289a9f7cb700294a038168fbdc) Conflicts: compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt
This commit is contained in:
+20
-15
@@ -55,28 +55,31 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_NOT_LOADED_FOR_TYPES
|
||||
}
|
||||
|
||||
val effectiveParent =
|
||||
if (type.nullable) KotlinPlaceHolderStubImpl<KtNullableType>(typeReference, KtStubElementTypes.NULLABLE_TYPE)
|
||||
else typeReference
|
||||
|
||||
fun createTypeParameterStub(name: Name) {
|
||||
createTypeAnnotationStubs(effectiveParent, annotations)
|
||||
createStubForTypeName(ClassId.topLevel(FqName.topLevel(name)), effectiveParent)
|
||||
}
|
||||
|
||||
when {
|
||||
type.hasClassName() || type.hasTypeAliasName() -> createClassReferenceTypeStub(effectiveParent, type, annotations)
|
||||
type.hasTypeParameter() -> createTypeParameterStub(c.typeParameters[type.typeParameter])
|
||||
type.hasTypeParameterName() -> createTypeParameterStub(c.nameResolver.getName(type.typeParameterName))
|
||||
type.hasClassName() || type.hasTypeAliasName() ->
|
||||
createClassReferenceTypeStub(typeReference, type, annotations)
|
||||
type.hasTypeParameter() ->
|
||||
createTypeParameterStub(typeReference, type, c.typeParameters[type.typeParameter], annotations)
|
||||
type.hasTypeParameterName() ->
|
||||
createTypeParameterStub(typeReference, type, c.nameResolver.getName(type.typeParameterName), annotations)
|
||||
}
|
||||
}
|
||||
|
||||
private fun nullableTypeParent(parent: KotlinStubBaseImpl<*>, type: Type): KotlinStubBaseImpl<*> =
|
||||
if (type.nullable) KotlinPlaceHolderStubImpl<KtNullableType>(parent, KtStubElementTypes.NULLABLE_TYPE)
|
||||
else parent
|
||||
|
||||
private fun createTypeParameterStub(parent: KotlinStubBaseImpl<*>, type: Type, name: Name, annotations: List<ClassId>) {
|
||||
createTypeAnnotationStubs(parent, annotations)
|
||||
createStubForTypeName(ClassId.topLevel(FqName.topLevel(name)), nullableTypeParent(parent, type))
|
||||
}
|
||||
|
||||
private fun createClassReferenceTypeStub(parent: KotlinStubBaseImpl<*>, type: Type, annotations: List<ClassId>) {
|
||||
if (type.hasFlexibleTypeCapabilitiesId()) {
|
||||
val id = c.nameResolver.getString(type.flexibleTypeCapabilitiesId)
|
||||
|
||||
if (id == DynamicTypeDeserializer.id) {
|
||||
KotlinPlaceHolderStubImpl<KtDynamicType>(parent, KtStubElementTypes.DYNAMIC_TYPE)
|
||||
KotlinPlaceHolderStubImpl<KtDynamicType>(nullableTypeParent(parent, type), KtStubElementTypes.DYNAMIC_TYPE)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -92,13 +95,15 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
val extension = annotations.any { annotation ->
|
||||
annotation.asSingleFqName() == KotlinBuiltIns.FQ_NAMES.extensionFunctionType
|
||||
}
|
||||
createFunctionTypeStub(parent, type, extension)
|
||||
createFunctionTypeStub(nullableTypeParent(parent, type), type, extension)
|
||||
return
|
||||
}
|
||||
|
||||
createTypeAnnotationStubs(parent, annotations)
|
||||
|
||||
val outerTypeChain = generateSequence(type) { it.outerType(c.typeTable) }.toList()
|
||||
|
||||
createStubForTypeName(classId, parent) {
|
||||
createStubForTypeName(classId, nullableTypeParent(parent, type)) {
|
||||
userTypeStub, index ->
|
||||
outerTypeChain.getOrNull(index)?.let { createTypeArgumentListStub(userTypeStub, it.argumentList) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user