From 9f33d0147cde34230bdc9687c9b3eb0b24d5e3cb Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 6 Aug 2020 15:39:30 +0300 Subject: [PATCH] FIR IDE: add info about nullability to KtType --- .../kotlin/idea/frontend/api/types/KtType.kt | 16 ++++++++++++++-- .../idea/frontend/api/fir/types/FirKtType.kt | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/types/KtType.kt b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/types/KtType.kt index 58795f5619e..392f9108aca 100644 --- a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/types/KtType.kt +++ b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/types/KtType.kt @@ -19,11 +19,23 @@ interface KtType : ValidityTokenOwner { fun asStringForDebugging(): String } +interface KtTypeWithNullability : KtType { + val nullability: KtTypeNullability +} + +enum class KtTypeNullability { + NULLABLE, NON_NULLABLE; + + companion object { + fun create(isNullable: Boolean) = if (isNullable) NULLABLE else NON_NULLABLE + } +} + sealed class KtDenotableType : KtType { abstract fun asString(): String } -abstract class KtClassType : KtDenotableType() { +abstract class KtClassType : KtDenotableType(), KtTypeWithNullability { abstract val classId: ClassId abstract val classSymbol: KtClassLikeSymbol abstract val typeArguments: List @@ -33,7 +45,7 @@ abstract class KtErrorType : KtType { abstract val error: String } -abstract class KtTypeParameterType : KtDenotableType() { +abstract class KtTypeParameterType : KtDenotableType(), KtTypeWithNullability { abstract val name: Name abstract val symbol: KtTypeParameterSymbol } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/types/FirKtType.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/types/FirKtType.kt index 0fe8cb193ba..6fd33f8a99c 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/types/FirKtType.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/types/FirKtType.kt @@ -65,6 +65,7 @@ internal class KtFirClassType( firBuilder.buildTypeArgument(typeArgument) } } + override val nullability: KtTypeNullability get() = withValidityAssertion { KtTypeNullability.create(coneType.isNullable) } override fun asString(): String = withValidityAssertion { coneType.render() //todo @@ -97,6 +98,8 @@ internal class KtFirTypeParameterType( ?: error("Type parameter ${coneType.lookupTag} was not found") } + override val nullability: KtTypeNullability get() = withValidityAssertion { KtTypeNullability.create(coneType.isNullable) } + override fun asString(): String = withValidityAssertion { coneType.render() //todo }