Package net.sourceforge.pmd.lang.rule
Class XPathRule
- java.lang.Object
-
- net.sourceforge.pmd.properties.AbstractPropertySource
-
- net.sourceforge.pmd.lang.rule.AbstractRule
-
- net.sourceforge.pmd.lang.rule.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 Summary
Fields Modifier and Type Field Description static EnumeratedProperty<java.lang.String>
VERSION_DESCRIPTOR
static StringProperty
XPATH_DESCRIPTOR
-
Fields inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
propertyDescriptors, propertyValuesByDescriptor
-
Fields inherited from interface net.sourceforge.pmd.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(java.util.List<? extends Node> nodes, RuleContext ctx)
Apply the rule to all nodes.java.lang.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.java.util.List<java.lang.String>
getRuleChainVisits()
Gets the collection of AST node names visited by the Rule on the RuleChain.void
setVersion(java.lang.String version)
void
setXPath(java.lang.String xPath)
Sets the XPath to query against the desired nodes inapply(List, RuleContext)
.-
Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractRule
addExample, addRuleChainVisit, addRuleChainVisit, addViolation, addViolation, addViolation, addViolationWithMessage, addViolationWithMessage, addViolationWithMessage, deepCopy, deepCopyValuesTo, end, equals, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getParserOptions, getPriority, getPropertySourceType, getRuleClass, getRuleSetName, getSince, hashCode, isDeprecated, isDfa, isMultifile, isRuleChain, isTypeResolution, setDeprecated, setDescription, setDfa, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setMultifile, setName, setPriority, setRuleClass, setRuleSetName, setSince, setTypeResolution, setUsesDFA, setUsesMultifile, setUsesTypeResolution, start, usesDFA, usesMultifile, usesRuleChain, usesTypeResolution
-
Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, 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.properties.PropertySource
definePropertyDescriptor, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, setProperty, useDefaultValueFor, usesDefaultValues
-
-
-
-
Field Detail
-
XPATH_DESCRIPTOR
public static final StringProperty XPATH_DESCRIPTOR
-
VERSION_DESCRIPTOR
public static final EnumeratedProperty<java.lang.String> VERSION_DESCRIPTOR
-
-
Method Detail
-
setXPath
public void setXPath(java.lang.String xPath)
Sets the XPath to query against the desired nodes inapply(List, RuleContext)
.- Parameters:
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.- Parameters:
nodes
- the nodesctx
- 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.
-
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 interfaceRule
- Overrides:
getRuleChainVisits
in classAbstractRule
- Returns:
- 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 interfacePropertySource
- Overrides:
dysfunctionReason
in classAbstractPropertySource
- Returns:
- String
-
-