Search in sources :

Example 16 with DetailNode

use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.

the class SingleLineJavadocCheck method hasJavadocInlineTags.

/**
     * Checks if comment has in-line tags which are not ignored.
     *
     * @param javadocRoot javadoc root node.
     * @return true, if comment has in-line tags which are not ignored.
     * @see <a href=
     * http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadoctags>
     * JavadocTags</a>
     */
private boolean hasJavadocInlineTags(DetailNode javadocRoot) {
    DetailNode javadocTagSection = JavadocUtils.findFirstToken(javadocRoot, JavadocTokenTypes.JAVADOC_INLINE_TAG);
    boolean foundTag = false;
    while (javadocTagSection != null) {
        if (!isTagIgnored(javadocTagSection)) {
            foundTag = true;
            break;
        }
        javadocTagSection = JavadocUtils.getNextSibling(javadocTagSection, JavadocTokenTypes.JAVADOC_INLINE_TAG);
    }
    return foundTag;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 17 with DetailNode

use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.

the class SummaryJavadocCheck method getFirstSentence.

/**
     * Finds and returns first sentence.
     * @param ast Javadoc root node.
     * @return first sentence.
     */
private static String getFirstSentence(DetailNode ast) {
    final StringBuilder result = new StringBuilder();
    final String periodSuffix = PERIOD + ' ';
    for (DetailNode child : ast.getChildren()) {
        final String text = child.getText();
        if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG && text.contains(periodSuffix)) {
            result.append(text.substring(0, text.indexOf(periodSuffix) + 1));
            break;
        } else {
            result.append(text);
        }
    }
    return result.toString();
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 18 with DetailNode

use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.

the class CodeSelectorPresentationTest method testDetailNodeLeafSelection.

@Test
public void testDetailNodeLeafSelection() {
    final DetailNode javadoc = (DetailNode) model.getParseTreeTableModel().getChild(tree.getFirstChild().getNextSibling().getFirstChild(), 0);
    final DetailNode javadocLeaf = javadoc.getChildren()[2];
    final CodeSelectorPresentation selector = new CodeSelectorPresentation(javadocLeaf, linesToPosition);
    selector.findSelectionPositions();
    Assert.assertEquals(5, selector.getSelectionStart());
    Assert.assertEquals(19, selector.getSelectionEnd());
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) Test(org.junit.Test)

Example 19 with DetailNode

use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.

the class ParseTreeTablePresentationTest method testJavadocChild.

@Test
public void testJavadocChild() {
    final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
    final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
    parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
    final Object javadoc = parseTree.getChild(commentContentNode, 0);
    Assert.assertTrue(javadoc instanceof DetailNode);
    Assert.assertEquals(JavadocTokenTypes.JAVADOC, ((DetailNode) javadoc).getType());
    final Object javadocChild = parseTree.getChild(javadoc, 2);
    Assert.assertTrue(javadocChild instanceof DetailNode);
    Assert.assertEquals(JavadocTokenTypes.TEXT, ((DetailNode) javadocChild).getType());
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) Test(org.junit.Test)

Example 20 with DetailNode

use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.

the class CodeSelectorPresentationTest method testDetailNodeSelection.

@Test
public void testDetailNodeSelection() {
    final DetailNode javadoc = (DetailNode) model.getParseTreeTableModel().getChild(tree.getFirstChild().getNextSibling().getFirstChild(), 0);
    final CodeSelectorPresentation selector = new CodeSelectorPresentation(javadoc, linesToPosition);
    selector.findSelectionPositions();
    Assert.assertEquals(3, selector.getSelectionStart());
    Assert.assertEquals(25, selector.getSelectionEnd());
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) Test(org.junit.Test)

Aggregations

DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)26 JavadocNodeImpl (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)5 Test (org.junit.Test)5 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 JavadocDetailNodeParser (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser)1 ArrayList (java.util.ArrayList)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1