Add KDoc to IrAttributeContainer

This commit is contained in:
Ivan Kylchik
2022-12-21 19:18:07 +01:00
committed by Space Team
parent 0af4ef8ee9
commit 4506ca6792
5 changed files with 26 additions and 4 deletions
@@ -11,7 +11,13 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.ir.IrElement
/**
* A non-leaf IR tree element.
* Represents an IR element that can be copied, but must remember its original element. It is
* useful, for example, to keep track of generated names for anonymous declarations.
* @property attributeOwnerId original element before copying. Always satisfies the following
* invariant: this.attributeOwnerId == this.attributeOwnerId.attributeOwnerId.
* @property attributeOwnerIdBeforeInline original element before inlining. Useful only with IR
* inliner. null if the element wasn't inlined. Unlike [attributeOwnerId], doesn't have the
* idempotence invariant and can contain a chain of declarations.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.attributeContainer
*/
interface IrAttributeContainer : IrElement {
@@ -170,6 +170,16 @@ object IrTree : AbstractTreeBuilder() {
+listField("sealedSubclasses", classSymbolType, mutability = Var)
}
val attributeContainer: ElementConfig by element(Declaration) {
kDoc = """
Represents an IR element that can be copied, but must remember its original element. It is
useful, for example, to keep track of generated names for anonymous declarations.
@property attributeOwnerId original element before copying. Always satisfies the following
invariant: `this.attributeOwnerId == this.attributeOwnerId.attributeOwnerId`.
@property attributeOwnerIdBeforeInline original element before inlining. Useful only with IR
inliner. `null` if the element wasn't inlined. Unlike [attributeOwnerId], doesn't have the
idempotence invariant and can contain a chain of declarations.
""".trimIndent()
+field("attributeOwnerId", attributeContainer)
+field("attributeOwnerIdBeforeInline", attributeContainer, nullable = true) // null <=> this element wasn't inlined
}
@@ -40,6 +40,7 @@ class ElementConfig(
var generationCallback: (TypeSpec.Builder.() -> Unit)? = null
var suppressPrint = false
var kDoc: String? = null
override val element get() = this
override val args get() = emptyMap<NamedTypeParameterRef, TypeRef>()
@@ -42,6 +42,7 @@ class Element(
val generationCallback = config.generationCallback
val suppressPrint = config.suppressPrint
val propertyName = config.propertyName
val kDoc = config.kDoc
override fun toString() = name
@@ -180,9 +180,13 @@ fun printElements(generationPath: File, model: Model) = sequence {
private fun TypeSpec.Builder.generateElementKDoc(element: Element) {
addKdoc(buildString {
append("A ")
append(if (element.isLeaf) "leaf" else "non-leaf")
appendLine(" IR tree element.")
if (element.kDoc != null) {
appendLine(element.kDoc)
} else {
append("A ")
append(if (element.isLeaf) "leaf" else "non-leaf")
appendLine(" IR tree element.")
}
append("@sample ${element.propertyName}")
})