use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class CheckUtilTest method testElseWithCurly.
@Test
public void testElseWithCurly() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.ASSIGN);
ast.setText("ASSIGN");
assertWithMessage("Invalid elseIf check result 'ASSIGN' is not 'else if'").that(CheckUtil.isElseIf(ast)).isFalse();
final DetailAstImpl parentAst = new DetailAstImpl();
parentAst.setType(TokenTypes.LCURLY);
parentAst.setText("LCURLY");
final DetailAstImpl ifAst = new DetailAstImpl();
ifAst.setType(TokenTypes.LITERAL_IF);
ifAst.setText("IF");
parentAst.addChild(ifAst);
assertWithMessage("Invalid elseIf check result: 'IF' is not 'else if'").that(CheckUtil.isElseIf(ifAst)).isFalse();
final DetailAstImpl parentAst2 = new DetailAstImpl();
parentAst2.setType(TokenTypes.SLIST);
parentAst2.setText("SLIST");
parentAst2.addChild(ifAst);
assertWithMessage("Invalid elseIf check result: 'SLIST' is not 'else if'").that(CheckUtil.isElseIf(ifAst)).isFalse();
final DetailAstImpl elseAst = new DetailAstImpl();
elseAst.setType(TokenTypes.LITERAL_ELSE);
elseAst.setFirstChild(ifAst);
assertWithMessage("Invalid elseIf check result").that(CheckUtil.isElseIf(ifAst)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class XpathUtilTest method testCreateChildren.
@Test
public void testCreateChildren() {
final DetailAstImpl rootAst = new DetailAstImpl();
final DetailAstImpl elementAst = new DetailAstImpl();
rootAst.addChild(elementAst);
final RootNode rootNode = new RootNode(rootAst);
final List<AbstractNode> children = XpathUtil.createChildren(rootNode, rootNode, elementAst);
assertWithMessage("Expected one child node").that(children).hasSize(1);
assertWithMessage("Node depth should be 1").that(children.get(0).getDepth()).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, String text) {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(type);
detailAST.setText(text);
return detailAST;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ElementNodeTest method testGetAttributeCached.
@Test
public void testGetAttributeCached() {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(TokenTypes.IDENT);
detailAST.setText("HelloWorld");
final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
try (AxisIterator first = elementNode.iterateAxis(AxisInfo.ATTRIBUTE);
AxisIterator second = elementNode.iterateAxis(AxisInfo.ATTRIBUTE)) {
assertWithMessage("Expected same attribute node").that(second.next()).isSameInstanceAs(first.next());
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ElementNodeTest method testGetAttributeValueNoAttribute.
@Test
public void testGetAttributeValueNoAttribute() {
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(TokenTypes.CLASS_DEF);
detailAST.setText("HelloWorld");
final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
assertWithMessage("Must be null").that(elementNode.getAttributeValue(null, "text")).isNull();
}
Aggregations