Search in sources :

Example 46 with DetailNode

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

the class RequireEmptyLineBeforeBlockTagGroupCheck method hasInsufficientConsecutiveNewlines.

/**
 * Returns true when there are not enough empty lines before the provided tagNode.
 *
 * <p>Iterates through the previous siblings of the tagNode looking for empty lines until
 * there are no more siblings or it hits something other than asterisk, whitespace or newline.
 * If it finds at least one empty line, return true. Return false otherwise.</p>
 *
 * @param tagNode the tagNode to check if there are sufficient empty lines before it.
 * @return true if there are not enough empty lines before the tagNode.
 */
private static boolean hasInsufficientConsecutiveNewlines(DetailNode tagNode) {
    int count = 0;
    DetailNode currentNode = JavadocUtil.getPreviousSibling(tagNode);
    while (count <= 1 && currentNode != null && (currentNode.getType() == JavadocTokenTypes.NEWLINE || currentNode.getType() == JavadocTokenTypes.WS || currentNode.getType() == JavadocTokenTypes.LEADING_ASTERISK)) {
        if (currentNode.getType() == JavadocTokenTypes.NEWLINE) {
            count++;
        }
        currentNode = JavadocUtil.getPreviousSibling(currentNode);
    }
    return count <= 1;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 47 with DetailNode

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

the class JavadocParagraphCheck method isFirstParagraph.

/**
 * Determines whether or not the line with paragraph tag is first line in javadoc.
 *
 * @param paragraphTag paragraph tag.
 * @return true, if line with paragraph tag is first line in javadoc.
 */
private static boolean isFirstParagraph(DetailNode paragraphTag) {
    boolean result = true;
    DetailNode previousNode = JavadocUtil.getPreviousSibling(paragraphTag);
    while (previousNode != null) {
        if (previousNode.getType() == JavadocTokenTypes.TEXT && !CommonUtil.isBlank(previousNode.getText()) || previousNode.getType() != JavadocTokenTypes.LEADING_ASTERISK && previousNode.getType() != JavadocTokenTypes.NEWLINE && previousNode.getType() != JavadocTokenTypes.TEXT) {
            result = false;
            break;
        }
        previousNode = JavadocUtil.getPreviousSibling(previousNode);
    }
    return result;
}
Also used : DetailNode(com.puppycrawl.tools.checkstyle.api.DetailNode)

Example 48 with DetailNode

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

the class JavadocParagraphCheck method getNearestEmptyLine.

/**
 * Finds and returns nearest empty line in javadoc.
 *
 * @param node DetailNode node.
 * @return Some nearest empty line in javadoc.
 */
private static DetailNode getNearestEmptyLine(DetailNode node) {
    DetailNode newLine = JavadocUtil.getPreviousSibling(node);
    while (newLine != null) {
        final DetailNode previousSibling = JavadocUtil.getPreviousSibling(newLine);
        if (newLine.getType() == JavadocTokenTypes.NEWLINE && isEmptyLine(newLine)) {
            break;
        }
        newLine = previousSibling;
    }
    return newLine;
}
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