use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class AttributeTest method testConstructor.
@Test
public void testConstructor() {
DummyNode p = new DummyNode(1);
p.testingOnlySetBeginLine(5);
Method[] methods = p.getClass().getMethods();
Method m = null;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals("getBeginLine")) {
m = methods[i];
break;
}
}
Attribute a = new Attribute(p, "BeginLine", m);
assertEquals("BeginLine", a.getName());
assertEquals(5, a.getValue());
assertEquals("5", a.getStringValue());
assertEquals(p, a.getParent());
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class NodeInfoPanelController method getAttributes.
/**
* Gets the XPath attributes of the node for display within a listview.
*/
private static ObservableList<String> getAttributes(Node node) {
ObservableList<String> result = FXCollections.observableArrayList();
AttributeAxisIterator attributeAxisIterator = new AttributeAxisIterator(node);
while (attributeAxisIterator.hasNext()) {
Attribute attribute = attributeAxisIterator.next();
result.add(attribute.getName() + " = " + ((attribute.getValue() != null) ? attribute.getStringValue() : "null"));
}
if (node instanceof TypeNode) {
result.add("typeof() = " + ((TypeNode) node).getType());
}
Collections.sort(result);
return result;
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class XmlParserTest method assertTextNode.
/**
* Assert a single text node.
*
* @param node
* the node to check
* @param text
* the text to expect
* @param toString
* the to string representation
*/
private void assertTextNode(Node node, String text, String toString) {
Assert.assertEquals(toString, String.valueOf(node));
Assert.assertEquals(0, node.jjtGetNumChildren());
Assert.assertEquals(text, StringUtil.escapeWhitespace(node.getImage()));
Iterator<Attribute> attributeIterator = ((XmlNode) node).getAttributeIterator();
Assert.assertTrue(attributeIterator.hasNext());
Attribute attribute = attributeIterator.next();
Assert.assertEquals("Image", attribute.getName());
Assert.assertEquals(text, StringUtil.escapeWhitespace(attribute.getValue()));
Assert.assertFalse(attributeIterator.hasNext());
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute 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.Attribute in project pmd by pmd.
the class AttributeAxisIterator method advance.
@Override
public void advance() {
if (this.iterator.hasNext()) {
Attribute attribute = this.iterator.next();
super.current = new AttributeNode(attribute, super.position());
} else {
super.current = null;
}
}
Aggregations