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;
}
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;
}
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;
}
Aggregations