Integrate nullability into cone types, add & use FIR flexible type

FIR fake overrides are rendered now more precisely to test this process
This commit is contained in:
Mikhail Glukhikh
2019-02-11 19:15:37 +03:00
parent 3d77f3d129
commit f8e165dbe4
15 changed files with 137 additions and 30 deletions
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
@@ -53,7 +50,7 @@ class JavaSymbolProvider(
annotationTypeRef = FirResolvedTypeRefImpl(
session = session,
psi = null,
type = ConeClassTypeImpl(FirClassSymbol(classId!!), emptyArray()),
type = ConeClassTypeImpl(FirClassSymbol(classId!!), emptyArray(), isNullable = false),
isMarkedNullable = true,
annotations = emptyList()
)
@@ -87,18 +84,24 @@ class JavaSymbolProvider(
}
}
private fun flexibleType(create: (isNullable: Boolean) -> ConeKotlinType): ConeFlexibleType {
return ConeFlexibleType(create(false), create(true))
}
private fun JavaClassifierType.toFirResolvedTypeRef(): FirResolvedTypeRef {
val coneType = when (val classifier = classifier) {
is JavaClass -> {
val symbol = session.service<FirSymbolProvider>().getClassLikeSymbolByFqName(classifier.classId!!) as? ConeClassSymbol
if (symbol == null) ConeKotlinErrorType("Symbol not found, for `${classifier.classId}`")
else ConeClassTypeImpl(symbol, typeArguments = typeArguments.map { it.toConeProjection() }.toTypedArray())
else flexibleType { isNullable ->
ConeClassTypeImpl(symbol, typeArguments.map { it.toConeProjection() }.toTypedArray(), isNullable)
}
}
is JavaTypeParameter -> {
// TODO: it's unclear how to identify type parameter by the symbol
// TODO: some type parameter cache (provider?)
val symbol = createTypeParameterSymbol(classifier.name)
ConeTypeParameterTypeImpl(symbol)
flexibleType { isNullable -> ConeTypeParameterTypeImpl(symbol, isNullable) }
}
else -> ConeClassErrorType(reason = "Unexpected classifier: $classifier")
}