use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ElementNodeTest method testSiblingsOrdering.
@Test
public void testSiblingsOrdering() {
final DetailAstImpl detailAst1 = new DetailAstImpl();
detailAst1.setType(TokenTypes.VARIABLE_DEF);
final DetailAstImpl detailAst2 = new DetailAstImpl();
detailAst2.setType(TokenTypes.NUM_INT);
final DetailAstImpl parentAST = new DetailAstImpl();
parentAST.setType(TokenTypes.METHOD_DEF);
parentAST.addChild(detailAst1);
parentAST.addChild(detailAst2);
final AbstractNode parentNode = new ElementNode(rootNode, rootNode, parentAST, 1, 0);
final List<AbstractNode> children = parentNode.getChildren();
assertWithMessage("Incorrect ordering value").that(children.get(0).compareOrder(children.get(1))).isEqualTo(-1);
assertWithMessage("Incorrect ordering value").that(children.get(1).compareOrder(children.get(0))).isEqualTo(1);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ElementNodeTest method testIterateAxisWithChildren.
@Test
public void testIterateAxisWithChildren() {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(TokenTypes.METHOD_DEF);
final DetailAstImpl childAst = new DetailAstImpl();
childAst.setType(TokenTypes.VARIABLE_DEF);
detailAST.addChild(childAst);
final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.CHILD)) {
assertWithMessage("Invalid iterator").that(iterator instanceof ArrayIterator).isTrue();
}
try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.DESCENDANT)) {
assertWithMessage("Invalid iterator").that(iterator instanceof DescendantIterator).isTrue();
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ScopeUtilTest method getNode.
private static DetailAstImpl getNode(int... nodeTypes) {
DetailAstImpl ast = new DetailAstImpl();
ast.setType(nodeTypes[0]);
for (int i = 1; i < nodeTypes.length; i++) {
final DetailAstImpl astChild = new DetailAstImpl();
astChild.setType(nodeTypes[i]);
ast.addChild(astChild);
ast = astChild;
}
return ast;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ScopeUtilTest method testInRecordBlock.
@Test
public void testInRecordBlock() {
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(new DetailAstImpl())).isFalse();
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.LITERAL_NEW, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return true when passed is record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.OBJBLOCK, TokenTypes.RECORD_DEF, TokenTypes.MODIFIERS))).isTrue();
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.RECORD_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.RECORD_DEF, TokenTypes.ANNOTATION_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.RECORD_DEF, TokenTypes.ENUM_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not record").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.RECORD_DEF, TokenTypes.LITERAL_NEW, TokenTypes.IDENT))).isFalse();
assertWithMessage("Should return false when passed is not expected").that(ScopeUtil.isInRecordBlock(getNode(TokenTypes.PACKAGE_DEF, TokenTypes.DOT))).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ScopeUtilTest method testInClassBlock.
@Test
public void testInClassBlock() {
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(new DetailAstImpl())).isFalse();
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.LITERAL_NEW, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return true when passed is class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.OBJBLOCK, TokenTypes.CLASS_DEF, TokenTypes.MODIFIERS))).isTrue();
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.CLASS_DEF, TokenTypes.ANNOTATION_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.CLASS_DEF, TokenTypes.ENUM_DEF, TokenTypes.MODIFIERS))).isFalse();
assertWithMessage("Should return false when passed is not class").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.CLASS_DEF, TokenTypes.LITERAL_NEW, TokenTypes.IDENT))).isFalse();
assertWithMessage("Should return false when passed is not expected").that(ScopeUtil.isInClassBlock(getNode(TokenTypes.PACKAGE_DEF, TokenTypes.DOT))).isFalse();
}
Aggregations