[Analysis API FIR] tests: add ability to ignore specific scope kind in TestScopeRenderer

^KT-57966
This commit is contained in:
Ilya Kirillov
2023-05-01 12:02:09 +02:00
committed by Space Team
parent 349e55cb00
commit 254092a267
2 changed files with 17 additions and 7 deletions
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.scopeP
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.components.KtScopeContext
import org.jetbrains.kotlin.analysis.api.components.KtScopeKind
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.scopeProvider.TestScopeRenderer.renderForTests
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
@@ -39,6 +40,8 @@ abstract class AbstractScopeContextForPositionTest : AbstractAnalysisApiBasedSin
printPretty: Boolean = false
): String = prettyPrint {
appendLine("element: ${element.text}")
renderForTests(scopeContext, printPretty)
renderForTests(scopeContext, printPretty) { scopeKind ->
scopeKind !is KtScopeKind.DefaultSimpleImportingScope && scopeKind !is KtScopeKind.DefaultStarImportingScope
}
}
}
@@ -25,7 +25,8 @@ internal object TestScopeRenderer {
context (KtAnalysisSession)
fun PrettyPrinter.renderForTests(
scopeContext: KtScopeContext,
printPretty: Boolean = false
printPretty: Boolean = false,
fullyPrintScope: (KtScopeKind) -> Boolean,
) {
appendLine("implicit receivers:")
@@ -39,7 +40,7 @@ internal object TestScopeRenderer {
}
appendLine("scopes:")
withIndent {
renderScopeContext(scopeContext, printPretty)
renderScopeContext(scopeContext, printPretty, fullyPrintScope)
}
}
@@ -58,18 +59,24 @@ internal object TestScopeRenderer {
context(KtAnalysisSession)
private fun PrettyPrinter.renderScopeContext(
scopeContext: KtScopeContext,
printPretty: Boolean
printPretty: Boolean,
fullyPrintScope: (KtScopeKind) -> Boolean,
) {
for (scopeWithKind in scopeContext.scopes) {
appendLine(renderForTests(scopeWithKind.scope, scopeWithKind.kind, printPretty))
appendLine(renderForTests(scopeWithKind.scope, scopeWithKind.kind, printPretty, fullyPrintScope))
}
}
context (KtAnalysisSession)
private fun renderForTests(scope: KtScope, scopeKind: KtScopeKind, printPretty: Boolean): String = prettyPrint {
private fun renderForTests(
scope: KtScope,
scopeKind: KtScopeKind,
printPretty: Boolean,
fullyPrintScope: (KtScopeKind) -> Boolean,
): String = prettyPrint {
append("${scopeKind::class.simpleName}, index = ${scopeKind.indexInTower}")
if (scopeKind is KtScopeKind.DefaultSimpleImportingScope || scopeKind is KtScopeKind.DefaultStarImportingScope) {
if (!fullyPrintScope(scopeKind)) {
appendLine()
return@prettyPrint
}