[FIR generator] Write kDocs for accept & transform methods in FirElement

This commit is contained in:
Sergej Jaskiewicz
2023-11-06 18:51:05 +01:00
committed by Space Team
parent ed28923282
commit 02c12ae26f
5 changed files with 122 additions and 84 deletions
@@ -19,18 +19,53 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
interface FirElement {
val source: KtSourceElement?
/**
* Runs the provided [visitor] on the FIR subtree with the root at this node.
*
* @param visitor The visitor to accept.
* @param data An arbitrary context to pass to each invocation of [visitor]'s methods.
* @return The value returned by the topmost `visit*` invocation.
*/
fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitElement(this, data)
/**
* Runs the provided [transformer] on the FIR subtree with the root at this node.
*
* @param transformer The transformer to use.
* @param data An arbitrary context to pass to each invocation of [transformer]'s methods.
* @return The transformed node.
*/
@Suppress("UNCHECKED_CAST")
fun <E : FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformElement(this, data) as E
fun accept(visitor: FirVisitorVoid) = accept(visitor, null)
/**
* Runs the provided [visitor] on subtrees with roots in this node's children.
*
* Basically, calls `accept(visitor, data)` on each child of this node.
*
* Does **not** run [visitor] on this node itself.
*
* @param visitor The visitor for children to accept.
* @param data An arbitrary context to pass to each invocation of [visitor]'s methods.
*/
fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D)
fun acceptChildren(visitor: FirVisitorVoid) = acceptChildren(visitor, null)
/**
* Recursively transforms this node's children *in place* using [transformer].
*
* Basically, executes `this.child = this.child.transform(transformer, data)` for each child of this node.
*
* Does **not** run [transformer] on this node itself.
*
* @param transformer The transformer to use for transforming the children.
* @param data An arbitrary context to pass to each invocation of [transformer]'s methods.
* @return `this`
*/
fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement
}