FIR IDE: add helper checking if a type is flexbily nullable
This commit is contained in:
committed by
Ilya Kirillov
parent
68e70769c8
commit
39939c7213
+8
-2
@@ -5,10 +5,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.api.components
|
package org.jetbrains.kotlin.analysis.api.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeAliasSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeAliasSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.types.*
|
import org.jetbrains.kotlin.analysis.api.types.KtFlexibleType
|
||||||
|
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
|
||||||
|
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||||
|
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||||
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
|
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
|
||||||
@@ -34,6 +37,9 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
|||||||
/** Returns true if the type is explicitly marked as nullable. This means it's safe to assign `null` to a variable with this type. */
|
/** Returns true if the type is explicitly marked as nullable. This means it's safe to assign `null` to a variable with this type. */
|
||||||
public val KtType.isMarkedNullable: Boolean get() = this.nullability == KtTypeNullability.NULLABLE
|
public val KtType.isMarkedNullable: Boolean get() = this.nullability == KtTypeNullability.NULLABLE
|
||||||
|
|
||||||
|
/** Returns true if the type is a platform flexible type and may or may not be marked nullable. */
|
||||||
|
public val KtType.hasFlexibleNullability: Boolean get() = this is KtFlexibleType && this.upperBound.isMarkedNullable != this.lowerBound.isMarkedNullable
|
||||||
|
|
||||||
public val KtType.isUnit: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT)
|
public val KtType.isUnit: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT)
|
||||||
public val KtType.isInt: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.INT)
|
public val KtType.isInt: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.INT)
|
||||||
public val KtType.isLong: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.LONG)
|
public val KtType.isLong: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.LONG)
|
||||||
|
|||||||
Reference in New Issue
Block a user