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.
-
-
Field Summary
Fields Modifier and Type Field Description static EnumeratedProperty<String>
VERSION_DESCRIPTOR
Deprecated.static StringProperty
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
apply(List<? extends Node> nodes, RuleContext ctx)
Apply this rule to the given collection of nodes, using the given context.Rule
deepCopy()
Creates a new copy of this rule.String
dysfunctionReason()
Returns a description of why the receiver may be dysfunctional.void
evaluate(Node node, RuleContext data)
Deprecated.List<String>
getRuleChainVisits()
Gets the collection of AST node names visited by the Rule on the RuleChain.XPathVersion
getVersion()
Returns the version for this rule.String
getXPathExpression()
Returns the XPath expression that implements this rule.void
setVersion(String version)
Deprecated.Use the constructorXPathRule(XPathVersion, String)
, don't set the version after the fact.void
setXPath(String xPath)
Deprecated.Use the constructorXPathRule(XPathVersion, String)
, don't set the expression after the fact.-
Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractRule
addExample, addRuleChainVisit, addRuleChainVisit, addViolation, addViolation, addViolation, addViolationWithMessage, addViolationWithMessage, addViolationWithMessage, asCtx, 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
@Deprecated public static final StringProperty XPATH_DESCRIPTOR
Deprecated.
-
VERSION_DESCRIPTOR
@Deprecated public static final EnumeratedProperty<String> VERSION_DESCRIPTOR
Deprecated.
-
-
Constructor Detail
-
XPathRule
public XPathRule()
Deprecated.Creates a new XPathRule without the corresponding XPath query.
-
XPathRule
public XPathRule(String xPath)
Deprecated.Creates a new XPathRule and associates the XPath query.
-
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.
-
setXPath
@Deprecated public void setXPath(String xPath)
Deprecated.Use the constructorXPathRule(XPathVersion, String)
, don't set the expression after the fact.
-
setVersion
@Deprecated public void setVersion(String version)
Deprecated.Use the constructorXPathRule(XPathVersion, String)
, don't set the version after the fact.
-
apply
public void apply(List<? extends Node> nodes, RuleContext ctx)
Description copied from interface:Rule
Apply this rule to the given collection of nodes, using the given context.- Parameters:
nodes
- the nodesctx
- the rule context
-
evaluate
@Deprecated public void evaluate(Node node, RuleContext data)
Deprecated.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 interfaceRule
- Overrides:
getRuleChainVisits
in classAbstractRule
- Returns:
- the list of AST node names
-
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 interfacePropertySource
- Overrides:
dysfunctionReason
in classAbstractPropertySource
- Returns:
- String
-
-