use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class RootNodeTest method testXpath.
@Test
public void testXpath() throws Exception {
final String xpath = "/";
final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
assertWithMessage("Invalid number of nodes").that(nodes).hasSize(1);
final NodeInfo firstNode = nodes.get(0);
assertWithMessage("Should return true, because selected node is RootNode").that(firstNode instanceof RootNode).isTrue();
assertWithMessage("Result node should have same reference as expected").that(rootNode).isEqualTo(firstNode);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class FollowingIteratorTest method testFollowingSibling.
@Test
public void testFollowingSibling() {
final NodeInfo startNode = findNode("ANNOTATIONS");
try (FollowingIterator iterator = new FollowingIterator(startNode)) {
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("CLASS_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("RCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("SLIST"));
assertWithMessage("Node should be null").that(iterator.next()).isNull();
assertWithMessage("Node should be null").that(iterator.next()).isNull();
}
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testQuerySelf.
@Test
public void testQuerySelf() throws Exception {
final String objectXpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]//OBJBLOCK";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> objectNodes = getXpathItems(objectXpath, rootNode);
assertWithMessage("Invalid number of nodes").that(objectNodes).hasSize(1);
final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
final String methodsXpath = "self::OBJBLOCK";
final DetailAST[] actual = convertToArray(getXpathItems(methodsXpath, objNode));
final DetailAST expectedObjBlockNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.OBJBLOCK);
final DetailAST[] expected = { expectedObjBlockNode };
assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testQueryAllClassDefinitions.
@Test
public void testQueryAllClassDefinitions() throws Exception {
final String xpath = "/COMPILATION_UNIT/CLASS_DEF";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
assertWithMessage("Invalid number of nodes").that(nodes).hasSize(1);
final AbstractNode classDefNode = (AbstractNode) nodes.get(0);
assertWithMessage("Invalid line number").that(classDefNode.getLineNumber()).isEqualTo(3);
assertWithMessage("Invalid column number").that(classDefNode.getColumnNumber()).isEqualTo(0);
final DetailAST[] actual = convertToArray(nodes);
final DetailAST expectedClassDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF);
final DetailAST[] expected = { expectedClassDefNode };
assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class DescendantIteratorTest method testIncludeSelf.
@Test
public void testIncludeSelf() {
final NodeInfo startNode = findNode("CLASS_DEF");
try (DescendantIterator iterator = new DescendantIterator(startNode, DescendantIterator.StartWith.CURRENT_NODE)) {
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(startNode);
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("RCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("SLIST"));
assertWithMessage("Node should be null").that(iterator.next()).isNull();
assertWithMessage("Node should be null").that(iterator.next()).isNull();
}
}
Aggregations