[Analysis API] implement better rendering for chained KtSubstitutor

This commit is contained in:
Ilya Kirillov
2023-09-20 16:30:46 +02:00
committed by Space Team
parent e2d248b76d
commit 1107e728a2
5 changed files with 38 additions and 3 deletions
@@ -20,4 +20,16 @@ interface KtMapBackedSubstitutor : KtSubstitutor {
* Substitution rules in a form of a `Map<KtTypeParameterSymbol, KtType>`
*/
fun getAsMap(): Map<KtTypeParameterSymbol, KtType>
}
}
/**
* A [KtSubstitutor] which substitution logic can be represented as subsequent invocation of two substitutors [first] and [second]
* This is an implementation detail,
* and Analysis API clients should not depend on the fact if some [KtSubstitutor] is [KtChainedSubstitutor] or not.
*/
@KtAnalysisApiInternals
interface KtChainedSubstitutor : KtSubstitutor {
val first: KtSubstitutor
val second: KtSubstitutor
}
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.calls.KtCall
import org.jetbrains.kotlin.analysis.api.calls.KtCallableMemberCall
import org.jetbrains.kotlin.analysis.api.diagnostics.KtDiagnostic
import org.jetbrains.kotlin.analysis.api.impl.base.KtChainedSubstitutor
import org.jetbrains.kotlin.analysis.api.impl.base.KtMapBackedSubstitutor
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KtDeclarationRendererForSource
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.renderers.KtRendererKeywordFilter
@@ -31,9 +32,10 @@ import kotlin.reflect.KVisibility
import kotlin.reflect.full.memberProperties
@OptIn(KtAnalysisApiInternals::class)
internal fun KtAnalysisSession.stringRepresentation(any: Any): String = with(any) {
internal fun KtAnalysisSession.stringRepresentation(any: Any?): String = with(any) {
fun KtType.render() = asStringForDebugging().replace('/', '.')
return when (this) {
null -> "null"
is KtFunctionLikeSymbol -> buildString {
append(
when (this@with) {
@@ -84,6 +86,7 @@ internal fun KtAnalysisSession.stringRepresentation(any: Any): String = with(any
.joinToString(prefix = "{", postfix = "}") { (k, v) -> stringRepresentation(k) + " = " + v.asStringForDebugging() }
"<map substitutor: $mappingText>"
}
is KtChainedSubstitutor -> "${stringRepresentation(first)} then ${stringRepresentation(second)}"
is KtSubstitutor -> "<complex substitutor>"
is KtDiagnostic -> "$severity<$factoryName: $defaultMessage>"
is KtType -> render()