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;
}
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;
}
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;
}
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>
* /**@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 @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);
}
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;
}
Aggregations