Class LexicalPreservingPrinter
java.lang.Object
com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static String
private static String
private static final LexicalDifferenceCalculator
The nodetext for a node is stored in the node's data field.private static AstObserver
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static AstObserver
(package private) static List
<TextElement> findIndentation
(Node node) private static ObservableProperty
findNodeListName
(NodeList<?> nodeList) (package private) static NodeText
getOrCreateNodeText
(Node node) private static NodeText
interpret
(Node node, CsmElement csm, NodeText nodeText) TODO: Process CsmIndent and CsmUnindent before reaching this pointstatic boolean
isAvailableOn
(Node node) private static boolean
private static void
prettyPrintingTextNode
(Node node, NodeText nodeText) static String
Print a Node into a String, preserving the lexical information.static <N extends Node>
Nsetup
(N node) Prepares the node so it can be used in the print methods.private static void
storeInitialText
(Node root) private static void
storeInitialTextForOneNode
(Node node, List<JavaToken> nodeTokens) private static Iterator
<TokenTextElement> tokensPreceeding
(Node node)
-
Field Details
-
JAVA_UTIL_OPTIONAL
-
JAVAPARSER_AST_NODELIST
-
observer
-
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. -
LEXICAL_DIFFERENCE_CALCULATOR
-
-
Constructor Details
-
LexicalPreservingPrinter
public LexicalPreservingPrinter()
-
-
Method Details
-
setup
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.
-
isAvailableOn
-
createObserver
-
storeInitialText
-
storeInitialTextForOneNode
-
tokensPreceeding
-
print
Print a Node into a String, preserving the lexical information. -
prettyPrintingTextNode
-
interpret
TODO: Process CsmIndent and CsmUnindent before reaching this point -
getOrCreateNodeText
-
findIndentation
-
isReturningOptionalNodeList
-
findNodeListName
-