[Test] Implement handler which dumps overrides tree of specified classes
This commit is contained in:
committed by
TeamCityServer
parent
4299794de2
commit
523d37b0f5
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -37,7 +36,10 @@ class FirAnalyzerFacade(
|
||||
val useLightTree: Boolean = false
|
||||
) {
|
||||
private var firFiles: List<FirFile>? = null
|
||||
private var scopeSession: ScopeSession? = null
|
||||
private var _scopeSession: ScopeSession? = null
|
||||
val scopeSession: ScopeSession
|
||||
get() = _scopeSession!!
|
||||
|
||||
private var collectedDiagnostics: Map<FirFile, List<FirDiagnostic<*>>>? = null
|
||||
|
||||
private fun buildRawFir() {
|
||||
@@ -62,16 +64,16 @@ class FirAnalyzerFacade(
|
||||
|
||||
fun runResolution(): List<FirFile> {
|
||||
if (firFiles == null) buildRawFir()
|
||||
if (scopeSession != null) return firFiles!!
|
||||
if (_scopeSession != null) return firFiles!!
|
||||
val resolveProcessor = FirTotalResolveProcessor(session)
|
||||
resolveProcessor.process(firFiles!!)
|
||||
scopeSession = resolveProcessor.scopeSession
|
||||
_scopeSession = resolveProcessor.scopeSession
|
||||
return firFiles!!
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun runCheckers(): Map<FirFile, List<FirDiagnostic<*>>> {
|
||||
if (scopeSession == null) runResolution()
|
||||
if (_scopeSession == null) runResolution()
|
||||
if (collectedDiagnostics != null) return collectedDiagnostics!!
|
||||
val collector = FirDiagnosticsCollector.create(session)
|
||||
collectedDiagnostics = buildMap {
|
||||
@@ -83,11 +85,11 @@ class FirAnalyzerFacade(
|
||||
}
|
||||
|
||||
fun convertToIr(extensions: GeneratorExtensions): Fir2IrResult {
|
||||
if (scopeSession == null) runResolution()
|
||||
if (_scopeSession == null) runResolution()
|
||||
val signaturer = JvmIdSignatureDescriptor(JvmManglerDesc())
|
||||
|
||||
return Fir2IrConverter.createModuleFragment(
|
||||
session, scopeSession!!, firFiles!!,
|
||||
session, _scopeSession!!, firFiles!!,
|
||||
languageVersionSettings, signaturer,
|
||||
extensions, FirJvmKotlinMangler(session), IrFactoryImpl,
|
||||
FirJvmVisibilityConverter,
|
||||
|
||||
@@ -54,6 +54,8 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
val renderCallableFqNames: Boolean,
|
||||
val renderDeclarationResolvePhase: Boolean,
|
||||
val renderAnnotation: Boolean,
|
||||
val renderBodies: Boolean = true,
|
||||
val renderPropertyAccessors: Boolean = true,
|
||||
) {
|
||||
object Normal : RenderMode(
|
||||
renderLambdaBodies = true,
|
||||
@@ -86,6 +88,16 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
renderDeclarationResolvePhase = true,
|
||||
renderAnnotation = true,
|
||||
)
|
||||
|
||||
object NoBodies : RenderMode(
|
||||
renderLambdaBodies = false,
|
||||
renderCallArguments = false,
|
||||
renderCallableFqNames = false,
|
||||
renderDeclarationResolvePhase = false,
|
||||
renderAnnotation = false,
|
||||
renderBodies = false,
|
||||
renderPropertyAccessors = false,
|
||||
)
|
||||
}
|
||||
|
||||
private val printer = Printer(builder)
|
||||
@@ -442,6 +454,7 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
override fun visitProperty(property: FirProperty) {
|
||||
visitVariable(property)
|
||||
if (property.isLocal) return
|
||||
if (!mode.renderPropertyAccessors) return
|
||||
println()
|
||||
pushIndent()
|
||||
property.getter?.accept(this)
|
||||
@@ -543,14 +556,17 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
anonymousInitializer.body?.renderBody()
|
||||
}
|
||||
|
||||
private fun FirBlock.renderBody(additionalStatements: List<FirStatement> = emptyList()) = when (this) {
|
||||
is FirLazyBlock -> {
|
||||
println(" { LAZY_BLOCK }")
|
||||
}
|
||||
else -> renderInBraces {
|
||||
for (statement in additionalStatements + statements) {
|
||||
statement.accept(this@FirRenderer)
|
||||
println()
|
||||
private fun FirBlock.renderBody(additionalStatements: List<FirStatement> = emptyList()) {
|
||||
if (!mode.renderBodies) return
|
||||
when (this) {
|
||||
is FirLazyBlock -> {
|
||||
println(" { LAZY_BLOCK }")
|
||||
}
|
||||
else -> renderInBraces {
|
||||
for (statement in additionalStatements + statements) {
|
||||
statement.accept(this@FirRenderer)
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
sealed class FirDeclarationOrigin(val fromSupertypes: Boolean = false) {
|
||||
sealed class FirDeclarationOrigin(private val displayName: String? = null, val fromSupertypes: Boolean = false) {
|
||||
object Source : FirDeclarationOrigin()
|
||||
object Library : FirDeclarationOrigin()
|
||||
object BuiltIns : FirDeclarationOrigin()
|
||||
@@ -18,7 +18,11 @@ sealed class FirDeclarationOrigin(val fromSupertypes: Boolean = false) {
|
||||
object IntersectionOverride : FirDeclarationOrigin(fromSupertypes = true)
|
||||
object Delegated : FirDeclarationOrigin()
|
||||
|
||||
class Plugin(val key: FirPluginKey) : FirDeclarationOrigin()
|
||||
class Plugin(val key: FirPluginKey) : FirDeclarationOrigin(displayName = "Plugin[$key]")
|
||||
|
||||
override fun toString(): String {
|
||||
return displayName ?: this::class.simpleName!!
|
||||
}
|
||||
}
|
||||
|
||||
abstract class FirPluginKey
|
||||
|
||||
Reference in New Issue
Block a user