[AA LC] Keep original qualifier while translating error cone types to Psi types

This commit is contained in:
Dmitriy Novozhilov
2022-09-26 17:00:59 +03:00
committed by Space Team
parent a3b9f15ecc
commit d5a76a1b3b
19 changed files with 79 additions and 47 deletions
@@ -44,4 +44,4 @@ internal class KtFe10ClassErrorType(
override val nullability: KtTypeNullability
get() = withValidityAssertion { fe10Type.ktNullability }
}
}
@@ -121,4 +121,8 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping(
override fun functionNTypeConstructor(n: Int): TypeConstructorMarker {
return builtIns.getFunction(n).typeConstructor
}
override fun KotlinTypeMarker.getNameForErrorType(): String? {
return null
}
}
@@ -133,4 +133,4 @@ public abstract class KtIntegerLiteralType : KtType {
*/
public abstract class KtDynamicType : KtType {
override fun toString(): String = asStringForDebugging()
}
}
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithTypeParameters
import org.jetbrains.kotlin.analysis.api.symbols.markers.isPrivateOrPrivateToThis
import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
@@ -418,30 +419,42 @@ internal fun SymbolLightClassForClassLike<*>.createInheritanceList(
)
fun KtType.needToAddTypeIntoList(): Boolean {
if (this !is KtNonErrorClassType) return false
// Do not add redundant "extends java.lang.Object" anywhere
if (this.classId == StandardClassIds.Any) return false
// We don't have Enum among enums supertype in sources neither we do for decompiled class-files and light-classes
if (isEnum && this.classId == StandardClassIds.Enum) return false
if (this.isAny) return false
// Interfaces have only extends lists
if (isInterface) return forExtendsList
val classKind = (classSymbol as? KtClassOrObjectSymbol)?.classKind
val isJvmInterface = classKind == KtClassKind.INTERFACE || classKind == KtClassKind.ANNOTATION_CLASS
return when (this) {
is KtNonErrorClassType -> {
// We don't have Enum among enums supertype in sources neither we do for decompiled class-files and light-classes
if (isEnum && this.classId == StandardClassIds.Enum) return false
return forExtendsList == !isJvmInterface
val classKind = (classSymbol as? KtClassOrObjectSymbol)?.classKind
val isJvmInterface = classKind == KtClassKind.INTERFACE || classKind == KtClassKind.ANNOTATION_CLASS
forExtendsList == !isJvmInterface
}
is KtClassErrorType -> {
val superList = this@createInheritanceList.kotlinOrigin?.getSuperTypeList() ?: return false
val qualifierName = this.qualifiers.joinToString(".") { it.name.asString() }.takeIf { it.isNotEmpty() } ?: return false
val isConstructorCall = superList.findEntry(qualifierName) is KtSuperTypeCallEntry
forExtendsList == isConstructorCall
}
else -> false
}
}
superTypes.asSequence()
.filter { it.needToAddTypeIntoList() }
.forEach { superType ->
if (superType !is KtNonErrorClassType) return@forEach
val mappedType =
mapType(superType, this@createInheritanceList, KtTypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS)
?: return@forEach
val mappedType = mapType(
superType,
this@createInheritanceList,
KtTypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS
) ?: return@forEach
listBuilder.addReference(mappedType)
if (mappedType.canonicalText.startsWith("kotlin.collections.")) {
val mappedToNoCollectionAsIs = mapType(superType, this@createInheritanceList, KtTypeMappingMode.SUPER_TYPE)
@@ -451,7 +464,9 @@ internal fun SymbolLightClassForClassLike<*>.createInheritanceList(
// Add java supertype
listBuilder.addReference(mappedToNoCollectionAsIs)
// Add marker interface
listBuilder.addMarkerInterfaceIfNeeded(superType.classId)
if (superType is KtNonErrorClassType) {
listBuilder.addMarkerInterfaceIfNeeded(superType.classId)
}
}
}
}
@@ -43,7 +43,6 @@ internal fun KtAnalysisSession.mapType(
psiContext: PsiElement,
mode: KtTypeMappingMode
): PsiClassType? {
if (type is KtClassErrorType) return null
val psiType = type.asPsiType(
psiContext,
allowErrorTypes = true,