Search in sources :

Example 6 with DocumentNavigator

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

the class AbstractNode method appendElement.

protected void appendElement(org.w3c.dom.Node parentNode) {
    DocumentNavigator docNav = new DocumentNavigator();
    Document ownerDocument = parentNode.getOwnerDocument();
    if (ownerDocument == null) {
        // If the parentNode is a Document itself, it's ownerDocument is
        // null
        ownerDocument = (Document) parentNode;
    }
    String elementName = docNav.getElementName(this);
    Element element = ownerDocument.createElement(elementName);
    parentNode.appendChild(element);
    for (Iterator<Attribute> iter = docNav.getAttributeAxisIterator(this); iter.hasNext(); ) {
        Attribute attr = iter.next();
        element.setAttribute(attr.getName(), attr.getStringValue());
    }
    for (Iterator<Node> iter = docNav.getChildAxisIterator(this); iter.hasNext(); ) {
        AbstractNode child = (AbstractNode) iter.next();
        child.appendElement(element);
    }
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) Element(org.w3c.dom.Element) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Document(org.w3c.dom.Document) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)

Example 7 with DocumentNavigator

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

the class DocumentNavigatorTest method testXPath2.

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

Example 8 with DocumentNavigator

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

the class DocumentNavigatorTest method testParentAxisIterator.

@Test
public void testParentAxisIterator() {
    DocumentNavigator nav = new DocumentNavigator();
    Iterator<Node> iter = nav.getParentAxisIterator(rule.importDeclaration);
    assertSame(rule.importDeclaration.jjtGetParent(), 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 9 with DocumentNavigator

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

the class DocumentNavigatorTest method testParentAxisIterator2.

@Test
public void testParentAxisIterator2() {
    DocumentNavigator nav = new DocumentNavigator();
    Iterator<Node> iter = nav.getParentAxisIterator(rule.compilationUnit);
    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 10 with DocumentNavigator

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

the class DocumentNavigatorTest method testDescendantAxisIterator2.

@Test
public void testDescendantAxisIterator2() throws UnsupportedAxisException {
    DocumentNavigator nav = new DocumentNavigator();
    Iterator<?> iter = nav.getDescendantAxisIterator(rule.primaryPrefix);
    Node name = rule.primaryPrefix.jjtGetChild(0);
    assertSame(name, 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)

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