use of net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode in project pmd by pmd.
the class SaxonXPathRuleQuery method evaluate.
@Override
@SuppressWarnings("unchecked")
public List<Node> evaluate(final Node node, final RuleContext data) {
initializeXPathExpression();
try {
final DocumentNode documentNode = getDocumentNodeForRootNode(node);
// Map AST Node -> Saxon Node
final ElementNode rootElementNode = documentNode.nodeToElementNode.get(node);
final XPathDynamicContext xpathDynamicContext = createDynamicContext(rootElementNode);
final List<ElementNode> nodes = xpathExpression.evaluate(xpathDynamicContext);
/*
Map List of Saxon Nodes -> List of AST Nodes, which were detected to match the XPath expression
(i.e. violation found)
*/
final List<Node> results = new ArrayList<>();
for (final ElementNode elementNode : nodes) {
results.add((Node) elementNode.getUnderlyingNode());
}
return results;
} catch (final XPathException e) {
throw new RuntimeException(super.xpath + " had problem: " + e.getMessage(), e);
}
}
Aggregations