use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class XpathIteratorUtil method createTree.
/**
* Creates AST tree for iteration tests and returns root.
* <p>
* PACKAGE_DEF -> package [1:0]
* |--ANNOTATIONS -> ANNOTATIONS [1:8]
* `--ANNOTATION_DEF -> ANNOTATIONS [1:8]
* `--CLASS_DEF -> CLASS_DEF [3:0]
* `--OBJBLOCK -> OBJBLOCK [3:19]
* |--LCURLY -> { [3:19]
* |--METHOD_DEF -> METHOD_DEF [4:4]
* | |--PARAMETERS -> PARAMETERS [4:31]
* | `--SLIST -> { [4:33]
* `--RCURLY -> } [8:0]
* </p>
*
* @return {@link DetailAST} object.
*/
private static DetailAST createTree() {
final DetailAstImpl rootNode = createNode(TokenTypes.PACKAGE_DEF, 1, 0);
final DetailAstImpl annotationsNode = createNode(rootNode, TokenTypes.ANNOTATIONS, 1, 8);
createNode(annotationsNode, TokenTypes.ANNOTATION_DEF, 1, 8);
final DetailAstImpl classDefNode = createNode(rootNode, TokenTypes.CLASS_DEF, 3, 0);
final DetailAstImpl objblockNode = createNode(classDefNode, TokenTypes.OBJBLOCK, 3, 19);
createNode(objblockNode, TokenTypes.LCURLY, 3, 19);
final DetailAstImpl methodDefNode = createNode(objblockNode, TokenTypes.METHOD_DEF, 4, 4);
createNode(objblockNode, TokenTypes.RCURLY, 8, 0);
createNode(methodDefNode, TokenTypes.PARAMETERS, 4, 31);
createNode(methodDefNode, TokenTypes.SLIST, 4, 33);
return rootNode;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class XpathIteratorUtil method createNode.
/**
* Creates {@link DetailAstImpl} node with predefined parent.
*
* @param parent parent node
* @param tokenType token type, see {@link TokenTypes}
* @param lineNo line number
* @param columnNo column number
*
* @return {@link DetailAstImpl} object.
*/
private static DetailAstImpl createNode(DetailAstImpl parent, int tokenType, int lineNo, int columnNo) {
final DetailAstImpl result = createNode(tokenType, lineNo, columnNo);
parent.addChild(result);
return result;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testGetIndexOfChild.
@Test
public void testGetIndexOfChild() {
DetailAST ithChild = tree.getFirstChild();
assertWithMessage("Child must not be null").that(ithChild).isNotNull();
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
int index = 0;
while (ithChild != null) {
final int indexOfChild = parseTree.getIndexOfChild(tree, ithChild);
assertWithMessage("Invalid child index").that(indexOfChild).isEqualTo(index);
ithChild = ithChild.getNextSibling();
index++;
}
final int indexOfChild = parseTree.getIndexOfChild(tree, new DetailAstImpl());
assertWithMessage("Invalid child index").that(indexOfChild).isEqualTo(-1);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class XpathUtilTest method createDetailAST.
private static DetailAST createDetailAST(int type) {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(type);
return detailAST;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ElementNodeTest method testParentChildOrdering.
@Test
public void testParentChildOrdering() {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(TokenTypes.VARIABLE_DEF);
final DetailAstImpl parentAST = new DetailAstImpl();
parentAST.setFirstChild(detailAST);
parentAST.setType(TokenTypes.METHOD_DEF);
final AbstractNode parentNode = new ElementNode(rootNode, rootNode, parentAST, 1, 0);
final AbstractNode childNode = new ElementNode(rootNode, parentNode, detailAST, 2, 0);
assertWithMessage("Incorrect ordering value").that(parentNode.compareOrder(childNode)).isEqualTo(-1);
assertWithMessage("Incorrect ordering value").that(childNode.compareOrder(parentNode)).isEqualTo(1);
}
Aggregations