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.

    • Field Detail


        public static final StringProperty XPATH_DESCRIPTOR

        public static final EnumeratedProperty<java.lang.String> VERSION_DESCRIPTOR
    • Constructor Detail

      • XPathRule

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

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

      • setXPath

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

        public void setVersion​(java.lang.String version)
      • apply

        public void apply​(java.util.List<? extends Node> nodes,
                          RuleContext ctx)
        Apply the rule to all nodes.
        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.
        node - The Node that to be checked.
        data - The RuleContext.
      • getRuleChainVisits

        public java.util.List<java.lang.String> getRuleChainVisits()
        Description copied from interface: Rule
        Gets the collection of AST node names visited by the Rule on the RuleChain.
        Specified by:
        getRuleChainVisits in interface Rule
        getRuleChainVisits in class AbstractRule
        the list of AST node names
      • dysfunctionReason

        public java.lang.String dysfunctionReason()
        Description copied from interface: PropertySource
        Returns a description of why the receiver may be dysfunctional. Usually due to missing property values or some kind of conflict between values. Returns null if the receiver is ok.
        Specified by:
        dysfunctionReason in interface PropertySource
        dysfunctionReason in class AbstractPropertySource