use of com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser in project checkstyle by checkstyle.
the class JavadocDetailNodeParser method parseJavadocAsParseTree.
/**
* Parses block comment content as javadoc comment.
* @param blockComment
* block comment content.
* @return parse tree
*/
private ParseTree parseJavadocAsParseTree(String blockComment) {
final ANTLRInputStream input = new ANTLRInputStream(blockComment);
final JavadocLexer lexer = new JavadocLexer(input);
// remove default error listeners
lexer.removeErrorListeners();
// add custom error listener that logs parsing errors
lexer.addErrorListener(errorListener);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final JavadocParser parser = new JavadocParser(tokens);
// remove default error listeners
parser.removeErrorListeners();
// add custom error listener that logs syntax errors
parser.addErrorListener(errorListener);
// This strategy stops parsing when parser error occurs.
// By default it uses Error Recover Strategy which is slow and useless.
parser.setErrorHandler(new BailErrorStrategy());
return parser.javadoc();
}
use of com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser in project contribution by checkstyle.
the class ExpectedParseTreeGenerator method parseJavadocFromFile.
private static ParseTree parseJavadocFromFile(File file) throws IOException {
final String content = Files.toString(file, Charsets.UTF_8);
final InputStream in = new ByteArrayInputStream(content.getBytes(Charsets.UTF_8));
final ANTLRInputStream input = new ANTLRInputStream(in);
final JavadocLexer lexer = new JavadocLexer(input);
lexer.removeErrorListeners();
final BaseErrorListener errorListener = new FailOnErrorListener();
lexer.addErrorListener(errorListener);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final JavadocParser parser = new JavadocParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
return parser.javadoc();
}
Aggregations