Class LexicalPreservingPrinter
- java.lang.Object
-
- com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter
-
public class LexicalPreservingPrinter extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LexicalPreservingPrinter.Observer
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
JAVA_UTIL_OPTIONAL
private static java.lang.String
JAVAPARSER_AST_NODELIST
private static LexicalDifferenceCalculator
LEXICAL_DIFFERENCE_CALCULATOR
static DataKey<NodeText>
NODE_TEXT_DATA
The nodetext for a node is stored in the node's data field.private static AstObserver
observer
-
Constructor Summary
Constructors Constructor Description LexicalPreservingPrinter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static AstObserver
createObserver()
(package private) static java.util.List<TextElement>
findIndentation(Node node)
private static java.util.Optional<Node>
findNodeForToken(Node node, Range tokenRange)
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
isReturningOptionalNodeList(java.lang.reflect.Method m)
private static void
prettyPrintingTextNode(Node node, NodeText nodeText)
static java.lang.String
print(Node node)
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, java.util.List<JavaToken> nodeTokens)
private static java.util.Iterator<TokenTextElement>
tokensPreceeding(Node node)
-
-
-
Field Detail
-
JAVA_UTIL_OPTIONAL
private static java.lang.String JAVA_UTIL_OPTIONAL
-
JAVAPARSER_AST_NODELIST
private static java.lang.String JAVAPARSER_AST_NODELIST
-
observer
private static AstObserver observer
-
NODE_TEXT_DATA
public static final DataKey<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.
-
LEXICAL_DIFFERENCE_CALCULATOR
private static final LexicalDifferenceCalculator LEXICAL_DIFFERENCE_CALCULATOR
-
-
Method Detail
-
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.
-
isAvailableOn
public static boolean isAvailableOn(Node node)
-
createObserver
private static AstObserver createObserver()
-
storeInitialText
private static void storeInitialText(Node root)
-
findNodeForToken
private static java.util.Optional<Node> findNodeForToken(Node node, Range tokenRange)
-
storeInitialTextForOneNode
private static void storeInitialTextForOneNode(Node node, java.util.List<JavaToken> nodeTokens)
-
tokensPreceeding
private static java.util.Iterator<TokenTextElement> tokensPreceeding(Node node)
-
print
public static java.lang.String print(Node node)
Print a Node into a String, preserving the lexical information.
-
interpret
private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText)
TODO: Process CsmIndent and CsmUnindent before reaching this point
-
findIndentation
static java.util.List<TextElement> findIndentation(Node node)
-
isReturningOptionalNodeList
private static boolean isReturningOptionalNodeList(java.lang.reflect.Method m)
-
findNodeListName
private static ObservableProperty findNodeListName(NodeList<?> nodeList)
-
-