Package com.puppycrawl.tools.checkstyle
Class JavaParser
java.lang.Object
com.puppycrawl.tools.checkstyle.JavaParser
Helper methods to parse java source files.
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classCustom error listener to provide detailed exception message.static enumEnum to be used for test if comments should be used. - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic DetailASTAppends comment nodes to existing AST.private static DetailASTcreateCommentAstFromToken(org.antlr.v4.runtime.CommonToken token) Create comment AST from token.private static DetailASTcreateSlCommentNode(org.antlr.v4.runtime.Token token) Create single-line comment from token.static DetailASTparse(FileContents contents) Static helper method to parses a Java source file.static DetailASTparseFile(File file, JavaParser.Options options) Parses Java source file.static DetailASTparseFileText(FileText text, JavaParser.Options options) Parse a text and return the parse tree. 
- 
Constructor Details
- 
JavaParser
private JavaParser()Stop instances being created. 
 - 
 - 
Method Details
- 
parse
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.Optionsto 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(File file, JavaParser.Options options) throws IOException, CheckstyleException Parses Java source file.- Parameters:
 file- the file to parseoptions-JavaParser.Optionsto control inclusion of comment nodes- Returns:
 - DetailAST tree
 - Throws:
 IOException- if the file could not be readCheckstyleException- if the file is not a valid Java source file
 - 
appendHiddenCommentNodes
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
 
 - 
createCommentAstFromToken
Create comment AST from token. Depending on token type SINGLE_LINE_COMMENT or BLOCK_COMMENT_BEGIN is created.- Parameters:
 token- to create the AST- Returns:
 - DetailAST of comment node
 
 - 
createSlCommentNode
Create single-line comment from token.- Parameters:
 token- to create the AST- Returns:
 - DetailAST with SINGLE_LINE_COMMENT type
 
 
 -