Search in sources :

Example 46 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testIdent.

@Test
public void testIdent() throws Exception {
    final String xpath = "//CLASS_DEF/IDENT[@text='InputXpathMapperAst']";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
    final DetailAST[] actual = convertToArray(nodes);
    final DetailAST expectedIdentNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.IDENT);
    final DetailAST[] expected = { expectedIdentNode };
    assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 47 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testQueryClassDefinitionByClassName.

@Test
public void testQueryClassDefinitionByClassName() throws Exception {
    final String xpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
    final DetailAST[] actual = convertToArray(nodes);
    final DetailAST expectedClassDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF);
    final DetailAST[] expected = { expectedClassDefNode };
    final ElementNode classDefNode = (ElementNode) nodes.get(0);
    assertWithMessage("Invalid node name").that(classDefNode.getLocalPart()).isEqualTo("CLASS_DEF");
    assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 48 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testNodeOrdering.

@Test
public void testNodeOrdering() throws Exception {
    final String xpath = "//METHOD_DEF/SLIST/*";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
    for (int i = 1; i < nodes.size(); i++) {
        final NodeInfo curr = nodes.get(i);
        final NodeInfo prev = nodes.get(i - 1);
        if (curr.getLineNumber() == prev.getLineNumber()) {
            assertWithMessage("Column number is not in document order").that(curr.getColumnNumber()).isGreaterThan(prev.getColumnNumber());
        } else {
            assertWithMessage("Line number is not in document order").that(curr.getLineNumber()).isGreaterThan(prev.getLineNumber());
        }
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Example 49 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class PrecedingIteratorTest method testPrecedingNodes.

@Test
public void testPrecedingNodes() {
    final NodeInfo startNode = findNode("SLIST");
    try (PrecedingIterator iterator = new PrecedingIterator(startNode)) {
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("CLASS_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ANNOTATIONS"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ANNOTATION_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PACKAGE_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ROOT"));
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Example 50 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class PrecedingIteratorTest method testNoSibling.

@Test
public void testNoSibling() {
    final NodeInfo startNode = findNode("ANNOTATIONS");
    try (PrecedingIterator iterator = new PrecedingIterator(startNode)) {
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PACKAGE_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ROOT"));
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Aggregations

NodeInfo (net.sf.saxon.om.NodeInfo)52 Test (org.junit.Test)21 XPathExpression (javax.xml.xpath.XPathExpression)16 Test (org.junit.jupiter.api.Test)14 Processor (net.sf.saxon.s9api.Processor)8 Configuration (net.sf.saxon.Configuration)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 NameTest (net.sf.saxon.pattern.NameTest)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)3 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)3 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Item (net.sf.saxon.om.Item)2 Serializer (net.sf.saxon.s9api.Serializer)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeList (org.w3c.dom.NodeList)2