Class XPathRule

  • All Implemented Interfaces:
    PropertySource, Rule

    public class XPathRule
    extends AbstractRule
    Rule that tries to match an XPath expression against a DOM view of an AST.

    This rule needs a "xpath" property value in order to function.

    • Constructor Detail

      • XPathRule

        public XPathRule()
        Creates a new XPathRule without the corresponding XPath query.
      • XPathRule

        public XPathRule​(String xPath)
        Creates a new XPathRule and associates the XPath query.
    • Method Detail

      • setXPath

        public void setXPath​(String xPath)
        Sets the XPath to query against the desired nodes in apply(List, RuleContext).
        Parameters:
        xPath - the XPath query
      • setVersion

        public void setVersion​(String version)
      • apply

        public void apply​(List<? extends Node> nodes,
                          RuleContext ctx)
        Apply the rule to all nodes.
        Parameters:
        nodes - the nodes
        ctx - the rule context
      • evaluate

        public void evaluate​(Node node,
                             RuleContext data)
        Evaluate the XPath query with the AST node. All matches are reported as violations.
        Parameters:
        node - The Node that to be checked.
        data - The RuleContext.