use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtil method getNextSibling.
/**
* Gets next sibling of specified node.
*
* @param node DetailNode
* @return next sibling.
*/
public static DetailNode getNextSibling(DetailNode node) {
DetailNode nextSibling = null;
final DetailNode parent = node.getParent();
if (parent != null) {
final int nextSiblingIndex = node.getIndex() + 1;
final DetailNode[] children = parent.getChildren();
if (nextSiblingIndex <= children.length - 1) {
nextSibling = children[nextSiblingIndex];
}
}
return nextSibling;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtil method containsInBranch.
/**
* Checks whether node contains any node of specified type among children on any deep level.
*
* @param node DetailNode
* @param type token type
* @return true if node contains any node of type type among children on any deep level.
*/
public static boolean containsInBranch(DetailNode node, int type) {
boolean result = true;
DetailNode curNode = node;
while (type != curNode.getType()) {
DetailNode toVisit = getFirstChild(curNode);
while (curNode != null && toVisit == null) {
toVisit = getNextSibling(curNode);
if (toVisit == null) {
curNode = curNode.getParent();
}
}
if (curNode == toVisit) {
result = false;
break;
}
curNode = toVisit;
}
return result;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocMetadataScraper method getTagTextFromProperty.
/**
* Get tag text from property data.
*
* @param nodeLi javadoc li item node
* @param propertyMeta property javadoc node
* @return property metadata text
*/
private static String getTagTextFromProperty(DetailNode nodeLi, DetailNode propertyMeta) {
final Optional<DetailNode> tagNodeOpt = getFirstChildOfType(nodeLi, JavadocTokenTypes.JAVADOC_INLINE_TAG, propertyMeta.getIndex() + 1);
DetailNode tagNode = null;
if (tagNodeOpt.isPresent()) {
tagNode = tagNodeOpt.get();
}
return getTextFromTag(tagNode);
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocMissingWhitespaceAfterAsteriskCheck method visitJavadocToken.
@Override
public void visitJavadocToken(DetailNode detailNode) {
final DetailNode textNode;
if (detailNode.getType() == JavadocTokenTypes.JAVADOC) {
textNode = JavadocUtil.getFirstChild(detailNode);
} else {
textNode = JavadocUtil.getNextSibling(detailNode);
}
if (textNode != null && textNode.getType() != JavadocTokenTypes.EOF) {
final String text = textNode.getText();
final int lastAsteriskPosition = getLastLeadingAsteriskPosition(text);
if (!isLast(lastAsteriskPosition, text) && !Character.isWhitespace(text.charAt(lastAsteriskPosition + 1))) {
log(textNode.getLineNumber(), textNode.getColumnNumber(), MSG_KEY);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocTagContinuationIndentationCheck method isViolation.
/**
* Checks if a text node meets the criteria for a violation.
* If the text is shorter than {@code offset} characters, then a violation is
* detected if the text is not blank or the next node is not a newline.
* If the text is longer than {@code offset} characters, then a violation is
* detected if any of the first {@code offset} characters are not blank.
*
* @param textNode the node to check.
* @return true if the node has a violation.
*/
private boolean isViolation(DetailNode textNode) {
boolean result = false;
final String text = textNode.getText();
if (text.length() <= offset) {
if (CommonUtil.isBlank(text)) {
final DetailNode nextNode = JavadocUtil.getNextSibling(textNode);
if (nextNode != null && nextNode.getType() != JavadocTokenTypes.NEWLINE) {
// text is blank but line hasn't ended yet
result = true;
}
} else {
// text is not blank
result = true;
}
} else if (!CommonUtil.isBlank(text.substring(1, offset + 1))) {
// first offset number of characters are not blank
result = true;
}
return result;
}
Aggregations