LexicalPreservingPrinter

The LexicalPreservingPrinter is responsible for maintaining the original formatting and layout of Java source code when the Abstract Syntax Tree (AST) is modified. This printer works by: 1. Storing the original textual representation alongside the AST nodes 2. Tracking changes made to the AST through a sophisticated change tracking system 3. Applying only the necessary modifications while preserving unchanged portions 4. Maintaining original spacing, comments, and formatting wherever possible The lexical preservation is essential for code refactoring tools that need to modify code while maintaining its original style and readability. Usage Pattern: 1. Setup lexical preservation on a CompilationUnit before making changes 2. Modify the AST as needed 3. Use this printer to generate the modified source code with preserved formatting

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
The nodetext for a node is stored in the node's data field.

Functions

Link copied to clipboard
open fun isAvailableOn(node: Node): Boolean
Link copied to clipboard
open fun print(node: Node): String
Prints the given node to a string while preserving the original formatting where possible and applying changes where the AST has been modified.
Link copied to clipboard
open fun <N : Node?> setup(node: N): N
Initializes lexical preservation for the given CompilationUnit.