Search in sources :

Example 31 with DetailNode

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

the class ParseTreeTablePresentationTest method testJavadocCommentChild.

@Test
public void testJavadocCommentChild() {
    final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
    final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
    parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
    final Object child = parseTree.getChild(commentContentNode, 0);
    assertWithMessage("Invalid child type").that(child instanceof DetailNode).isTrue();
    final int type = ((DetailNode) child).getType();
    assertWithMessage("Invalid child token type").that(type).isEqualTo(JavadocTokenTypes.JAVADOC);
    // get Child one more time to test cache of PModel
    final Object childSame = parseTree.getChild(commentContentNode, 0);
    assertWithMessage("Invalid child type").that(childSame instanceof DetailNode).isTrue();
    final int sameType = ((DetailNode) childSame).getType();
    assertWithMessage("Invalid child token type").that(sameType).isEqualTo(JavadocTokenTypes.JAVADOC);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) Test(org.junit.jupiter.api.Test)

Example 32 with DetailNode

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

the class ParseTreeTablePresentationTest method testJavadocChildCount.

@Test
public void testJavadocChildCount() {
    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);
    assertWithMessage("Invalid child type").that(javadoc instanceof DetailNode).isTrue();
    final int type = ((DetailNode) javadoc).getType();
    assertWithMessage("Invalid child token type").that(type).isEqualTo(JavadocTokenTypes.JAVADOC);
    final int javadocChildCount = parseTree.getChildCount(javadoc);
    assertWithMessage("Invalid child count").that(javadocChildCount).isEqualTo(5);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) Test(org.junit.jupiter.api.Test)

Example 33 with DetailNode

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

the class JavadocUtilTest method testGetPreviousSibling.

@Test
public void testGetPreviousSibling() {
    final JavadocNodeImpl root = new JavadocNodeImpl();
    final JavadocNodeImpl node = new JavadocNodeImpl();
    node.setIndex(1);
    node.setParent(root);
    final JavadocNodeImpl previousNode = new JavadocNodeImpl();
    previousNode.setIndex(0);
    node.setParent(root);
    root.setChildren(previousNode, node);
    final DetailNode previousSibling = JavadocUtil.getPreviousSibling(node);
    assertWithMessage("Unexpected node").that(previousSibling).isEqualTo(previousNode);
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl) Test(org.junit.jupiter.api.Test)

Example 34 with DetailNode

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

the class JavadocUtilTest method testGetFirstToken.

@Test
public void testGetFirstToken() {
    final JavadocNodeImpl javadocNode = new JavadocNodeImpl();
    final JavadocNodeImpl basetag = new JavadocNodeImpl();
    basetag.setType(JavadocTokenTypes.BASE_TAG);
    final JavadocNodeImpl body = new JavadocNodeImpl();
    body.setType(JavadocTokenTypes.BODY);
    body.setParent(javadocNode);
    basetag.setParent(javadocNode);
    javadocNode.setChildren(basetag, body);
    final DetailNode result = JavadocUtil.findFirstToken(javadocNode, JavadocTokenTypes.BODY);
    assertWithMessage("Invalid first token").that(result).isEqualTo(body);
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl) Test(org.junit.jupiter.api.Test)

Example 35 with DetailNode

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

the class JavadocUtil method findFirstToken.

/**
 * Returns the first child token that has a specified type.
 *
 * @param detailNode
 *        Javadoc AST node
 * @param type
 *        the token type to match
 * @return the matching token, or null if no match
 */
public static DetailNode findFirstToken(DetailNode detailNode, int type) {
    DetailNode returnValue = null;
    DetailNode node = getFirstChild(detailNode);
    while (node != null) {
        if (node.getType() == type) {
            returnValue = node;
            break;
        }
        node = getNextSibling(node);
    }
    return returnValue;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Aggregations

DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)48 Test (org.junit.jupiter.api.Test)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 JavadocNodeImpl (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)4 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Matcher (java.util.regex.Matcher)2 FileStatefulCheck (com.puppycrawl.tools.checkstyle.FileStatefulCheck)1 JavadocDetailNodeParser (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser)1 JavadocTokenTypes (com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes)1 TokenTypes (com.puppycrawl.tools.checkstyle.api.TokenTypes)1 AbstractJavadocCheck (com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck)1 JavadocParser (com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser)1 TokenUtil (com.puppycrawl.tools.checkstyle.utils.TokenUtil)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1