Search in sources :

Example 41 with DetailNode

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

the class JavadocTagContinuationIndentationCheck method getAllNewlineNodes.

/**
 * Finds and collects all NEWLINE nodes inside DESCRIPTION node.
 *
 * @param descriptionNode DESCRIPTION node.
 * @return List with NEWLINE nodes.
 */
private static List<DetailNode> getAllNewlineNodes(DetailNode descriptionNode) {
    final List<DetailNode> textNodes = new ArrayList<>();
    DetailNode node = JavadocUtil.getFirstChild(descriptionNode);
    while (JavadocUtil.getNextSibling(node) != null) {
        if (node.getType() == JavadocTokenTypes.HTML_ELEMENT) {
            final DetailNode descriptionNodeChild = JavadocUtil.getFirstChild(node);
            textNodes.addAll(getAllNewlineNodes(descriptionNodeChild));
        }
        if (node.getType() == JavadocTokenTypes.LEADING_ASTERISK) {
            textNodes.add(node);
        }
        node = JavadocUtil.getNextSibling(node);
    }
    return textNodes;
}
Also used : ArrayList(java.util.ArrayList) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 42 with DetailNode

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

the class JavadocTagContinuationIndentationCheck method isInlineDescription.

/**
 * Checks, if description node is a description of in-line tag.
 *
 * @param description DESCRIPTION node.
 * @return true, if description node is a description of in-line tag.
 */
private static boolean isInlineDescription(DetailNode description) {
    boolean isInline = false;
    DetailNode inlineTag = description.getParent();
    while (inlineTag != null) {
        if (inlineTag.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG) {
            isInline = true;
            break;
        }
        inlineTag = inlineTag.getParent();
    }
    return isInline;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 43 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=
 * "https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadoctags">
 * JavadocTags</a>
 */
private boolean hasJavadocInlineTags(DetailNode javadocRoot) {
    DetailNode javadocTagSection = JavadocUtil.findFirstToken(javadocRoot, JavadocTokenTypes.JAVADOC_INLINE_TAG);
    boolean foundTag = false;
    while (javadocTagSection != null) {
        if (!isTagIgnored(javadocTagSection)) {
            foundTag = true;
            break;
        }
        javadocTagSection = JavadocUtil.getNextSibling(javadocTagSection, JavadocTokenTypes.JAVADOC_INLINE_TAG);
    }
    return foundTag;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 44 with DetailNode

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

the class RequireEmptyLineBeforeBlockTagGroupCheck method isOnlyTagInWholeJavadoc.

/**
 * Returns true when there are is only whitespace and asterisks before the provided tagNode.
 * When javadoc has only a javadoc tag like {@literal @} in it, the JAVADOC_TAG in a JAVADOC
 * detail node will always have 2 or 3 siblings before it. The parse tree looks like:
 * <pre>
 * JAVADOC[3x0]
 * |--NEWLINE[3x0] : [\n]
 * |--LEADING_ASTERISK[4x0] : [ *]
 * |--WS[4x2] : [ ]
 * |--JAVADOC_TAG[4x3] : [@param T The bar.\n ]
 * </pre>
 * Or it can also look like:
 * <pre>
 * JAVADOC[3x0]
 * |--NEWLINE[3x0] : [\n]
 * |--LEADING_ASTERISK[4x0] : [ *]
 * |--JAVADOC_TAG[4x3] : [@param T The bar.\n ]
 * </pre>
 * We do not include the variation
 * <pre>
 *  /**&#64;param noSpace there is no space here
 * </pre>
 * which results in the tree
 * <pre>
 * JAVADOC[3x0]
 * |--JAVADOC_TAG[4x3] : [@param noSpace there is no space here\n ]
 * </pre>
 * because this one is invalid. We must recommend placing a blank line to separate &#64;param
 * from the first javadoc asterisks.
 *
 * @param tagNode the at tag node to check if there is nothing before it.
 * @return true if there no text before the tagNode.
 */
private static boolean isOnlyTagInWholeJavadoc(DetailNode tagNode) {
    final List<Integer> previousNodeTypes = new ArrayList<>();
    DetailNode currentNode = JavadocUtil.getPreviousSibling(tagNode);
    while (currentNode != null) {
        previousNodeTypes.add(currentNode.getType());
        currentNode = JavadocUtil.getPreviousSibling(currentNode);
    }
    return ONLY_TAG_VARIATION_1.equals(previousNodeTypes) || ONLY_TAG_VARIATION_2.equals(previousNodeTypes);
}
Also used : ArrayList(java.util.ArrayList) DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 45 with DetailNode

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

the class RequireEmptyLineBeforeBlockTagGroupCheck method isAnotherTagBefore.

/**
 * Returns true when there is a javadoc tag before the provided tagNode.
 *
 * @param tagNode the javadoc tag node, to look for more tags before it.
 * @return true when there is a javadoc tag before the provided tagNode.
 */
private static boolean isAnotherTagBefore(DetailNode tagNode) {
    boolean found = false;
    DetailNode currentNode = JavadocUtil.getPreviousSibling(tagNode);
    while (currentNode != null) {
        if (currentNode.getType() == JavadocTokenTypes.JAVADOC_TAG) {
            found = true;
            break;
        }
        currentNode = JavadocUtil.getPreviousSibling(currentNode);
    }
    return found;
}
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