use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testJavadocCommentChild.
@Test
public void testJavadocCommentChild() {
final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final Object child = parseTree.getChild(commentContentNode, 0);
assertWithMessage("Invalid child type").that(child instanceof DetailNode).isTrue();
final int type = ((DetailNode) child).getType();
assertWithMessage("Invalid child token type").that(type).isEqualTo(JavadocTokenTypes.JAVADOC);
// get Child one more time to test cache of PModel
final Object childSame = parseTree.getChild(commentContentNode, 0);
assertWithMessage("Invalid child type").that(childSame instanceof DetailNode).isTrue();
final int sameType = ((DetailNode) childSame).getType();
assertWithMessage("Invalid child token type").that(sameType).isEqualTo(JavadocTokenTypes.JAVADOC);
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testJavadocChildCount.
@Test
public void testJavadocChildCount() {
final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final Object javadoc = parseTree.getChild(commentContentNode, 0);
assertWithMessage("Invalid child type").that(javadoc instanceof DetailNode).isTrue();
final int type = ((DetailNode) javadoc).getType();
assertWithMessage("Invalid child token type").that(type).isEqualTo(JavadocTokenTypes.JAVADOC);
final int javadocChildCount = parseTree.getChildCount(javadoc);
assertWithMessage("Invalid child count").that(javadocChildCount).isEqualTo(5);
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtilTest method testGetPreviousSibling.
@Test
public void testGetPreviousSibling() {
final JavadocNodeImpl root = new JavadocNodeImpl();
final JavadocNodeImpl node = new JavadocNodeImpl();
node.setIndex(1);
node.setParent(root);
final JavadocNodeImpl previousNode = new JavadocNodeImpl();
previousNode.setIndex(0);
node.setParent(root);
root.setChildren(previousNode, node);
final DetailNode previousSibling = JavadocUtil.getPreviousSibling(node);
assertWithMessage("Unexpected node").that(previousSibling).isEqualTo(previousNode);
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtilTest method testGetFirstToken.
@Test
public void testGetFirstToken() {
final JavadocNodeImpl javadocNode = new JavadocNodeImpl();
final JavadocNodeImpl basetag = new JavadocNodeImpl();
basetag.setType(JavadocTokenTypes.BASE_TAG);
final JavadocNodeImpl body = new JavadocNodeImpl();
body.setType(JavadocTokenTypes.BODY);
body.setParent(javadocNode);
basetag.setParent(javadocNode);
javadocNode.setChildren(basetag, body);
final DetailNode result = JavadocUtil.findFirstToken(javadocNode, JavadocTokenTypes.BODY);
assertWithMessage("Invalid first token").that(result).isEqualTo(body);
}
use of com.puppycrawl.tools.checkstyle.api.DetailNode in project checkstyle by checkstyle.
the class JavadocUtil 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;
}
Aggregations