use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class ParseTreeTablePresentation method getJavadocTree.
/**
* Gets Javadoc (DetailNode) tree of specified block comments.
* @param blockComment Javadoc comment as a block comment
* @return DetailNode tree
*/
private DetailNode getJavadocTree(DetailAST blockComment) {
DetailNode javadocTree = blockCommentToJavadocTree.get(blockComment);
if (javadocTree == null) {
javadocTree = new JavadocDetailNodeParser().parseJavadocAsDetailNode(blockComment).getTree();
blockCommentToJavadocTree.put(blockComment, javadocTree);
}
return javadocTree;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtils method getPreviousSibling.
/**
* Gets previous sibling of specified node.
* @param node DetailNode
* @return previous sibling
*/
public static DetailNode getPreviousSibling(DetailNode node) {
final DetailNode parent = node.getParent();
final int previousSiblingIndex = node.getIndex() - 1;
final DetailNode[] children = parent.getChildren();
if (previousSiblingIndex >= 0) {
return children[previousSiblingIndex];
}
return null;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtils method findFirstToken.
/**
* Returns the first child token that has a specified type.
* @param detailNode
* Javadoc AST node
* @param type
* the token type to match
* @return the matching token, or null if no match
*/
public static DetailNode findFirstToken(DetailNode detailNode, int type) {
DetailNode returnValue = null;
DetailNode node = getFirstChild(detailNode);
while (node != null) {
if (node.getType() == type) {
returnValue = node;
break;
}
node = getNextSibling(node);
}
return returnValue;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class CodeSelectorPresentation method findLastPosition.
/**
* Finds the last position of node without children.
* @param detailNode DetailNode node.
* @return Last position of node without children.
*/
private int findLastPosition(final DetailNode detailNode) {
final int lastPosition;
if (detailNode.getChildren().length == 0) {
lastPosition = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber() + detailNode.getText().length();
} else {
final DetailNode lastChild = detailNode.getChildren()[detailNode.getChildren().length - 1];
lastPosition = findLastPosition(lastChild);
}
return lastPosition;
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class DetailNodeTreeStringPrinter method getIndentation.
/**
* Get indentation for a node.
* @param node the DetailNode to get the indentation for.
* @return the indentation in String format.
*/
private static String getIndentation(DetailNode node) {
final boolean isLastChild = JavadocUtils.getNextSibling(node) == null;
DetailNode currentNode = node;
final StringBuilder indentation = new StringBuilder();
while (currentNode.getParent() != null) {
currentNode = currentNode.getParent();
if (currentNode.getParent() == null) {
if (isLastChild) {
// only ASCII symbols must be used due to
// problems with running tests on Windows
indentation.append("`--");
} else {
indentation.append("|--");
}
} else {
if (JavadocUtils.getNextSibling(currentNode) == null) {
indentation.insert(0, " ");
} else {
indentation.insert(0, "| ");
}
}
}
return indentation.toString();
}
Aggregations