Skip to content

Commit

Permalink
[Test] Render isPublicApi attribute in AA tests
Browse files Browse the repository at this point in the history
^KT-74040

(cherry picked from commit 279d373)
  • Loading branch information
demiurg906 authored and Space Team committed Jan 15, 2025
1 parent eb8beaf commit c49acfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols.SymbolTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols.SymbolTestDirectives.DO_NOT_CHECK_SYMBOL_RESTORE_K1
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols.SymbolTestDirectives.DO_NOT_CHECK_SYMBOL_RESTORE_K2
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols.SymbolTestDirectives.PRETTY_RENDERER_OPTION
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols.SymbolTestDirectives.RENDER_IS_PUBLIC_API
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KaDeclarationRenderer
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KaDeclarationRendererForDebug
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.KaClassifierBodyRenderer
Expand Down Expand Up @@ -330,8 +331,12 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiBasedTest() {
}

protected open fun KaSession.renderSymbolForComparison(symbol: KaSymbol, directives: RegisteredDirectives): String {
val renderExpandedTypes = directives[PRETTY_RENDERER_OPTION].any { it == PrettyRendererOption.FULLY_EXPANDED_TYPES }
return with(DebugSymbolRenderer(renderExtra = true, renderExpandedTypes = renderExpandedTypes)) { render(useSiteSession, symbol) }
val renderer = DebugSymbolRenderer(
renderExtra = true,
renderExpandedTypes = directives[PRETTY_RENDERER_OPTION].any { it == PrettyRendererOption.FULLY_EXPANDED_TYPES },
renderIsPublicApi = RENDER_IS_PUBLIC_API in directives
)
return with(renderer) { render(useSiteSession, symbol) }
}
}

Expand Down Expand Up @@ -363,6 +368,8 @@ object SymbolTestDirectives : SimpleDirectivesContainer() {
val PRETTY_RENDERER_OPTION by enumDirective(description = "Explicit rendering mode") { PrettyRendererOption.valueOf(it) }

val TARGET_FILE_NAME by stringDirective(description = "The name of the main file")

val RENDER_IS_PUBLIC_API by directive(description = "Render `isPublicApi` attribute for symbols")
}

enum class PrettyRendererOption(val transformation: (KaDeclarationRenderer) -> KaDeclarationRenderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DebugSymbolRenderer(
public val renderExtra: Boolean = false,
public val renderTypeByProperties: Boolean = false,
public val renderExpandedTypes: Boolean = false,
public val renderIsPublicApi: Boolean = false,
) {

public fun render(analysisSession: KaSession, symbol: KaSymbol): String = prettyPrint {
Expand Down Expand Up @@ -99,6 +100,12 @@ public class DebugSymbolRenderer(
renderComputedValue("javaSetterName", printer, currentSymbolStack) { symbol.javaSetterName }
renderComputedValue("setterDeprecationStatus", printer, currentSymbolStack) { symbol.setterDeprecationStatus }
}

if (renderIsPublicApi) {
if (symbol is KaDeclarationSymbol) {
renderComputedValue("isPublicApi", printer, currentSymbolStack) { isPublicApi(symbol) }
}
}
}
} finally {
currentSymbolStack -= symbol
Expand Down Expand Up @@ -516,4 +523,4 @@ public class DebugSymbolRenderer(
}

private val PrettyPrinter.printer: PrettyPrinter
get() = this
get() = this

0 comments on commit c49acfb

Please sign in to comment.