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 voidapply(Node target, RuleContext ctx)Process the given node.protected @NonNull RuleTargetSelectorbuildTargetSelector()Create the targeting strategy for this rule.RuledeepCopy()Creates a new copy of this rule.StringdysfunctionReason()Returns a description of why the receiver may be dysfunctional.StringgetXPathExpression()Returns the XPath expression that implements this rule.voidinitialize(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:RuleCreates a new copy of this rule.- Specified by:
deepCopyin interfaceRule- Overrides:
deepCopyin 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:RuleProcess 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:RuleInitialize 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:AbstractRuleCreate the targeting strategy for this rule. Use the factory methods ofRuleTargetSelector.- Overrides:
buildTargetSelectorin classAbstractRule
-
dysfunctionReason
public String dysfunctionReason()
Description copied from interface:PropertySourceReturns 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
-
-