[Analysis API FIR] tests: add ability to ignore specific scope kind in TestScopeRenderer
^KT-57966
This commit is contained in:
committed by
Space Team
parent
349e55cb00
commit
254092a267
+4
-1
@@ -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.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.components.KtScopeContext
|
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.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.base.AbstractAnalysisApiBasedSingleModuleTest
|
||||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||||
@@ -39,6 +40,8 @@ abstract class AbstractScopeContextForPositionTest : AbstractAnalysisApiBasedSin
|
|||||||
printPretty: Boolean = false
|
printPretty: Boolean = false
|
||||||
): String = prettyPrint {
|
): String = prettyPrint {
|
||||||
appendLine("element: ${element.text}")
|
appendLine("element: ${element.text}")
|
||||||
renderForTests(scopeContext, printPretty)
|
renderForTests(scopeContext, printPretty) { scopeKind ->
|
||||||
|
scopeKind !is KtScopeKind.DefaultSimpleImportingScope && scopeKind !is KtScopeKind.DefaultStarImportingScope
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-6
@@ -25,7 +25,8 @@ internal object TestScopeRenderer {
|
|||||||
context (KtAnalysisSession)
|
context (KtAnalysisSession)
|
||||||
fun PrettyPrinter.renderForTests(
|
fun PrettyPrinter.renderForTests(
|
||||||
scopeContext: KtScopeContext,
|
scopeContext: KtScopeContext,
|
||||||
printPretty: Boolean = false
|
printPretty: Boolean = false,
|
||||||
|
fullyPrintScope: (KtScopeKind) -> Boolean,
|
||||||
) {
|
) {
|
||||||
appendLine("implicit receivers:")
|
appendLine("implicit receivers:")
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ internal object TestScopeRenderer {
|
|||||||
}
|
}
|
||||||
appendLine("scopes:")
|
appendLine("scopes:")
|
||||||
withIndent {
|
withIndent {
|
||||||
renderScopeContext(scopeContext, printPretty)
|
renderScopeContext(scopeContext, printPretty, fullyPrintScope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,18 +59,24 @@ internal object TestScopeRenderer {
|
|||||||
context(KtAnalysisSession)
|
context(KtAnalysisSession)
|
||||||
private fun PrettyPrinter.renderScopeContext(
|
private fun PrettyPrinter.renderScopeContext(
|
||||||
scopeContext: KtScopeContext,
|
scopeContext: KtScopeContext,
|
||||||
printPretty: Boolean
|
printPretty: Boolean,
|
||||||
|
fullyPrintScope: (KtScopeKind) -> Boolean,
|
||||||
) {
|
) {
|
||||||
for (scopeWithKind in scopeContext.scopes) {
|
for (scopeWithKind in scopeContext.scopes) {
|
||||||
appendLine(renderForTests(scopeWithKind.scope, scopeWithKind.kind, printPretty))
|
appendLine(renderForTests(scopeWithKind.scope, scopeWithKind.kind, printPretty, fullyPrintScope))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context (KtAnalysisSession)
|
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}")
|
append("${scopeKind::class.simpleName}, index = ${scopeKind.indexInTower}")
|
||||||
|
|
||||||
if (scopeKind is KtScopeKind.DefaultSimpleImportingScope || scopeKind is KtScopeKind.DefaultStarImportingScope) {
|
if (!fullyPrintScope(scopeKind)) {
|
||||||
appendLine()
|
appendLine()
|
||||||
return@prettyPrint
|
return@prettyPrint
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user