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 Stringprivate static Stringprivate static final LexicalDifferenceCalculatorThe 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) findNodeForToken(Node node, Range tokenRange) private static ObservablePropertyfindNodeListName(NodeList<?> nodeList) (package private) static NodeTextgetOrCreateNodeText(Node node) private static NodeTextinterpret(Node node, CsmElement csm, NodeText nodeText) TODO: Process CsmIndent and CsmUnindent before reaching this pointstatic booleanisAvailableOn(Node node) private static booleanprivate static voidprettyPrintingTextNode(Node node, NodeText nodeText) static StringPrint 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 voidstoreInitialText(Node root) private static voidstoreInitialTextForOneNode(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
-
findNodeForToken
-
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
-