Class XPathRule
- java.lang.Object
-
- net.sourceforge.pmd.properties.AbstractPropertySource
-
- net.sourceforge.pmd.lang.rule.AbstractRule
-
- net.sourceforge.pmd.lang.rule.xpath.XPathRule
-
- All Implemented Interfaces:
Rule
,PropertySource
public final class XPathRule extends AbstractRule
Rule that tries to match an XPath expression against a DOM view of an AST.
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.rule.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Constructor Summary
Constructors Constructor Description XPathRule(XPathVersion version, String expression)
Make a new XPath rule with the given version + expression
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(Node target, RuleContext ctx)
Process the given node.protected @NonNull RuleTargetSelector
buildTargetSelector()
Create the targeting strategy for this rule.Rule
deepCopy()
Creates a new copy of this rule.String
dysfunctionReason()
Returns a description of why the receiver may be dysfunctional.String
getXPathExpression()
Returns the XPath expression that implements this rule.void
initialize(LanguageProcessor languageProcessor)
Initialize the rule using the language processor if needed.-
Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractRule
addExample, asCtx, end, equals, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getPriority, getPropertySourceType, getRuleClass, getRuleSetName, getSince, getTargetSelector, hashCode, isDeprecated, setDeprecated, setDescription, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setName, setPriority, setRuleClass, setRuleSetName, setSince, start
-
Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
definePropertyDescriptor, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, isPropertyOverridden, setProperty
-
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, isPropertyOverridden, setProperty
-
-
-
-
Constructor Detail
-
XPathRule
public XPathRule(XPathVersion version, String expression)
Make a new XPath rule with the given version + expression- Parameters:
version
- Version of the XPath languageexpression
- XPath expression- Throws:
NullPointerException
- If any of the arguments is null
-
-
Method Detail
-
deepCopy
public Rule deepCopy()
Description copied from interface:Rule
Creates a new copy of this rule.- Specified by:
deepCopy
in interfaceRule
- Overrides:
deepCopy
in classAbstractRule
- Returns:
- A new exact copy of this rule
-
getXPathExpression
public String getXPathExpression()
Returns the XPath expression that implements this rule.
-
apply
public void apply(Node target, RuleContext ctx)
Description copied from interface:Rule
Process the given node. The nodes that are fed to this method are the nodes selected byRule.getTargetSelector()
.- Parameters:
target
- Node on which to apply the rulectx
- Rule context, handling violations
-
initialize
public void initialize(LanguageProcessor languageProcessor)
Description copied from interface:Rule
Initialize the rule using the language processor if needed.- Parameters:
languageProcessor
- The processor for the rule's language
-
buildTargetSelector
protected @NonNull RuleTargetSelector buildTargetSelector()
Description copied from class:AbstractRule
Create the targeting strategy for this rule. Use the factory methods ofRuleTargetSelector
.- Overrides:
buildTargetSelector
in classAbstractRule
-
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.- Returns:
- String
-
-