Analysis API: introduce KtIntegerLiteralType
This commit is contained in:
committed by
TeamCityServer
parent
30b1487afc
commit
5c3ce67648
+1
@@ -359,6 +359,7 @@ internal class KtSymbolByFirBuilder private constructor(
|
|||||||
is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder)
|
is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder)
|
||||||
is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder)
|
is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder)
|
||||||
is ConeCapturedType -> KtFirCapturedType(coneType, token)
|
is ConeCapturedType -> KtFirCapturedType(coneType, token)
|
||||||
|
is ConeIntegerLiteralType -> KtFirIntegerLiteralType(coneType, token, this@KtSymbolByFirBuilder)
|
||||||
else -> throwUnexpectedElementError(coneType)
|
else -> throwUnexpectedElementError(coneType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -200,6 +200,28 @@ internal class KtFirIntersectionType(
|
|||||||
override fun hashCode() = typeHashcode()
|
override fun hashCode() = typeHashcode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class KtFirIntegerLiteralType(
|
||||||
|
override val coneType: ConeIntegerLiteralType,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
private val builder: KtSymbolByFirBuilder,
|
||||||
|
) : KtIntegerLiteralType(), KtFirType {
|
||||||
|
override val isUnsigned: Boolean get() = withValidityAssertion { coneType.isUnsigned }
|
||||||
|
|
||||||
|
override val value: Long get() = withValidityAssertion { coneType.value }
|
||||||
|
|
||||||
|
override val possibleTypes: List<KtClassType> by cached {
|
||||||
|
coneType.possibleTypes.map { possibleType ->
|
||||||
|
builder.typeBuilder.buildKtType(possibleType) as KtClassType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val nullability: KtTypeNullability get() = withValidityAssertion { coneType.nullability.asKtNullability() }
|
||||||
|
|
||||||
|
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
||||||
|
override fun equals(other: Any?) = typeEquals(other)
|
||||||
|
override fun hashCode() = typeHashcode()
|
||||||
|
}
|
||||||
|
|
||||||
private fun ConeNullability.asKtNullability(): KtTypeNullability = when (this) {
|
private fun ConeNullability.asKtNullability(): KtTypeNullability = when (this) {
|
||||||
ConeNullability.NULLABLE -> KtTypeNullability.NULLABLE
|
ConeNullability.NULLABLE -> KtTypeNullability.NULLABLE
|
||||||
ConeNullability.UNKNOWN -> KtTypeNullability.UNKNOWN
|
ConeNullability.UNKNOWN -> KtTypeNullability.UNKNOWN
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.analysis.api.KtTypeArgument
|
|||||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeNullability
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
@@ -80,5 +82,30 @@ public abstract class KtFlexibleType : KtType {
|
|||||||
public abstract class KtIntersectionType : KtType {
|
public abstract class KtIntersectionType : KtType {
|
||||||
public abstract val conjuncts: List<KtType>
|
public abstract val conjuncts: List<KtType>
|
||||||
|
|
||||||
|
override fun toString(): String = asStringForDebugging()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-denotable type representing some number type. This type generally come when retrieving some integer literal `KtType`
|
||||||
|
* It is unknown which number type it exactly is, but possible options based on [value] can be retrieved via [possibleTypes].
|
||||||
|
*/
|
||||||
|
public abstract class KtIntegerLiteralType : KtType {
|
||||||
|
/**
|
||||||
|
* Literal value for which the type was created.
|
||||||
|
*/
|
||||||
|
public abstract val value: Long
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the type unsigned (i.e. corresponding literal had `u` suffix)
|
||||||
|
*/
|
||||||
|
public abstract val isUnsigned: Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of `Number` types the type may be represented as.
|
||||||
|
*
|
||||||
|
* The possible options are: `Byte`, `Short` ,`Int`, `Long`, `UByte`, `UShort` `UInt`, `ULong`
|
||||||
|
*/
|
||||||
|
public abstract val possibleTypes: Collection<KtClassType>
|
||||||
|
|
||||||
override fun toString(): String = asStringForDebugging()
|
override fun toString(): String = asStringForDebugging()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user