use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class XmlParserTest method assertNode.
/**
* Asserts a single node inclusive attributes.
*
* @param node
* the node
* @param toString
* the to String representation to expect
* @param childs
* number of childs
* @param atts
* attributes - each object pair forms one attribute: first name,
* then value.
*/
private void assertNode(Node node, String toString, int childs, Object... atts) {
Assert.assertEquals(toString, String.valueOf(node));
Assert.assertEquals(childs, node.jjtGetNumChildren());
Iterator<Attribute> attributeIterator = ((XmlNode) node).getAttributeIterator();
if (atts != null) {
for (int i = 0; i < atts.length; i += 2) {
Assert.assertTrue(attributeIterator.hasNext());
String name = String.valueOf(atts[i]);
Object value = atts[i + 1];
Attribute attribute = attributeIterator.next();
Assert.assertEquals(name, attribute.getName());
Assert.assertEquals(value, attribute.getValue());
}
}
Assert.assertFalse(attributeIterator.hasNext());
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class MatchesFunction method call.
@Override
public Object call(Context context, List args) throws FunctionCallException {
if (args.isEmpty()) {
return Boolean.FALSE;
}
List attributes = (List) args.get(0);
Attribute attr = (Attribute) attributes.get(0);
for (int i = 1; i < args.size(); i++) {
Pattern check = Pattern.compile((String) args.get(i));
Matcher matcher = check.matcher(attr.getStringValue());
if (matcher.find()) {
return context.getNodeSet();
}
}
return Boolean.FALSE;
}
Aggregations