Search in sources :

Example 1 with JavadocNodeImpl

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl in project checkstyle by checkstyle.

the class JavadocUtilsTest method testBranchContains.

@Test
public void testBranchContains() {
    final JavadocNodeImpl node = new JavadocNodeImpl();
    final JavadocNodeImpl firstChild = new JavadocNodeImpl();
    final JavadocNodeImpl secondChild = new JavadocNodeImpl();
    node.setType(JavadocTokenTypes.JAVADOC);
    firstChild.setType(JavadocTokenTypes.BODY_TAG_OPEN);
    secondChild.setType(JavadocTokenTypes.CODE_LITERAL);
    node.setChildren(firstChild, secondChild);
    assertFalse(JavadocUtils.containsInBranch(node, JavadocTokenTypes.AUTHOR_LITERAL));
    firstChild.setParent(node);
    secondChild.setParent(node);
    assertFalse(JavadocUtils.containsInBranch(node, JavadocTokenTypes.AUTHOR_LITERAL));
    secondChild.setType(JavadocTokenTypes.AUTHOR_LITERAL);
    assertTrue(JavadocUtils.containsInBranch(node, JavadocTokenTypes.AUTHOR_LITERAL));
}
Also used : JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl) Test(org.junit.Test)

Example 2 with JavadocNodeImpl

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl in project checkstyle by checkstyle.

the class JavadocDetailNodeParser method adjustFirstLineToJavadocIndent.

/**
     * Adjust first line nodes to javadoc indent.
     * @param tree DetailNode tree root
     * @param javadocColumnNumber javadoc indent
     */
private void adjustFirstLineToJavadocIndent(DetailNode tree, int javadocColumnNumber) {
    if (tree.getLineNumber() == blockCommentLineNumber) {
        ((JavadocNodeImpl) tree).setColumnNumber(tree.getColumnNumber() + javadocColumnNumber);
        final DetailNode[] children = tree.getChildren();
        for (DetailNode child : children) {
            adjustFirstLineToJavadocIndent(child, javadocColumnNumber);
        }
    }
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)

Example 3 with JavadocNodeImpl

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl in project checkstyle by checkstyle.

the class JavadocDetailNodeParser method convertParseTreeToDetailNode.

/**
     * Converts ParseTree (that is generated by ANTLRv4) to DetailNode tree.
     *
     * @param parseTreeNode root node of ParseTree
     * @return root of DetailNode tree
     */
private DetailNode convertParseTreeToDetailNode(ParseTree parseTreeNode) {
    final JavadocNodeImpl rootJavadocNode = createRootJavadocNode(parseTreeNode);
    JavadocNodeImpl currentJavadocParent = rootJavadocNode;
    ParseTree parseTreeParent = parseTreeNode;
    while (currentJavadocParent != null) {
        // remove unnecessary children tokens
        if (currentJavadocParent.getType() == JavadocTokenTypes.TEXT) {
            currentJavadocParent.setChildren((DetailNode[]) JavadocNodeImpl.EMPTY_DETAIL_NODE_ARRAY);
        }
        final JavadocNodeImpl[] children = (JavadocNodeImpl[]) currentJavadocParent.getChildren();
        insertChildrenNodes(children, parseTreeParent);
        if (children.length > 0) {
            currentJavadocParent = children[0];
            parseTreeParent = parseTreeParent.getChild(0);
        } else {
            JavadocNodeImpl nextJavadocSibling = (JavadocNodeImpl) JavadocUtils.getNextSibling(currentJavadocParent);
            ParseTree nextParseTreeSibling = getNextSibling(parseTreeParent);
            if (nextJavadocSibling == null) {
                JavadocNodeImpl tempJavadocParent = (JavadocNodeImpl) currentJavadocParent.getParent();
                ParseTree tempParseTreeParent = parseTreeParent.getParent();
                while (nextJavadocSibling == null && tempJavadocParent != null) {
                    nextJavadocSibling = (JavadocNodeImpl) JavadocUtils.getNextSibling(tempJavadocParent);
                    nextParseTreeSibling = getNextSibling(tempParseTreeParent);
                    tempJavadocParent = (JavadocNodeImpl) tempJavadocParent.getParent();
                    tempParseTreeParent = tempParseTreeParent.getParent();
                }
            }
            currentJavadocParent = nextJavadocSibling;
            parseTreeParent = nextParseTreeSibling;
        }
    }
    return rootJavadocNode;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 4 with JavadocNodeImpl

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl in project checkstyle by checkstyle.

the class JavadocDetailNodeParser method createChildrenNodes.

/**
     * Creates children Javadoc nodes base on ParseTree node's children.
     * @param parentJavadocNode node that will be parent for created children
     * @param parseTreeNode original ParseTree node
     * @return array of Javadoc nodes
     */
private JavadocNodeImpl[] createChildrenNodes(JavadocNodeImpl parentJavadocNode, ParseTree parseTreeNode) {
    final JavadocNodeImpl[] children = new JavadocNodeImpl[parseTreeNode.getChildCount()];
    for (int j = 0; j < children.length; j++) {
        final JavadocNodeImpl child = createJavadocNode(parseTreeNode.getChild(j), parentJavadocNode, j);
        children[j] = child;
    }
    return children;
}
Also used : JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)

Example 5 with JavadocNodeImpl

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl in project checkstyle by checkstyle.

the class JavadocDetailNodeParser method createRootJavadocNode.

/**
     * Creates root JavadocNodeImpl node base on ParseTree root node.
     * @param parseTreeNode ParseTree root node
     * @return root Javadoc node
     */
private JavadocNodeImpl createRootJavadocNode(ParseTree parseTreeNode) {
    final JavadocNodeImpl rootJavadocNode = createJavadocNode(parseTreeNode, null, -1);
    final int childCount = parseTreeNode.getChildCount();
    final JavadocNodeImpl[] children = new JavadocNodeImpl[childCount];
    for (int i = 0; i < childCount; i++) {
        final JavadocNodeImpl child = createJavadocNode(parseTreeNode.getChild(i), rootJavadocNode, i);
        children[i] = child;
    }
    rootJavadocNode.setChildren((DetailNode[]) children);
    return rootJavadocNode;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode) JavadocNodeImpl(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)

Aggregations

JavadocNodeImpl (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNodeImpl)7 DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)5 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 Test (org.junit.Test)1