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 final class XPathRule extends AbstractRule
Rule that tries to match an XPath expression against a DOM view of an AST.
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyDescriptor<XPathVersion>
VERSION_DESCRIPTOR
Deprecated.static PropertyDescriptor<String>
XPATH_DESCRIPTOR
Deprecated.-
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
-
-
Constructor Summary
Constructors Constructor Description XPathRule()
Deprecated.This is now only used by the ruleset loader.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.XPathVersion
getVersion()
Returns the version for this rule.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, addRuleChainVisit, addViolation, addViolation, addViolation, addViolationWithMessage, addViolationWithMessage, addViolationWithMessage, asCtx, deepCopyValuesTo, 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
copyPropertyDescriptors, copyPropertyValues, 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
-
-
-
-
Field Detail
-
XPATH_DESCRIPTOR
@Deprecated public static final PropertyDescriptor<String> XPATH_DESCRIPTOR
Deprecated.
-
VERSION_DESCRIPTOR
@Deprecated public static final PropertyDescriptor<XPathVersion> VERSION_DESCRIPTOR
Deprecated.
-
-
Constructor Detail
-
XPathRule
@Deprecated public XPathRule()
Deprecated.This is now only used by the ruleset loader. When we have syntactic sugar for XPath rules in the XML, we won't need this anymore.
-
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
-
getVersion
public XPathVersion getVersion()
Returns the version for this rule. Returns null if this is not set or invalid.
-
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. Please override this instead of usingAbstractRule.addRuleChainVisit(Class)
. 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
-
-