use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class TypeOfFunction method call.
public Object call(Context context, List args) throws FunctionCallException {
String nodeTypeName = null;
String fullTypeName = null;
String shortTypeName = null;
Attribute attr = null;
for (int i = 0; i < args.size(); i++) {
if (args.get(i) instanceof List) {
if (attr == null) {
attr = ((List<Attribute>) args.get(i)).get(0);
nodeTypeName = attr.getStringValue();
} else {
throw new IllegalArgumentException("typeof function can take only a single argument which is an Attribute.");
}
} else {
if (fullTypeName == null) {
fullTypeName = (String) args.get(i);
} else if (shortTypeName == null) {
shortTypeName = (String) args.get(i);
} else {
break;
}
}
}
if (fullTypeName == null) {
throw new IllegalArgumentException("typeof function must be given at least one String argument for the fully qualified type name.");
}
Node n = (Node) context.getNodeSet().get(0);
return typeof(n, nodeTypeName, fullTypeName, shortTypeName);
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class MatchesFunctionTest method tryRegexp.
private Object tryRegexp(MyNode myNode, String exp) throws FunctionCallException, NoSuchMethodException {
MatchesFunction function = new MatchesFunction();
List<Object> list = new ArrayList<>();
List<Attribute> attrs = new ArrayList<>();
attrs.add(new Attribute(myNode, "matches", myNode.getClass().getMethod("getClassName", new Class[0])));
list.add(attrs);
list.add(exp);
Context c = new Context(null);
c.setNodeSet(new ArrayList<>());
return function.call(c, list);
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class AttributesSubMenu method init.
private void init() {
AttributeAxisIterator i = new AttributeAxisIterator(node);
while (i.hasNext()) {
Attribute attribute = i.next();
add(new XPathFragmentAddingItem(attribute.getName() + " = " + attribute.getValue(), model, AttributeToolkit.constructPredicate(attribute)));
}
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.
the class DumpFacade method dump.
private void dump(XmlNode node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
image = StringUtil.escapeWhitespace(image);
// Extras
List<String> extras = new ArrayList<>();
Iterator<Attribute> iterator = node.getAttributeIterator();
while (iterator.hasNext()) {
Attribute attribute = iterator.next();
extras.add(attribute.getName() + "=" + StringUtil.escapeWhitespace(attribute.getValue()));
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
use of net.sourceforge.pmd.lang.ast.xpath.Attribute 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