[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,
@@ -58,7 +58,8 @@ object AbstractTypeMapper {
sw: Writer? = null
): Type {
if (type.isError()) {
val jvmType = Type.getObjectType(NON_EXISTENT_CLASS_NAME)
val name = type.getNameForErrorType() ?: NON_EXISTENT_CLASS_NAME
val jvmType = Type.getObjectType(name)
with(context) { sw?.writeGenericType(type, jvmType, mode) }
return jvmType
}
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.isInner
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.resolve.defaultType
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedSymbolError
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedTypeQualifierError
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.resolve.toSymbol
@@ -33,9 +34,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.types.AbstractTypeMapper
import org.jetbrains.kotlin.types.TypeMappingContext
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
@@ -44,7 +43,6 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.TypeParameterMarker
import org.jetbrains.kotlin.utils.addToStdlib.runIf
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
import org.jetbrains.org.objectweb.asm.Type
@@ -294,4 +292,13 @@ class ConeTypeSystemCommonBackendContextForTypeMapping(
return symbolProvider.getClassLikeSymbolByClassId(classId)?.toLookupTag()
?: ConeClassLikeErrorLookupTag(classId)
}
override fun KotlinTypeMarker.getNameForErrorType(): String? {
require(this is ConeErrorType)
val result = when (val diagnostic = diagnostic) {
is ConeUnresolvedTypeQualifierError -> diagnostic.qualifier
else -> null
}
return result
}
}
@@ -280,4 +280,8 @@ private class IrTypeCheckerContextForTypeMapping(
override fun functionNTypeConstructor(n: Int): IrClassSymbol {
return backendContext.irBuiltIns.functionN(n).symbol
}
override fun KotlinTypeMarker.getNameForErrorType(): String? {
return null
}
}
@@ -31,15 +31,15 @@ public final class Container /* p1.Container*/ {
@org.jetbrains.annotations.NotNull()
public java.lang.CharSequence subSequence(int, int);// subSequence(int, int)
@java.lang.Override()
public IntStream chars();// chars()
@java.lang.Override()
public IntStream codePoints();// codePoints()
@java.lang.Override()
public char get(int);// get(int)
@java.lang.Override()
public error.NonExistentClass chars();// chars()
@java.lang.Override()
public error.NonExistentClass codePoints();// codePoints()
public MyString();// .ctor()
public int getLength();// getLength()
@@ -1,4 +1,4 @@
public final class C /* p.C*/ {
public final class C /* p.C*/ extends A {
@java.lang.Override()
public int af();// af()
@@ -1,4 +1,4 @@
public final class C /* p.C*/ {
public final class C /* p.C*/ extends A implements I {
private final int ip = 5 /* initializer type: int */;
@java.lang.Override()
@@ -1,4 +1,4 @@
public final class C /* p.C*/ {
public final class C /* p.C*/ extends A {
@java.lang.Override()
public int af();// af()
@@ -151,7 +151,7 @@ public final class Foo /* Foo*/ {
private java.lang.String x = null /* initializer type: null */;
@Anno()
public Foo(error.NonExistentClass);// .ctor(error.NonExistentClass)
public Foo(MyDependency);// .ctor(MyDependency)
@Anno()
public final void f4(@org.jetbrains.annotations.NotNull() java.lang.String);// f4(java.lang.String)
@@ -24,7 +24,7 @@ public final class JvmWildcardAnnotationsKt /* JvmWildcardAnnotationsKt*/ {
@kotlin.jvm.JvmSuppressWildcards(suppress = true)
@org.jetbrains.annotations.NotNull()
public static final Out<error.NonExistentClass> foo2();// foo2()
public static final Out<T> foo2();// foo2()
@kotlin.jvm.JvmSuppressWildcards(suppress = true)
public static final int bar(boolean, @org.jetbrains.annotations.NotNull() In<? super java.lang.Long>, long);// bar(boolean, In<? super java.lang.Long>, long)
@@ -64,7 +64,7 @@ public final class PropertiesKt /* PropertiesKt*/ {
private static java.lang.String protectedLateinitVar;
public static error.NonExistentClass subject;
public static Unresolved subject;
@org.jetbrains.annotations.NotNull()
protected static final java.lang.String getProtectedLateinitVar();// getProtectedLateinitVar()
@@ -124,14 +124,14 @@ public final class PropertiesKt /* PropertiesKt*/ {
protected static final void setProtectedLateinitVar(@org.jetbrains.annotations.NotNull() java.lang.String);// setProtectedLateinitVar(java.lang.String)
public static final Unresolved getSubject();// getSubject()
public static final boolean isEmpty();// isEmpty()
public static final error.NonExistentClass getDelegatedProp2();// getDelegatedProp2()
public static final error.NonExistentClass getIntConst();// getIntConst()
public static final error.NonExistentClass getSubject();// getSubject()
public static final int getCounter();// getCounter()
public static final int getF1();// getF1()
@@ -144,7 +144,7 @@ public final class PropertiesKt /* PropertiesKt*/ {
public static final int getPlainField();// getPlainField()
public static final int getValue(error.NonExistentClass, @org.jetbrains.annotations.NotNull() kotlin.reflect.KProperty<?>);// getValue(error.NonExistentClass, kotlin.reflect.KProperty<?>)
public static final int getValue(T, @org.jetbrains.annotations.NotNull() kotlin.reflect.KProperty<?>);// getValue(T, kotlin.reflect.KProperty<?>)
public static final void setCounter(int);// setCounter(int)
@@ -170,7 +170,7 @@ public final class PropertiesKt /* PropertiesKt*/ {
public static final void setStringRepresentation(@org.jetbrains.annotations.NotNull() java.lang.String);// setStringRepresentation(java.lang.String)
public static final void setSubject(error.NonExistentClass);// setSubject(error.NonExistentClass)
public static final void setSubject(Unresolved);// setSubject(Unresolved)
public static final void setValue(error.NonExistentClass, @org.jetbrains.annotations.NotNull() kotlin.reflect.KProperty<?>, int);// setValue(error.NonExistentClass, kotlin.reflect.KProperty<?>, int)
public static final void setValue(T, @org.jetbrains.annotations.NotNull() kotlin.reflect.KProperty<?>, int);// setValue(T, kotlin.reflect.KProperty<?>, int)
}
@@ -2,17 +2,17 @@ public final class SimpleFunctionsKt /* SimpleFunctionsKt*/ {
@org.jetbrains.annotations.NotNull()
public static final native java.lang.String externalFun(int);// externalFun(int)
private static final /* vararg */ java.lang.String bar3(error.NonExistentClass, @org.jetbrains.annotations.NotNull() error.NonExistentClass...);// bar3(error.NonExistentClass, error.NonExistentClass[])
private static final /* vararg */ java.lang.String bar3(Foo.Inner, @org.jetbrains.annotations.NotNull() Inner...);// bar3(Foo.Inner, Inner[])
public static final /* vararg */ void nullableVararg(@org.jetbrains.annotations.NotNull() java.lang.Object...);// nullableVararg(java.lang.Object[])
public static final error.NonExistentClass onString(@org.jetbrains.annotations.NotNull() java.lang.String, @org.jetbrains.annotations.NotNull() kotlin.jvm.functions.Function1<? super java.lang.Integer, ? extends java.lang.Object>);// onString(java.lang.String, kotlin.jvm.functions.Function1<? super java.lang.Integer, ? extends java.lang.Object>)
public static final Foo onString(@org.jetbrains.annotations.NotNull() java.lang.String, @org.jetbrains.annotations.NotNull() kotlin.jvm.functions.Function1<? super java.lang.Integer, ? extends java.lang.Object>);// onString(java.lang.String, kotlin.jvm.functions.Function1<? super java.lang.Integer, ? extends java.lang.Object>)
public static final error.NonExistentClass plus(int);// plus(int)
public static final Foo plus(int);// plus(int)
public static final int bar4();// bar4()
public static final void bar(int, @org.jetbrains.annotations.NotNull() java.lang.Object, error.NonExistentClass);// bar(int, java.lang.Object, error.NonExistentClass)
public static final void bar(int, @org.jetbrains.annotations.NotNull() java.lang.Object, Foo);// bar(int, java.lang.Object, Foo)
public static final void bar2(error.NonExistentClass, error.NonExistentClass);// bar2(error.NonExistentClass, error.NonExistentClass)
public static final void bar2(error.NonExistentClass, Unresolved);// bar2(error.NonExistentClass, Unresolved)
}
@@ -6,7 +6,7 @@ public enum Foo /* Foo*/ {
public final int getX();// getX()
}
public final class InlineInheritance /* InlineInheritance*/ {
public final class InlineInheritance /* InlineInheritance*/ implements I {
private final int v;
@java.lang.Override()
@@ -16,7 +16,7 @@ public final class Foo /* Foo*/ {
public final int bar4();// bar4()
public final void bar2$light_idea_test_case(error.NonExistentClass, error.NonExistentClass);// bar2$light_idea_test_case(error.NonExistentClass, error.NonExistentClass)
public final void bar2$light_idea_test_case(error.NonExistentClass, Unresolved);// bar2$light_idea_test_case(error.NonExistentClass, Unresolved)
public void bar(int, @org.jetbrains.annotations.NotNull() java.lang.Object, @org.jetbrains.annotations.NotNull() Foo);// bar(int, java.lang.Object, Foo)
@@ -78,4 +78,6 @@ interface TypeSystemCommonBackendContextForTypeMapping : TypeSystemCommonBackend
fun continuationTypeConstructor(): TypeConstructorMarker
fun functionNTypeConstructor(n: Int): TypeConstructorMarker
fun KotlinTypeMarker.getNameForErrorType(): String?
}