Class LexicalPreservingPrinter
- java.lang.Object
-
- com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter
-
public class LexicalPreservingPrinter extends Object
A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when operating on the AST and then used them to reproduce the source code in its original formatting including the AST changes.
-
-
Field Summary
Fields Modifier and Type Field Description static DataKey<com.github.javaparser.printer.lexicalpreservation.NodeText>
NODE_TEXT_DATA
The nodetext for a node is stored in the node's data field.
-
Constructor Summary
Constructors Constructor Description LexicalPreservingPrinter(Node node)
Deprecated.use setup(Node) to prepare a node for lexical preservation, then use the static methods on this class to print it.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
print(Node node)
Print a Node into a String, preserving the lexical information.static void
print(Node node, Writer writer)
Print a Node into a Writer, preserving the lexical information.static <N extends Node>
Pair<ParseResult<N>,LexicalPreservingPrinter>setup(ParseStart<N> parseStart, Provider provider)
Deprecated.use setup(Node) and the static methods on this class.static <N extends Node>
Nsetup(N node)
Prepares the node so it can be used in the print methods.
-
-
-
Field Detail
-
NODE_TEXT_DATA
public static final DataKey<com.github.javaparser.printer.lexicalpreservation.NodeText> NODE_TEXT_DATA
The nodetext for a node is stored in the node's data field. This is the key to set and retrieve it.
-
-
Constructor Detail
-
LexicalPreservingPrinter
@Deprecated public LexicalPreservingPrinter(Node node)
Deprecated.use setup(Node) to prepare a node for lexical preservation, then use the static methods on this class to print it.
-
-
Method Detail
-
setup
public static <N extends Node> Pair<ParseResult<N>,LexicalPreservingPrinter> setup(ParseStart<N> parseStart, Provider provider)
Deprecated.use setup(Node) and the static methods on this class.Parse the code and setup the LexicalPreservingPrinter.
-
setup
public static <N extends Node> N setup(N node)
Prepares the node so it can be used in the print methods. The correct order is:- Parse some code
- Call this setup method on the result
- Make changes to the AST as desired
- Use one of the print methods on this class to print out the original source code with your changes added
- Returns:
- the node passed as a parameter for your convenience.
-
print
public static String print(Node node)
Print a Node into a String, preserving the lexical information.
-
print
public static void print(Node node, Writer writer) throws IOException
Print a Node into a Writer, preserving the lexical information.- Throws:
IOException
-
-