Package com.puppycrawl.tools.checkstyle
Class JavaParser
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.JavaParser
-
public final class JavaParser extends java.lang.Object
Helper methods to parse java source files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JavaParser.Options
Enum to be used for test if comments should be used.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DetailAST
appendHiddenCommentNodes(DetailAST root)
Appends comment nodes to existing AST.static DetailAST
parse(FileContents contents)
Static helper method to parses a Java source file.static DetailAST
parseFile(java.io.File file, JavaParser.Options options)
Parses Java source file.static DetailAST
parseFileText(FileText text, JavaParser.Options options)
Parse a text and return the parse tree.
-
-
-
Method Detail
-
parse
public static DetailAST parse(FileContents contents) throws CheckstyleException
Static helper method to parses a Java source file.- Parameters:
contents
- contains the contents of the file- Returns:
- the root of the AST
- Throws:
CheckstyleException
- if the contents is not a valid Java source
-
parseFileText
public static DetailAST parseFileText(FileText text, JavaParser.Options options) throws CheckstyleException
Parse a text and return the parse tree.- Parameters:
text
- the text to parseoptions
-JavaParser.Options
to control inclusion of comment nodes- Returns:
- the root node of the parse tree
- Throws:
CheckstyleException
- if the text is not a valid Java source
-
parseFile
public static DetailAST parseFile(java.io.File file, JavaParser.Options options) throws java.io.IOException, CheckstyleException
Parses Java source file.- Parameters:
file
- the file to parseoptions
-JavaParser.Options
to control inclusion of comment nodes- Returns:
- DetailAST tree
- Throws:
java.io.IOException
- if the file could not be readCheckstyleException
- if the file is not a valid Java source file
-
appendHiddenCommentNodes
public static DetailAST appendHiddenCommentNodes(DetailAST root)
Appends comment nodes to existing AST. It traverses each node in AST, looks for hidden comment tokens and appends found comment tokens as nodes in AST.- Parameters:
root
- of AST- Returns:
- root of AST with comment nodes
-
-