Search in sources :

Example 6 with DetailNode

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

the class ParseTreeTablePresentation method getJavadocTree.

/**
     * Gets Javadoc (DetailNode) tree of specified block comments.
     * @param blockComment Javadoc comment as a block comment
     * @return DetailNode tree
     */
private DetailNode getJavadocTree(DetailAST blockComment) {
    DetailNode javadocTree = blockCommentToJavadocTree.get(blockComment);
    if (javadocTree == null) {
        javadocTree = new JavadocDetailNodeParser().parseJavadocAsDetailNode(blockComment).getTree();
        blockCommentToJavadocTree.put(blockComment, javadocTree);
    }
    return javadocTree;
}
Also used : JavadocDetailNodeParser(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 7 with DetailNode

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

the class JavadocUtils method getPreviousSibling.

/**
     * Gets previous sibling of specified node.
     * @param node DetailNode
     * @return previous sibling
     */
public static DetailNode getPreviousSibling(DetailNode node) {
    final DetailNode parent = node.getParent();
    final int previousSiblingIndex = node.getIndex() - 1;
    final DetailNode[] children = parent.getChildren();
    if (previousSiblingIndex >= 0) {
        return children[previousSiblingIndex];
    }
    return null;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 8 with DetailNode

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

the class JavadocUtils 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)

Example 9 with DetailNode

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

the class CodeSelectorPresentation method findLastPosition.

/**
     * Finds the last position of node without children.
     * @param detailNode DetailNode node.
     * @return Last position of node without children.
     */
private int findLastPosition(final DetailNode detailNode) {
    final int lastPosition;
    if (detailNode.getChildren().length == 0) {
        lastPosition = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber() + detailNode.getText().length();
    } else {
        final DetailNode lastChild = detailNode.getChildren()[detailNode.getChildren().length - 1];
        lastPosition = findLastPosition(lastChild);
    }
    return lastPosition;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 10 with DetailNode

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

the class DetailNodeTreeStringPrinter method getIndentation.

/**
     * Get indentation for a node.
     * @param node the DetailNode to get the indentation for.
     * @return the indentation in String format.
     */
private static String getIndentation(DetailNode node) {
    final boolean isLastChild = JavadocUtils.getNextSibling(node) == null;
    DetailNode currentNode = node;
    final StringBuilder indentation = new StringBuilder();
    while (currentNode.getParent() != null) {
        currentNode = currentNode.getParent();
        if (currentNode.getParent() == null) {
            if (isLastChild) {
                // only ASCII symbols must be used due to
                // problems with running tests on Windows
                indentation.append("`--");
            } else {
                indentation.append("|--");
            }
        } else {
            if (JavadocUtils.getNextSibling(currentNode) == null) {
                indentation.insert(0, "    ");
            } else {
                indentation.insert(0, "|   ");
            }
        }
    }
    return indentation.toString();
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

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