use of net.sourceforge.pmd.util.CompoundIterator in project pmd by pmd.
the class XmlNodeWrapper method getAttributeIterator.
@Override
public Iterator<Attribute> getAttributeIterator() {
List<Iterator<Attribute>> iterators = new ArrayList<>();
// Expose DOM Attributes
final NamedNodeMap attributes = node.getAttributes();
iterators.add(new Iterator<Attribute>() {
private int index;
@Override
public boolean hasNext() {
return attributes != null && index < attributes.getLength();
}
@Override
public Attribute next() {
org.w3c.dom.Node attributeNode = attributes.item(index++);
return new Attribute(parser.wrapDomNode(node), attributeNode.getNodeName(), attributeNode.getNodeValue());
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
});
// Expose Text/CDATA nodes to have an 'Image' attribute like AST Nodes
if (node instanceof Text) {
iterators.add(Collections.singletonList(new Attribute(this, "Image", ((Text) node).getData())).iterator());
}
// Expose Java Attributes
// iterators.add(new AttributeAxisIterator((net.sourceforge.pmd.lang.ast.Node) p));
@SuppressWarnings("unchecked") Iterator<Attribute>[] it = (Iterator<Attribute>[]) new Iterator[iterators.size()];
return new CompoundIterator<>(iterators.toArray(it));
}
Aggregations