Writer

open class Writer(appendable: Appendable = StringBuilder(), withExtras: Boolean = true) : Visitor

Writer that converts AST nodes back to source code. When the withExtras is true, which is the default, it will preserve the original whitespaces, comments, semicolons and trailing commas. Even when the withExtras is false, it will still insert minimal whitespaces and semicolons automatically to avoid compilation errors or loss of meaning.

Example usage:

// Write with extras
val source = Writer.write(node)
// Write without extras
val sourceWithoutExtras = Writer.write(node, withExtras = false)

Constructors

Link copied to clipboard
constructor(appendable: Appendable = StringBuilder(), withExtras: Boolean = true)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun traverse(rootNode: Node)

Traverses the given AST node and its descendants depth-first order and calls the protected visit method for each node.

Link copied to clipboard
fun write(rootNode: Node)

Converts the given AST node back to source code.