Search in sources :

Example 6 with ParseErrorMessage

use of com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage in project checkstyle by checkstyle.

the class DetailNodeTreeStringPrinterTest method testMissedHtmlTagParseErrorMessage.

@Test
public void testMissedHtmlTagParseErrorMessage() throws Exception {
    final String actual = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(35, MSG_JAVADOC_MISSED_HTML_CLOSE, 7, "xyz"));
    final Violation violation = new Violation(35, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", MSG_JAVADOC_MISSED_HTML_CLOSE, new Object[] { 7, "xyz" }, "", DetailNodeTreeStringPrinter.class, null);
    final String expected = "[ERROR:35] " + violation.getViolation();
    assertWithMessage("Javadoc parse error violation for missed HTML tag " + "doesn't meet expectations").that(actual).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) Test(org.junit.jupiter.api.Test)

Example 7 with ParseErrorMessage

use of com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage in project checkstyle by checkstyle.

the class AbstractJavadocCheck method visitToken.

@Override
public final void visitToken(DetailAST blockCommentNode) {
    if (JavadocUtil.isJavadocComment(blockCommentNode)) {
        // store as field, to share with child Checks
        context.get().blockCommentAst = blockCommentNode;
        final LineColumn treeCacheKey = new LineColumn(blockCommentNode.getLineNo(), blockCommentNode.getColumnNo());
        final ParseStatus result;
        if (TREE_CACHE.get().containsKey(treeCacheKey)) {
            result = TREE_CACHE.get().get(treeCacheKey);
        } else {
            result = context.get().parser.parseJavadocAsDetailNode(blockCommentNode);
            TREE_CACHE.get().put(treeCacheKey, result);
        }
        if (result.getParseErrorMessage() == null) {
            if (acceptJavadocWithNonTightHtml() || !result.isNonTight()) {
                processTree(result.getTree());
            }
            if (violateExecutionOnNonTightHtml && result.isNonTight()) {
                log(result.getFirstNonTightHtmlTag().getLine(), JavadocDetailNodeParser.MSG_UNCLOSED_HTML_TAG, result.getFirstNonTightHtmlTag().getText());
            }
        } else {
            final ParseErrorMessage parseErrorMessage = result.getParseErrorMessage();
            log(parseErrorMessage.getLineNumber(), parseErrorMessage.getMessageKey(), parseErrorMessage.getMessageArguments());
        }
    }
}
Also used : ParseStatus(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseStatus) LineColumn(com.puppycrawl.tools.checkstyle.api.LineColumn) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage)

Example 8 with ParseErrorMessage

use of com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage in project checkstyle by checkstyle.

the class DetailNodeTreeStringPrinterTest method testParseErrorMessage.

@Test
public void testParseErrorMessage() throws Exception {
    final String actual = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(10, MSG_JAVADOC_PARSE_RULE_ERROR, 9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT"));
    final Violation violation = new Violation(10, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", MSG_JAVADOC_PARSE_RULE_ERROR, new Object[] { 9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT" }, "", DetailNodeTreeStringPrinter.class, null);
    final String expected = "[ERROR:10] " + violation.getViolation();
    assertWithMessage("Javadoc parse error violation doesn't meet expectations").that(actual).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) Test(org.junit.jupiter.api.Test)

Example 9 with ParseErrorMessage

use of com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage in project checkstyle by checkstyle.

the class DetailNodeTreeStringPrinterTest method testNoViableAltException.

@Test
public void testNoViableAltException() throws Exception {
    final File file = new File(getPath("InputDetailNodeTreeStringPrinterNoViableAltException.javadoc"));
    try {
        DetailNodeTreeStringPrinter.printFileAst(file);
        assertWithMessage("Exception is expected").fail();
    } catch (IllegalArgumentException ex) {
        final String expected = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(0, MSG_JAVADOC_PARSE_RULE_ERROR, 9, "no viable alternative at input '<<'", "HTML_ELEMENT"));
        assertWithMessage("Generated and expected parse error messages don't match").that(ex.getMessage()).isEqualTo(expected);
    }
}
Also used : ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 10 with ParseErrorMessage

use of com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage in project checkstyle by checkstyle.

the class DetailNodeTreeStringPrinterTest method testHtmlTagCloseBeforeTagOpen.

@Test
public void testHtmlTagCloseBeforeTagOpen() throws Exception {
    final File file = new File(getPath("InputDetailNodeTreeStringPrinterHtmlTagCloseBeforeTagOpen.javadoc"));
    try {
        DetailNodeTreeStringPrinter.printFileAst(file);
        assertWithMessage("Exception is expected").fail();
    } catch (IllegalArgumentException ex) {
        final String expected = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(0, MSG_JAVADOC_PARSE_RULE_ERROR, 4, "no viable alternative at input '</tag'", "HTML_ELEMENT"));
        assertWithMessage("Generated and expected parse error messages don't match").that(ex.getMessage()).isEqualTo(expected);
    }
}
Also used : ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ParseErrorMessage (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage)10 Test (org.junit.jupiter.api.Test)9 File (java.io.File)6 Violation (com.puppycrawl.tools.checkstyle.api.Violation)3 ParseStatus (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseStatus)1 LineColumn (com.puppycrawl.tools.checkstyle.api.LineColumn)1