Package com.puppycrawl.tools.checkstyle
Class AstTreeStringPrinter
java.lang.Object
com.puppycrawl.tools.checkstyle.AstTreeStringPrinter
Class for printing AST to String.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
escapeAllControlChars
(String text) Replace all control chars with escaped symbols.private static String
getIndentation
(DetailAST ast) Get indentation for an AST node.private static String
getNodeInfo
(DetailAST node) Get string representation of the node as token name, node text, line number and column number.private static String
Parses block comment as javadoc and prints its tree.static String
printAst
(FileText text, JavaParser.Options options) Parse a file and print the parse tree.static String
printBranch
(DetailAST node) Print branch info from root down to givennode
.static String
printFileAst
(File file, JavaParser.Options options) Parse a file and print the parse tree.private static String
Prints full tree (java + comments + javadoc) of the DetailAST.static String
printJavaAndJavadocTree
(File file) Prints full AST (java + comments + javadoc) of the java file.private static String
Print AST.
-
Field Details
-
NEWLINE
Newline pattern. -
RETURN
Return pattern. -
TAB
Tab pattern. -
LINE_SEPARATOR
OS specific line separator.
-
-
Constructor Details
-
AstTreeStringPrinter
private AstTreeStringPrinter()Prevent instances.
-
-
Method Details
-
printFileAst
public static String printFileAst(File file, JavaParser.Options options) throws IOException, CheckstyleException Parse a file and print the parse tree.- Parameters:
file
- the file to print.options
-JavaParser.Options
to control the inclusion of comment nodes.- Returns:
- the AST of the file in String form.
- Throws:
IOException
- if the file could not be read.CheckstyleException
- if the file is not a Java source.
-
printJavaAndJavadocTree
Prints full AST (java + comments + javadoc) of the java file.- Parameters:
file
- java file- Returns:
- Full tree
- Throws:
IOException
- Failed to open a fileCheckstyleException
- error while parsing the file
-
printJavaAndJavadocTree
Prints full tree (java + comments + javadoc) of the DetailAST.- Parameters:
ast
- root DetailAST- Returns:
- Full tree
-
parseAndPrintJavadocTree
Parses block comment as javadoc and prints its tree.- Parameters:
node
- block comment begin- Returns:
- string javadoc tree
-
printAst
Parse a file and print the parse tree.- Parameters:
text
- the text to parse.options
-JavaParser.Options
to control the inclusion of comment nodes.- Returns:
- the AST of the file in String form.
- Throws:
CheckstyleException
- if the file is not a Java source.
-
printBranch
Print branch info from root down to givennode
.- Parameters:
node
- last item of the branch- Returns:
- branch as string
-
printTree
Print AST.- Parameters:
ast
- the root AST node.- Returns:
- string AST.
-
getNodeInfo
Get string representation of the node as token name, node text, line number and column number.- Parameters:
node
- DetailAST- Returns:
- node info
-
getIndentation
Get indentation for an AST node.- Parameters:
ast
- the AST to get the indentation for.- Returns:
- the indentation in String format.
-
escapeAllControlChars
Replace all control chars with escaped symbols.- Parameters:
text
- the String to process.- Returns:
- the processed String with all control chars escaped.
-