net.sourceforge.pmd.lang.rule

## Class XPathRule

- java.lang.Object
- - net.sourceforge.pmd.AbstractPropertySource
  - - net.sourceforge.pmd.lang.rule.AbstractRule
    - - net.sourceforge.pmd.lang.rule.XPathRule

All Implemented Interfaces:
  PropertySource, Rule

Direct Known Subclasses:
  EcmascriptXPathRule, XmlXPathRule

    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 Summary

Fields
`static EnumeratedProperty<String>` `VERSION_DESCRIPTOR`
`static StringProperty` `XPATH_DESCRIPTOR`

### Fields inherited from class net.sourceforge.pmd.AbstractPropertySource

`propertyDescriptors, propertyValuesByDescriptor`

### Fields inherited from interface net.sourceforge.pmd.Rule

`VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR`

### Constructor Summary

Constructors
Constructor and Description
`XPathRule()`
`XPathRule(String xPath)`

### Method Summary

Methods
`void` `apply(List<? extends Node> nodes, RuleContext ctx)` Apply the rule to all nodes.
`String` `dysfunctionReason()` Returns a description of why the receiver may be dysfunctional.
`void` `evaluate(Node node, RuleContext data)` Evaluate the XPath query with the AST node.
`List<String>` `getRuleChainVisits()` Gets the collection of AST node names visited by the Rule on the RuleChain.
`boolean` `hasXPathExpression()`
`void` `setVersion(String version)`
`void` `setXPath(String xPath)`

### Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractRule

`addExample, addRuleChainVisit, addRuleChainVisit, addViolation, addViolation, addViolation, addViolationWithMessage, addViolationWithMessage, addViolationWithMessage, deepCopyValuesTo, end, equals, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getParserOptions, getPriority, getRuleClass, getRuleSetName, getSince, hashCode, isDeprecated, setDeprecated, setDescription, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setName, setPriority, setRuleClass, setRuleSetName, setSince, setUsesDFA, setUsesTypeResolution, start, usesDFA, usesRuleChain, usesTypeResolution`

### Methods inherited from class net.sourceforge.pmd.AbstractPropertySource

`copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.sourceforge.pmd.PropertySource

`definePropertyDescriptor, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues`

### Field Detail

#### XPATH_DESCRIPTOR

    public static final StringProperty XPATH_DESCRIPTOR

#### VERSION_DESCRIPTOR

    public static final EnumeratedProperty<String> VERSION_DESCRIPTOR

### Constructor Detail

#### XPathRule

    public XPathRule()

#### XPathRule

    public XPathRule(String xPath)

### Method Detail

#### setXPath

    public void setXPath(String xPath)

#### setVersion

    public void setVersion(String version)

#### apply

    public void apply(List<? extends Node> nodes,
             RuleContext ctx)

Apply the rule to all nodes.

#### 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.

#### getRuleChainVisits

    public List<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`
Overrides:
  `getRuleChainVisits` in class `AbstractRule`
See Also:
  `Rule.getRuleChainVisits()`

#### hasXPathExpression

    public boolean hasXPathExpression()

#### dysfunctionReason

    public 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`
Overrides:
  `dysfunctionReason` in class `AbstractPropertySource`
Returns:
  String
See Also:
  `PropertySource.dysfunctionReason()`