Search in sources :

Example 11 with DocumentNavigator

use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.

the class DocumentNavigatorTest method testPrecedingSiblingAxisIterator.

@Test
public void testPrecedingSiblingAxisIterator() {
    DocumentNavigator nav = new DocumentNavigator();
    Iterator<Node> iter = nav.getPrecedingSiblingAxisIterator(rule.primaryExpression.jjtGetChild(1));
    assertSame(rule.primaryExpression.jjtGetChild(0), iter.next());
    assertFalse(iter.hasNext());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 12 with DocumentNavigator

use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.

the class DocumentNavigatorTest method testChildAxisIterator.

@Test
public void testChildAxisIterator() {
    DocumentNavigator nav = new DocumentNavigator();
    Iterator<Node> iter = nav.getChildAxisIterator(rule.compilationUnit);
    assertSame(rule.compilationUnit.jjtGetChild(0), iter.next());
    assertSame(rule.compilationUnit.jjtGetChild(1), iter.next());
    assertFalse(iter.hasNext());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 13 with DocumentNavigator

use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.

the class DocumentNavigatorTest method testXPath.

@Test
public void testXPath() throws JaxenException {
    BaseXPath xPath = new BaseXPath(".//*", new DocumentNavigator());
    List<?> matches = xPath.selectNodes(rule.statement);
    assertEquals(6, matches.size());
}
Also used : BaseXPath(org.jaxen.BaseXPath) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Aggregations

DocumentNavigator (net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)13 Test (org.junit.Test)11 Node (net.sourceforge.pmd.lang.ast.Node)9 BaseXPath (org.jaxen.BaseXPath)3 ParseException (net.sourceforge.pmd.lang.ast.ParseException)1 Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)1 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)1 JaxenException (org.jaxen.JaxenException)1 XPath (org.jaxen.XPath)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1