Package net.sourceforge.pmd
Interface Rule
-
- All Superinterfaces:
PropertySource
- All Known Implementing Classes:
AbstractDelegateRule,AbstractRule,AbstractVisitorRule,RuleReference,XPathRule
public interface Rule extends PropertySource
This is the basic Rule interface for PMD rules.Thread safety: PMD will create one instance of a rule per thread. The instances are not shared across different threads. However, a single rule instance is reused for analyzing multiple files.
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyDescriptor<Optional<Pattern>>VIOLATION_SUPPRESS_REGEX_DESCRIPTORThe property descriptor to universally suppress violations with messages matching a regular expression.static PropertyDescriptor<Optional<String>>VIOLATION_SUPPRESS_XPATH_DESCRIPTORName of the property to universally suppress violations on nodes which match a given relative XPath expression.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddExample(String example)Add a single example for this Rule.voidapply(Node target, RuleContext ctx)Process the given node.RuledeepCopy()Creates a new copy of this rule.voidend(RuleContext ctx)End processing.StringgetDescription()Get the description of this Rule.List<String>getExamples()Get the list of examples for this Rule.StringgetExternalInfoUrl()Get a URL for external information about this Rule.LanguagegetLanguage()Get the Language of this Rule.LanguageVersiongetMaximumLanguageVersion()Get the maximum LanguageVersion to which this Rule applies.StringgetMessage()Get the message to show when this Rule identifies a violation.LanguageVersiongetMinimumLanguageVersion()Get the minimum LanguageVersion to which this Rule applies.StringgetName()Get the name of this Rule.RulePrioritygetPriority()Get the priority of this Rule.StringgetRuleClass()Get the implementation class of this Rule.StringgetRuleSetName()Get the name of the RuleSet containing this Rule.StringgetSince()Get the version of PMD in which this Rule was added.RuleTargetSelectorgetTargetSelector()Returns the object that selects the nodes to which this rule applies.default voidinitialize(LanguageProcessor languageProcessor)Initialize the rule using the language processor if needed.booleanisDeprecated()Gets whether this Rule is deprecated.voidsetDeprecated(boolean deprecated)Sets whether this Rule is deprecated.voidsetDescription(String description)Set the description of this Rule.voidsetExternalInfoUrl(String externalInfoUrl)Set a URL for external information about this Rule.voidsetLanguage(Language language)Set the Language of this Rule.voidsetMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)Set the maximum LanguageVersion to which this Rule applies.voidsetMessage(String message)Set the message to show when this Rule identifies a violation.voidsetMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)Set the minimum LanguageVersion to which this Rule applies.voidsetName(String name)Set the name of this Rule.voidsetPriority(RulePriority priority)Set the priority of this Rule.voidsetRuleClass(String ruleClass)Set the class of this Rule.voidsetRuleSetName(String name)Set the name of the RuleSet containing this Rule.voidsetSince(String since)Set the version of PMD in which this Rule was added.voidstart(RuleContext ctx)Start processing.-
Methods inherited from interface net.sourceforge.pmd.properties.PropertySource
definePropertyDescriptor, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, isPropertyOverridden, setProperty
-
-
-
-
Field Detail
-
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
static final PropertyDescriptor<Optional<Pattern>> VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
The property descriptor to universally suppress violations with messages matching a regular expression.
-
VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
static final PropertyDescriptor<Optional<String>> VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
Name of the property to universally suppress violations on nodes which match a given relative XPath expression.
-
-
Method Detail
-
getLanguage
Language getLanguage()
Get the Language of this Rule.- Returns:
- the language
-
setLanguage
void setLanguage(Language language)
Set the Language of this Rule.- Parameters:
language- the language
-
getMinimumLanguageVersion
LanguageVersion getMinimumLanguageVersion()
Get the minimum LanguageVersion to which this Rule applies. If this value isnullit indicates there is no minimum bound.- Returns:
- the minimum language version
-
setMinimumLanguageVersion
void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)
Set the minimum LanguageVersion to which this Rule applies.- Parameters:
minimumLanguageVersion- the minimum language version
-
getMaximumLanguageVersion
LanguageVersion getMaximumLanguageVersion()
Get the maximum LanguageVersion to which this Rule applies. If this value isnullit indicates there is no maximum bound.- Returns:
- the maximum language version
-
setMaximumLanguageVersion
void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)
Set the maximum LanguageVersion to which this Rule applies.- Parameters:
maximumLanguageVersion- the maximum language version
-
isDeprecated
boolean isDeprecated()
Gets whether this Rule is deprecated. A deprecated Rule is one which:- is scheduled for removal in a future version of PMD
- or, has been removed and replaced with a non-functioning place-holder and will be completely removed in a future version of PMD
- or, has been renamed/moved and the old name will be completely removed in a future version of PMD
- Returns:
trueif this rule is deprecated
-
setDeprecated
void setDeprecated(boolean deprecated)
Sets whether this Rule is deprecated.- Parameters:
deprecated- whether this rule is deprecated
-
getName
String getName()
Get the name of this Rule.- Specified by:
getNamein interfacePropertySource- Returns:
- the name
-
setName
void setName(String name)
Set the name of this Rule.- Parameters:
name- the name
-
getSince
String getSince()
Get the version of PMD in which this Rule was added. Returnnullif not applicable.- Returns:
- version of PMD since when this rule was added
-
setSince
void setSince(String since)
Set the version of PMD in which this Rule was added.- Parameters:
since- the version of PMD since when this rule was added
-
getRuleClass
String getRuleClass()
Get the implementation class of this Rule.- Returns:
- the implementation class name of this rule.
-
setRuleClass
void setRuleClass(String ruleClass)
Set the class of this Rule.- Parameters:
ruleClass- the class name of this rule.
-
getRuleSetName
String getRuleSetName()
Get the name of the RuleSet containing this Rule.- Returns:
- the name of th ruleset containing this rule.
- See Also:
RuleSet
-
setRuleSetName
void setRuleSetName(String name)
Set the name of the RuleSet containing this Rule.- Parameters:
name- the name of the ruleset containing this rule.- See Also:
RuleSet
-
getMessage
String getMessage()
Get the message to show when this Rule identifies a violation.- Returns:
- the message to show for a violation.
-
setMessage
void setMessage(String message)
Set the message to show when this Rule identifies a violation.- Parameters:
message- the message to show for a violation.
-
getDescription
String getDescription()
Get the description of this Rule.- Returns:
- the description
-
setDescription
void setDescription(String description)
Set the description of this Rule.- Parameters:
description- the description
-
getExamples
List<String> getExamples()
Get the list of examples for this Rule.- Returns:
- the list of examples for this rule.
-
addExample
void addExample(String example)
Add a single example for this Rule.- Parameters:
example- a single example to add
-
getExternalInfoUrl
String getExternalInfoUrl()
Get a URL for external information about this Rule.- Returns:
- the URL for external information about this rule.
-
setExternalInfoUrl
void setExternalInfoUrl(String externalInfoUrl)
Set a URL for external information about this Rule.- Parameters:
externalInfoUrl- the URL for external information about this rule.
-
getPriority
RulePriority getPriority()
Get the priority of this Rule.- Returns:
- the priority
-
setPriority
void setPriority(RulePriority priority)
Set the priority of this Rule.- Parameters:
priority- the priority
-
getTargetSelector
RuleTargetSelector getTargetSelector()
Returns the object that selects the nodes to which this rule applies. The selected nodes will be handed toapply(Node, RuleContext).
-
initialize
default void initialize(LanguageProcessor languageProcessor)
Initialize the rule using the language processor if needed.- Parameters:
languageProcessor- The processor for the rule's language
-
start
void start(RuleContext ctx)
Start processing. Called once per file, before apply() is first called.- Parameters:
ctx- the rule context
-
apply
void apply(Node target, RuleContext ctx)
Process the given node. The nodes that are fed to this method are the nodes selected bygetTargetSelector().- Parameters:
target- Node on which to apply the rulectx- Rule context, handling violations
-
end
void end(RuleContext ctx)
End processing. Called once per file, after apply() is last called.- Parameters:
ctx- the rule context
-
deepCopy
Rule deepCopy()
Creates a new copy of this rule.- Returns:
- A new exact copy of this rule
-
-