[FIR] Add string representation for ConeKotlinType
`ConeKotlinType.render` moved from `tree` module to `types` module
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6c26fc1943
commit
43e7f54fae
@@ -64,6 +64,10 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), ConeTypedProjection, K
|
|||||||
get() = this
|
get() = this
|
||||||
|
|
||||||
abstract val nullability: ConeNullability
|
abstract val nullability: ConeNullability
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return render()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ConeKotlinType.isNullable: Boolean get() = nullability != ConeNullability.NOT_NULL
|
val ConeKotlinType.isNullable: Boolean get() = nullability != ConeNullability.NOT_NULL
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.types
|
||||||
|
|
||||||
|
fun ConeKotlinType.render(): String {
|
||||||
|
return when (this) {
|
||||||
|
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})"
|
||||||
|
is ConeDefinitelyNotNullType -> "${original.render()}!"
|
||||||
|
is ConeClassErrorType -> "class error: $reason"
|
||||||
|
is ConeCapturedType -> "captured type: lowerType = ${lowerType?.render()}"
|
||||||
|
is ConeClassLikeType -> {
|
||||||
|
buildString {
|
||||||
|
append(lookupTag.classId.asString())
|
||||||
|
if (typeArguments.isNotEmpty()) {
|
||||||
|
append(typeArguments.joinToString(prefix = "<", postfix = ">") {
|
||||||
|
when (it) {
|
||||||
|
ConeStarProjection -> "*"
|
||||||
|
is ConeKotlinTypeProjectionIn -> "in ${it.type.render()}"
|
||||||
|
is ConeKotlinTypeProjectionOut -> "out ${it.type.render()}"
|
||||||
|
is ConeKotlinType -> it.render()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ConeTypeParameterType -> {
|
||||||
|
lookupTag.name.asString()
|
||||||
|
}
|
||||||
|
is ConeFlexibleType -> {
|
||||||
|
buildString {
|
||||||
|
append("ft<")
|
||||||
|
append(lowerBound.render())
|
||||||
|
append(lowerBound.nullability.suffix)
|
||||||
|
append(", ")
|
||||||
|
append(upperBound.render())
|
||||||
|
append(upperBound.nullability.suffix)
|
||||||
|
append(">")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
|||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.*
|
import org.jetbrains.kotlin.fir.types.impl.*
|
||||||
|
import org.jetbrains.kotlin.fir.types.render
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
|
|||||||
@@ -37,45 +37,6 @@ fun FirElement.renderWithType(): String = buildString {
|
|||||||
|
|
||||||
fun FirElement.render(): String = buildString { this@render.accept(FirRenderer(this)) }
|
fun FirElement.render(): String = buildString { this@render.accept(FirRenderer(this)) }
|
||||||
|
|
||||||
|
|
||||||
fun ConeKotlinType.render(): String {
|
|
||||||
return when (this) {
|
|
||||||
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})"
|
|
||||||
is ConeDefinitelyNotNullType -> "${original.render()}!"
|
|
||||||
is ConeClassErrorType -> "class error: $reason"
|
|
||||||
is ConeCapturedType -> "captured type: lowerType = ${lowerType?.render()}"
|
|
||||||
is ConeClassLikeType -> {
|
|
||||||
val sb = StringBuilder()
|
|
||||||
sb.append(lookupTag.classId.asString())
|
|
||||||
if (typeArguments.isNotEmpty()) {
|
|
||||||
sb.append(typeArguments.joinToString(prefix = "<", postfix = ">") {
|
|
||||||
when (it) {
|
|
||||||
ConeStarProjection -> "*"
|
|
||||||
is ConeKotlinTypeProjectionIn -> "in ${it.type.render()}"
|
|
||||||
is ConeKotlinTypeProjectionOut -> "out ${it.type.render()}"
|
|
||||||
is ConeKotlinType -> it.render()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
sb.toString()
|
|
||||||
}
|
|
||||||
is ConeTypeParameterType -> {
|
|
||||||
lookupTag.name.asString()
|
|
||||||
}
|
|
||||||
is ConeFlexibleType -> {
|
|
||||||
buildString {
|
|
||||||
append("ft<")
|
|
||||||
append(lowerBound.render())
|
|
||||||
append(lowerBound.nullability.suffix)
|
|
||||||
append(", ")
|
|
||||||
append(upperBound.render())
|
|
||||||
append(upperBound.nullability.suffix)
|
|
||||||
append(">")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
||||||
private val printer = Printer(builder)
|
private val printer = Printer(builder)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user