[FIR] get rid of FirFileAnnotationsContainer

This element has been introduced to simplify resolution logic in LL FIR,
but now this element is redundant and only complicates the code as after
KT-56683 `FirFile` has real phases

^KT-65876 Fixed
This commit is contained in:
Dmitrii Gridin
2024-02-20 00:38:31 +01:00
committed by Space Team
parent 24c91bbf56
commit 17c128adf2
55 changed files with 109 additions and 484 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.builtins.StandardNames.DATA_CLASS_COMPONENT_PREFIX
import org.jetbrains.kotlin.descriptors.ValueClassRepresentation
import org.jetbrains.kotlin.diagnostics.startOffsetSkippingComments
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.builder.buildFileAnnotationsContainer
import org.jetbrains.kotlin.fir.builder.buildPackageDirective
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildFile
@@ -698,11 +697,6 @@ fun FirSession.createFilesWithGeneratedDeclarations(): List<FirFile> {
return buildList {
for (packageFqName in (topLevelClasses.keys + topLevelCallables.keys)) {
this += buildFile {
symbol = FirFileSymbol()
annotationsContainer = buildFileAnnotationsContainer {
moduleData = this@createFilesWithGeneratedDeclarations.moduleData
containingFileSymbol = this@buildFile.symbol
}
origin = FirDeclarationOrigin.Synthetic.PluginFile
moduleData = this@createFilesWithGeneratedDeclarations.moduleData
packageDirective = buildPackageDirective {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -76,7 +76,7 @@ class LightTreeRawFirDeclarationBuilder(
}
val fileSymbol = FirFileSymbol()
var fileAnnotationContainer: FirFileAnnotationsContainer? = null
var fileAnnotations = mutableListOf<FirAnnotation>()
val importList = mutableListOf<FirImport>()
val firDeclarationList = mutableListOf<FirDeclaration>()
val modifierList = mutableListOf<LighterASTNode>()
@@ -84,7 +84,11 @@ class LightTreeRawFirDeclarationBuilder(
var packageDirective: FirPackageDirective? = null
file.forEachChildren { child ->
when (child.tokenType) {
FILE_ANNOTATION_LIST -> fileAnnotationContainer = convertFileAnnotationsContainer(child, fileSymbol)
FILE_ANNOTATION_LIST -> {
withContainerSymbol(fileSymbol) {
fileAnnotations += convertAnnotationList(child)
}
}
PACKAGE_DIRECTIVE -> {
packageDirective = convertPackageDirective(child).also { context.packageFqName = it.packageFqName }
}
@@ -115,7 +119,7 @@ class LightTreeRawFirDeclarationBuilder(
this.sourceFile = sourceFile
this.sourceFileLinesMapping = linesMapping
this.packageDirective = packageDirective ?: buildPackageDirective { packageFqName = context.packageFqName }
annotationsContainer = fileAnnotationContainer
annotations += fileAnnotations
imports += importList
declarations += firDeclarationList
}
@@ -316,26 +320,6 @@ class LightTreeRawFirDeclarationBuilder(
}
/***** ANNOTATIONS *****/
/**
* [org.jetbrains.kotlin.parsing.KotlinParsing.parseFileAnnotationList]
*/
private fun convertFileAnnotationsContainer(
fileAnnotationList: LighterASTNode,
fileSymbol: FirFileSymbol
): FirFileAnnotationsContainer {
return buildFileAnnotationsContainer {
moduleData = baseModuleData
source = fileAnnotationList.toFirSourceElement()
containingFileSymbol = fileSymbol
withContainerSymbol(fileSymbol) {
annotations += convertAnnotationList(fileAnnotationList)
}
annotations.ifEmpty {
resolvePhase = FirResolvePhase.BODY_RESOLVE
}
}
}
/**
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseAnnotationOrList
@@ -1183,7 +1183,6 @@ open class PsiRawFirBuilder(
BodyBuildingMode.LAZY_BODIES -> file.packageFqName
}
return buildFile {
symbol = FirFileSymbol()
source = file.toFirSourceElement()
moduleData = baseModuleData
origin = FirDeclarationOrigin.Source
@@ -1194,19 +1193,11 @@ open class PsiRawFirBuilder(
packageFqName = context.packageFqName
source = file.packageDirective?.toKtPsiSourceElement()
}
annotationsContainer = file.fileAnnotationList?.let {
buildFileAnnotationsContainer {
moduleData = baseModuleData
containingFileSymbol = this@buildFile.symbol
source = it.toKtPsiSourceElement()
withContainerSymbol(containingFileSymbol) {
for (annotationEntry in it.annotationEntries) {
annotations += annotationEntry.convert<FirAnnotation>()
}
}
annotations.ifEmpty {
resolvePhase = FirResolvePhase.BODY_RESOLVE
file.fileAnnotationList?.let {
withContainerSymbol(symbol) {
for (annotationEntry in it.annotationEntries) {
annotations += annotationEntry.convert<FirAnnotation>()
}
}
}
@@ -457,15 +457,6 @@ abstract class FirAbstractBodyResolveTransformerDispatcher(
FirDeclarationsResolveTransformer::transformDanglingModifierList,
)
override fun transformFileAnnotationsContainer(
fileAnnotationsContainer: FirFileAnnotationsContainer,
data: ResolutionMode,
): FirFileAnnotationsContainer = declarationTransformation(
fileAnnotationsContainer,
data,
FirDeclarationsResolveTransformer::transformFileAnnotationsContainer,
)
override fun transformProperty(
property: FirProperty,
data: ResolutionMode,
@@ -125,16 +125,6 @@ open class FirDeclarationsResolveTransformer(
return danglingModifierList
}
override fun transformFileAnnotationsContainer(
fileAnnotationsContainer: FirFileAnnotationsContainer,
data: ResolutionMode
): FirFileAnnotationsContainer {
if (implicitTypeOnly) return fileAnnotationsContainer
fileAnnotationsContainer.transformAnnotations(transformer, data)
return fileAnnotationsContainer
}
override fun transformProperty(property: FirProperty, data: ResolutionMode): FirProperty = whileAnalysing(session, property) {
require(property !is FirSyntheticProperty) { "Synthetic properties should not be processed by body transformers" }
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.fir.resolve.transformers.contracts
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.contracts.FirLegacyRawContractDescription
import org.jetbrains.kotlin.fir.contracts.FirRawContractDescription
@@ -327,13 +326,6 @@ abstract class FirAbstractContractResolveTransformerDispatcher(
return danglingModifierList
}
override fun transformFileAnnotationsContainer(
fileAnnotationsContainer: FirFileAnnotationsContainer,
data: ResolutionMode
): FirFileAnnotationsContainer {
return fileAnnotationsContainer
}
override fun transformErrorPrimaryConstructor(
errorPrimaryConstructor: FirErrorPrimaryConstructor,
data: ResolutionMode,
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// This file was generated automatically. See compiler/fir/tree/tree-generator/Readme.md.
// DO NOT MODIFY IT MANUALLY.
package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.symbols.impl.FirFileSymbol
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
/**
* Generated from: [org.jetbrains.kotlin.fir.tree.generator.FirTreeBuilder.fileAnnotationsContainer]
*/
abstract class FirFileAnnotationsContainer : FirElementWithResolveState(), FirAnnotationContainer {
abstract override val source: KtSourceElement?
abstract override val moduleData: FirModuleData
abstract override val annotations: List<FirAnnotation>
abstract val containingFileSymbol: FirFileSymbol
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitFileAnnotationsContainer(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E : FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformFileAnnotationsContainer(this, data) as E
abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirFileAnnotationsContainer
}
@@ -1,48 +0,0 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// This file was generated automatically. See compiler/fir/tree/tree-generator/Readme.md.
// DO NOT MODIFY IT MANUALLY.
@file:Suppress("DuplicatedCode", "unused")
package org.jetbrains.kotlin.fir.builder
import kotlin.contracts.*
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.impl.FirFileAnnotationsContainerImpl
import org.jetbrains.kotlin.fir.symbols.impl.FirFileSymbol
@FirBuilderDsl
class FirFileAnnotationsContainerBuilder : FirAnnotationContainerBuilder {
override var source: KtSourceElement? = null
var resolvePhase: FirResolvePhase = FirResolvePhase.RAW_FIR
lateinit var moduleData: FirModuleData
override val annotations: MutableList<FirAnnotation> = mutableListOf()
lateinit var containingFileSymbol: FirFileSymbol
override fun build(): FirFileAnnotationsContainer {
return FirFileAnnotationsContainerImpl(
source,
resolvePhase,
moduleData,
annotations.toMutableOrEmpty(),
containingFileSymbol,
)
}
}
@OptIn(ExperimentalContracts::class)
inline fun buildFileAnnotationsContainer(init: FirFileAnnotationsContainerBuilder.() -> Unit): FirFileAnnotationsContainer {
contract {
callsInPlace(init, InvocationKind.EXACTLY_ONCE)
}
return FirFileAnnotationsContainerBuilder().apply(init).build()
}
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.KtSourceFile
import org.jetbrains.kotlin.KtSourceFileLinesMapping
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.FirPackageDirective
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
@@ -31,7 +30,6 @@ abstract class FirFile : FirDeclaration(), FirControlFlowGraphOwner {
abstract override val origin: FirDeclarationOrigin
abstract override val attributes: FirDeclarationAttributes
abstract override val controlFlowGraphReference: FirControlFlowGraphReference?
abstract val annotationsContainer: FirFileAnnotationsContainer?
abstract val packageDirective: FirPackageDirective
abstract val imports: List<FirImport>
abstract val declarations: List<FirDeclaration>
@@ -53,8 +51,6 @@ abstract class FirFile : FirDeclaration(), FirControlFlowGraphOwner {
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirFile
abstract fun <D> transformAnnotationsContainer(transformer: FirTransformer<D>, data: D): FirFile
abstract fun <D> transformImports(transformer: FirTransformer<D>, data: D): FirFile
abstract fun <D> transformDeclarations(transformer: FirTransformer<D>, data: D): FirFile
@@ -14,11 +14,11 @@ import kotlin.contracts.*
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.KtSourceFile
import org.jetbrains.kotlin.KtSourceFileLinesMapping
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.FirPackageDirective
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
@@ -28,26 +28,26 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirFileSymbol
class FirFileBuilder : FirAnnotationContainerBuilder {
override var source: KtSourceElement? = null
var resolvePhase: FirResolvePhase = FirResolvePhase.RAW_FIR
override val annotations: MutableList<FirAnnotation> = mutableListOf()
lateinit var moduleData: FirModuleData
lateinit var origin: FirDeclarationOrigin
var attributes: FirDeclarationAttributes = FirDeclarationAttributes()
var annotationsContainer: FirFileAnnotationsContainer? = null
lateinit var packageDirective: FirPackageDirective
val imports: MutableList<FirImport> = mutableListOf()
val declarations: MutableList<FirDeclaration> = mutableListOf()
lateinit var name: String
var sourceFile: KtSourceFile? = null
var sourceFileLinesMapping: KtSourceFileLinesMapping? = null
lateinit var symbol: FirFileSymbol
var symbol: FirFileSymbol = FirFileSymbol()
override fun build(): FirFile {
return FirFileImpl(
source,
resolvePhase,
annotations.toMutableOrEmpty(),
moduleData,
origin,
attributes,
annotationsContainer,
packageDirective,
imports,
declarations,
@@ -58,9 +58,6 @@ class FirFileBuilder : FirAnnotationContainerBuilder {
)
}
@Deprecated("Modification of 'annotations' has no impact for FirFileBuilder", level = DeprecationLevel.HIDDEN)
override val annotations: MutableList<FirAnnotation> = mutableListOf()
}
@OptIn(ExperimentalContracts::class)
@@ -13,9 +13,10 @@ package org.jetbrains.kotlin.fir.declarations.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.KtSourceFile
import org.jetbrains.kotlin.KtSourceFileLinesMapping
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.FirPackageDirective
import org.jetbrains.kotlin.fir.MutableOrEmptyList
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
@@ -28,10 +29,10 @@ import org.jetbrains.kotlin.fir.visitors.transformInplace
internal class FirFileImpl(
override val source: KtSourceElement?,
resolvePhase: FirResolvePhase,
override var annotations: MutableOrEmptyList<FirAnnotation>,
override val moduleData: FirModuleData,
override val origin: FirDeclarationOrigin,
override val attributes: FirDeclarationAttributes,
override var annotationsContainer: FirFileAnnotationsContainer?,
override var packageDirective: FirPackageDirective,
override val imports: MutableList<FirImport>,
override val declarations: MutableList<FirDeclaration>,
@@ -40,8 +41,6 @@ internal class FirFileImpl(
override val sourceFileLinesMapping: KtSourceFileLinesMapping?,
override val symbol: FirFileSymbol,
) : FirFile() {
override val annotations: List<FirAnnotation>
get() = annotationsContainer?.annotations ?: emptyList()
override var controlFlowGraphReference: FirControlFlowGraphReference? = null
init {
@@ -50,16 +49,16 @@ internal class FirFileImpl(
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) }
controlFlowGraphReference?.accept(visitor, data)
annotationsContainer?.accept(visitor, data)
packageDirective.accept(visitor, data)
imports.forEach { it.accept(visitor, data) }
declarations.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirFileImpl {
transformAnnotations(transformer, data)
controlFlowGraphReference = controlFlowGraphReference?.transform(transformer, data)
transformAnnotationsContainer(transformer, data)
packageDirective = packageDirective.transform(transformer, data)
transformImports(transformer, data)
transformDeclarations(transformer, data)
@@ -67,11 +66,7 @@ internal class FirFileImpl(
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirFileImpl {
return this
}
override fun <D> transformAnnotationsContainer(transformer: FirTransformer<D>, data: D): FirFileImpl {
annotationsContainer = annotationsContainer?.transform(transformer, data)
annotations.transformInplace(transformer, data)
return this
}
@@ -85,7 +80,9 @@ internal class FirFileImpl(
return this
}
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {}
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?) {
controlFlowGraphReference = newControlFlowGraphReference
@@ -1,57 +0,0 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// This file was generated automatically. See compiler/fir/tree/tree-generator/Readme.md.
// DO NOT MODIFY IT MANUALLY.
@file:Suppress("DuplicatedCode", "unused")
package org.jetbrains.kotlin.fir.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.MutableOrEmptyList
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.ResolveStateAccess
import org.jetbrains.kotlin.fir.declarations.asResolveState
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.symbols.impl.FirFileSymbol
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.fir.visitors.transformInplace
@OptIn(ResolveStateAccess::class)
internal class FirFileAnnotationsContainerImpl(
override val source: KtSourceElement?,
resolvePhase: FirResolvePhase,
override val moduleData: FirModuleData,
override var annotations: MutableOrEmptyList<FirAnnotation>,
override val containingFileSymbol: FirFileSymbol,
) : FirFileAnnotationsContainer() {
init {
resolveState = resolvePhase.asResolveState()
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirFileAnnotationsContainerImpl {
transformAnnotations(transformer, data)
return this
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirFileAnnotationsContainerImpl {
annotations.transformInplace(transformer, data)
return this
}
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
}
@@ -139,14 +139,6 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformElementWithResolveState(elementWithResolveState, data)
}
open fun transformFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer, data: D): FirFileAnnotationsContainer {
return transformElement(fileAnnotationsContainer, data)
}
final override fun visitFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer, data: D): FirFileAnnotationsContainer {
return transformFileAnnotationsContainer(fileAnnotationsContainer, data)
}
open fun transformDeclaration(declaration: FirDeclaration, data: D): FirDeclaration {
return transformElement(declaration, data)
}
@@ -65,9 +65,6 @@ abstract class FirVisitor<out R, in D> {
open fun visitElementWithResolveState(elementWithResolveState: FirElementWithResolveState, data: D): R =
visitElement(elementWithResolveState, data)
open fun visitFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer, data: D): R =
visitElement(fileAnnotationsContainer, data)
open fun visitDeclaration(declaration: FirDeclaration, data: D): R =
visitElement(declaration, data)
@@ -139,14 +139,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(elementWithResolveState)
}
final override fun visitFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer, data: Nothing?) {
visitFileAnnotationsContainer(fileAnnotationsContainer)
}
open fun visitFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer) {
visitElement(fileAnnotationsContainer)
}
final override fun visitDeclaration(declaration: FirDeclaration, data: Nothing?) {
visitDeclaration(declaration)
}
@@ -1,19 +0,0 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
class FirFileAnnotationsContainerRenderer {
internal lateinit var components: FirRendererComponents
private val printer get() = components.printer
fun render(fileAnnotationsContainer: FirFileAnnotationsContainer) {
components.annotationRenderer?.render(fileAnnotationsContainer)
components.resolvePhaseRenderer?.render(fileAnnotationsContainer)
printer.println("annotations container")
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -43,7 +43,6 @@ class FirRenderer(
override val referencedSymbolRenderer: FirSymbolRenderer = FirSymbolRenderer(),
override val valueParameterRenderer: FirValueParameterRenderer? = FirValueParameterRenderer(),
override val errorExpressionRenderer: FirErrorExpressionRenderer? = FirErrorExpressionOnlyErrorRenderer(),
override val fileAnnotationsContainerRenderer: FirFileAnnotationsContainerRenderer? = null,
override val resolvedNamedReferenceRenderer: FirResolvedNamedReferenceRenderer = FirResolvedNamedReferenceRendererWithLabel(),
override val resolvedQualifierRenderer: FirResolvedQualifierRenderer = FirResolvedQualifierRendererWithLabel(),
private val lineBreakAfterContextReceivers: Boolean = true,
@@ -55,20 +54,20 @@ class FirRenderer(
override val printer = FirPrinter(builder)
companion object {
fun noAnnotationBodiesAccessorAndArguments(): FirRenderer =
FirRenderer(
annotationRenderer = null, bodyRenderer = null, propertyAccessorRenderer = null,
callArgumentsRenderer = FirCallNoArgumentsRenderer()
)
fun noAnnotationBodiesAccessorAndArguments(): FirRenderer = FirRenderer(
annotationRenderer = null,
bodyRenderer = null,
propertyAccessorRenderer = null,
callArgumentsRenderer = FirCallNoArgumentsRenderer(),
)
fun withResolvePhase(): FirRenderer =
FirRenderer(
resolvePhaseRenderer = FirResolvePhaseRenderer(),
fileAnnotationsContainerRenderer = FirFileAnnotationsContainerRenderer(),
)
fun withResolvePhase(): FirRenderer = FirRenderer(
resolvePhaseRenderer = FirResolvePhaseRenderer(),
)
fun withDeclarationAttributes(): FirRenderer =
FirRenderer(declarationRenderer = FirDeclarationRendererWithAttributes())
fun withDeclarationAttributes(): FirRenderer = FirRenderer(
declarationRenderer = FirDeclarationRendererWithAttributes(),
)
fun forReadability(): FirRenderer = FirRenderer(
typeRenderer = ConeTypeRenderer(),
@@ -79,7 +78,7 @@ class FirRenderer(
callArgumentsRenderer = FirCallNoArgumentsRenderer(),
modifierRenderer = FirPartialModifierRenderer(),
valueParameterRenderer = FirValueParameterRendererForReadability(),
declarationRenderer = FirDeclarationRenderer("local ")
declarationRenderer = FirDeclarationRenderer("local "),
)
}
@@ -100,7 +99,6 @@ class FirRenderer(
referencedSymbolRenderer.components = this
valueParameterRenderer?.components = this
errorExpressionRenderer?.components = this
fileAnnotationsContainerRenderer?.components = this
resolvedNamedReferenceRenderer.components = this
resolvedQualifierRenderer.components = this
getClassCallRenderer.components = this
@@ -202,7 +200,7 @@ class FirRenderer(
printer.println(file.name)
printer.pushIndent()
file.annotationsContainer?.let { visitFileAnnotationsContainer(it) }
annotationRenderer?.render(file)
visitPackageDirective(file.packageDirective)
file.imports.forEach { it.accept(this) }
file.declarations.forEach { it.accept(this) }
@@ -237,14 +235,6 @@ class FirRenderer(
bodyRenderer?.renderBody(codeFragment.block)
}
override fun visitFileAnnotationsContainer(fileAnnotationsContainer: FirFileAnnotationsContainer) {
if (fileAnnotationsContainerRenderer != null) {
fileAnnotationsContainerRenderer.render(fileAnnotationsContainer)
} else {
annotationRenderer?.render(fileAnnotationsContainer)
}
}
override fun visitAnnotation(annotation: FirAnnotation) {
annotationRenderer?.renderAnnotation(annotation)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -25,7 +25,6 @@ internal interface FirRendererComponents {
val referencedSymbolRenderer: FirSymbolRenderer
val valueParameterRenderer: FirValueParameterRenderer?
val errorExpressionRenderer: FirErrorExpressionRenderer?
val fileAnnotationsContainerRenderer: FirFileAnnotationsContainerRenderer?
val resolvedNamedReferenceRenderer: FirResolvedNamedReferenceRenderer
val resolvedQualifierRenderer: FirResolvedQualifierRenderer
val getClassCallRenderer: FirGetClassCallRenderer
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -23,7 +23,6 @@ fun ExceptionAttachmentBuilder.withFirEntry(name: String, fir: FirElement) {
FirRenderer(
resolvePhaseRenderer = FirResolvePhaseRenderer(),
declarationRenderer = FirDeclarationRendererWithAttributes(),
fileAnnotationsContainerRenderer = FirFileAnnotationsContainerRenderer(),
).renderElementAsString(it)
}
withEntry("${name}ElementKind", fir.source?.kind?.let { it::class.simpleName })
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -36,7 +36,7 @@ object BuilderConfigurator : AbstractFirBuilderConfigurator<FirTreeBuilder>(FirT
}
builder(file) {
defaultNull("annotationsContainer")
default("symbol", "FirFileSymbol()")
}
builder(regularClass) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -31,7 +31,6 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val contextReceiver by element(Declaration)
val elementWithResolveState by element(Other)
val fileAnnotationsContainer by element(Other, elementWithResolveState, annotationContainer)
val declaration by sealedElement(Declaration, elementWithResolveState, annotationContainer)
val typeParameterRefsOwner by sealedElement(Declaration)
val typeParametersOwner by sealedElement(Declaration, typeParameterRefsOwner)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -591,13 +591,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
noImpl(userTypeRef)
impl(file) {
default("annotations") {
value = "annotationsContainer?.annotations ?: emptyList()"
withGetter = true
}
}
noImpl(argumentList)
noImpl(annotationArgumentMapping)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -92,10 +92,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
shouldBeAbstractClass()
}
fileAnnotationsContainer.configure {
+field("containingFileSymbol", type("fir.symbols.impl", "FirFileSymbol"))
}
declaration.configure {
+symbolWithPackageWithArgument("fir.symbols", "FirBasedSymbol")
+field("moduleData", firModuleDataType)
@@ -491,7 +487,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
file.configure {
+field("annotationsContainer", fileAnnotationsContainer, nullable = true).withTransform()
+field("packageDirective", packageDirective)
+fieldList(import).withTransform()
+declarations.withTransform()
@@ -70,7 +70,6 @@ internal class ImplementationPrinter(
!element.typeName.contains("Reference")
&& !element.typeName.contains("ResolvedQualifier")
&& !element.typeName.endsWith("Ref")
&& !element.typeName.endsWith("AnnotationsContainer")
}.orEmpty()
val customCalls = fieldsInConstructor.filter { it.customInitializationCall != null }