Class LexicalPreservingPrinter
- java.lang.Object
-
- com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter
-
public class LexicalPreservingPrinter extends java.lang.ObjectA 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 classLexicalPreservingPrinter.Observer
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringJAVA_UTIL_OPTIONALprivate static java.lang.StringJAVAPARSER_AST_NODELISTprivate static LexicalDifferenceCalculatorLEXICAL_DIFFERENCE_CALCULATORstatic DataKey<NodeText>NODE_TEXT_DATAThe nodetext for a node is stored in the node's data field.private static AstObserverobserver
-
Constructor Summary
Constructors Constructor Description LexicalPreservingPrinter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static AstObservercreateObserver()(package private) static java.util.List<TextElement>findIndentation(Node node)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 booleanisReturningOptionalNodeList(java.lang.reflect.Method m)private static voidprettyPrintingTextNode(Node node, NodeText nodeText)static java.lang.Stringprint(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 voidstoreInitialText(Node root)private static voidstoreInitialTextForOneNode(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)
-
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)
-
-