Search in sources :

Example 1 with JavadocLexer

use of com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocLexer in project checkstyle by checkstyle.

the class JavadocDetailNodeParser method createJavadocParser.

/**
 * Parses block comment content as javadoc comment.
 *
 * @param blockComment
 *        block comment content.
 * @param errorListener custom error listener
 * @return parse tree
 */
private static JavadocParser createJavadocParser(String blockComment, DescriptiveErrorListener errorListener) {
    final JavadocLexer lexer = new JavadocLexer(CharStreams.fromString(blockComment), true);
    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);
    // JavadocParserErrorStrategy stops parsing on first parse error encountered unlike the
    // DefaultErrorStrategy used by ANTLR which rather attempts error recovery.
    parser.setErrorHandler(new CheckstyleParserErrorStrategy());
    return parser;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) JavadocParser(com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser) JavadocLexer(com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocLexer)

Aggregations

JavadocLexer (com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocLexer)1 JavadocParser (com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1