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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations