FirRenderer: add renderAllModifiers and renderDetailedTypeReferences

Related to KT-52020
This commit is contained in:
Mikhail Glukhikh
2022-06-24 10:21:21 +02:00
committed by Space
parent b2a9ad079d
commit 31ec10142b
16 changed files with 83 additions and 66 deletions
@@ -9,20 +9,24 @@ import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
fun ConeKotlinType.render(): String {
fun ConeKotlinType.render(renderFqNames: Boolean = true): String {
val nullabilitySuffix = if (this !is ConeFlexibleType && this !is ConeErrorType) nullability.suffix else ""
return when (this) {
is ConeTypeVariableType -> "${renderAttributes()}TypeVariable(${this.lookupTag.name})"
is ConeDefinitelyNotNullType -> "${original.render()} & Any"
is ConeDefinitelyNotNullType -> "${original.render(renderFqNames)} & Any"
is ConeErrorType -> "${renderAttributes()}ERROR CLASS: ${diagnostic.reason}"
is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render()})"
is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render(renderFqNames)})"
is ConeClassLikeType -> {
buildString {
append(renderAttributes())
append(lookupTag.classId.asString())
if (renderFqNames) {
append(lookupTag.classId.asString())
} else {
append(lookupTag.classId.relativeClassName.asString())
}
if (typeArguments.isNotEmpty()) {
append(typeArguments.joinToString(prefix = "<", postfix = ">") {
it.render()
it.render(renderFqNames)
})
}
}
@@ -31,13 +35,15 @@ fun ConeKotlinType.render(): String {
"${renderAttributes()}${lookupTag.name.asString()}"
}
is ConeDynamicType -> "dynamic"
is ConeFlexibleType -> this.render()
is ConeFlexibleType -> this.render(renderFqNames)
is ConeIntersectionType -> {
intersectedTypes.joinToString(
separator = " & ",
prefix = "${renderAttributes()}it(",
postfix = ")"
)
) {
it.render(renderFqNames)
}
}
is ConeStubTypeForSyntheticFixation -> "${renderAttributes()}Stub (fixation): ${constructor.variable}"
is ConeStubTypeForChainInference -> "${renderAttributes()}Stub (chain inference): ${constructor.variable}"
@@ -47,12 +53,12 @@ fun ConeKotlinType.render(): String {
} + nullabilitySuffix
}
private fun ConeFlexibleType.render(): String =
private fun ConeFlexibleType.render(renderFqNames: Boolean): String =
buildString {
append("ft<")
append(lowerBound.render())
append(lowerBound.render(renderFqNames))
append(", ")
append(upperBound.render())
append(upperBound.render(renderFqNames))
append(">")
}
@@ -61,18 +67,18 @@ private fun ConeKotlinType.renderAttributes(): String {
return attributes.joinToString(" ", postfix = " ") { it.toString() }
}
fun ConeTypeProjection.render(): String {
fun ConeTypeProjection.render(renderFqNames: Boolean): String {
return when (this) {
ConeStarProjection -> "*"
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render()}"
is ConeKotlinTypeProjectionIn -> "in ${type.render()}"
is ConeKotlinTypeProjectionOut -> "out ${type.render()}"
is ConeKotlinType -> render()
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render(renderFqNames)}"
is ConeKotlinTypeProjectionIn -> "in ${type.render(renderFqNames)}"
is ConeKotlinTypeProjectionOut -> "out ${type.render(renderFqNames)}"
is ConeKotlinType -> render(renderFqNames)
}
}
fun ConeKotlinType.renderFunctionType(
kind: FunctionClassKind?, renderType: ConeTypeProjection.() -> String = { render() }
kind: FunctionClassKind?, renderFqNames: Boolean, renderType: ConeTypeProjection.() -> String = { render(renderFqNames) }
): String {
if (!kind.withPrettyRender()) return renderType()