Package net.sourceforge.pmd
Interface Rule
-
- All Superinterfaces:
PropertySource
- All Known Subinterfaces:
CodeClimateRule
,DFAGraphRule
,StatisticalRule
- All Known Implementing Classes:
AbstractDelegateRule
,AbstractRule
,MockRule
,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 StringProperty
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
The property descriptor to universally suppress violations with messages matching a regular expression.static StringProperty
VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
Name of the property to universally suppress violations on nodes which match a given relative XPath expression.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addExample(String example)
Add a single example for this Rule.void
addRuleChainVisit(Class<? extends Node> nodeClass)
Adds an AST node by class to be visited by the Rule on the RuleChain.void
addRuleChainVisit(String astNodeName)
Adds an AST node by name to be visited by the Rule on the RuleChain.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.void
end(RuleContext ctx)
End processing.String
getDescription()
Get the description of this Rule.List<String>
getExamples()
Get the list of examples for this Rule.String
getExternalInfoUrl()
Get a URL for external information about this Rule.Language
getLanguage()
Get the Language of this Rule.LanguageVersion
getMaximumLanguageVersion()
Get the maximum LanguageVersion to which this Rule applies.String
getMessage()
Get the message to show when this Rule identifies a violation.LanguageVersion
getMinimumLanguageVersion()
Get the minimum LanguageVersion to which this Rule applies.String
getName()
Get the name of this Rule.ParserOptions
getParserOptions()
Deprecated.This was never implemented and will never be.RulePriority
getPriority()
Get the priority of this Rule.List<String>
getRuleChainVisits()
Gets the collection of AST node names visited by the Rule on the RuleChain.String
getRuleClass()
Get the implementation class of this Rule.String
getRuleSetName()
Get the name of the RuleSet containing this Rule.String
getSince()
Get the version of PMD in which this Rule was added.boolean
isDeprecated()
Gets whether this Rule is deprecated.boolean
isDfa()
Deprecated.Optional AST processing stages will be reified in 7.0.0 to factorise common logic.boolean
isMultifile()
Deprecated.Logic for multifile analysis is not implemented yet and probably won't be implemented this way.boolean
isRuleChain()
Gets whether this Rule uses the RuleChain.boolean
isTypeResolution()
Deprecated.Optional AST processing stages will be reified in 7.0.0 to factorise common logic.void
setDeprecated(boolean deprecated)
Sets whether this Rule is deprecated.void
setDescription(String description)
Set the description of this Rule.void
setDfa(boolean isDfa)
Deprecated.SeeisDfa()
void
setExternalInfoUrl(String externalInfoUrl)
Set a URL for external information about this Rule.void
setLanguage(Language language)
Set the Language of this Rule.void
setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)
Set the maximum LanguageVersion to which this Rule applies.void
setMessage(String message)
Set the message to show when this Rule identifies a violation.void
setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)
Set the minimum LanguageVersion to which this Rule applies.void
setMultifile(boolean multifile)
Deprecated.SeeisMultifile()
void
setName(String name)
Set the name of this Rule.void
setPriority(RulePriority priority)
Set the priority of this Rule.void
setRuleClass(String ruleClass)
Set the class of this Rule.void
setRuleSetName(String name)
Set the name of the RuleSet containing this Rule.void
setSince(String since)
Set the version of PMD in which this Rule was added.void
setTypeResolution(boolean usingTypeResolution)
Deprecated.void
setUsesDFA()
Deprecated.SeeisDfa()
void
setUsesMultifile()
Deprecated.SeeisMultifile()
void
setUsesTypeResolution()
Deprecated.void
start(RuleContext ctx)
Start processing.boolean
usesDFA()
Deprecated.SeeisDfa()
boolean
usesMultifile()
Deprecated.SeeisMultifile()
boolean
usesRuleChain()
Deprecated.USeisRuleChain()
instead.boolean
usesTypeResolution()
Deprecated.-
Methods inherited from interface net.sourceforge.pmd.properties.PropertySource
definePropertyDescriptor, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, setProperty, useDefaultValueFor, usesDefaultValues
-
-
-
-
Field Detail
-
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
static final StringProperty VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
The property descriptor to universally suppress violations with messages matching a regular expression.
-
VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
static final StringProperty 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 isnull
it 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 isnull
it 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:
true
if 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:
getName
in 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. Returnnull
if 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
-
getParserOptions
@Deprecated ParserOptions getParserOptions()
Deprecated.This was never implemented and will never be. PMD cannot parse files once per rule. Let this method assume its default by not overriding it.Get the parser options for this Rule. Parser options are used to configure theParser
to create an AST in the form the Rule is expecting. Because ParserOptions are mutable, a Rule should return a new instance on each call.- Returns:
- the parser options
-
setUsesDFA
@Deprecated void setUsesDFA()
Deprecated.SeeisDfa()
Sets whether this Rule uses Data Flow Analysis.
-
setDfa
@Deprecated void setDfa(boolean isDfa)
Deprecated.SeeisDfa()
Sets whether this Rule uses Data Flow Analysis.
-
usesDFA
@Deprecated boolean usesDFA()
Deprecated.SeeisDfa()
Gets whether this Rule uses Data Flow Analysis.- Returns:
true
if Data Flow Analysis is used.
-
isDfa
@Deprecated boolean isDfa()
Deprecated.Optional AST processing stages will be reified in 7.0.0 to factorise common logic. This method and the similar methods will be removed.Gets whether this Rule uses Data Flow Analysis.- Returns:
true
if Data Flow Analysis is used.
-
setUsesTypeResolution
@Deprecated void setUsesTypeResolution()
Deprecated.Sets whether this Rule uses Type Resolution.
-
setTypeResolution
@Deprecated void setTypeResolution(boolean usingTypeResolution)
Deprecated.Sets whether this Rule uses Type Resolution.
-
usesTypeResolution
@Deprecated boolean usesTypeResolution()
Deprecated.Gets whether this Rule uses Type Resolution.- Returns:
true
if Type Resolution is used.
-
isTypeResolution
@Deprecated boolean isTypeResolution()
Deprecated.Optional AST processing stages will be reified in 7.0.0 to factorise common logic. This method and the similar methods will be removed.Gets whether this Rule uses Type Resolution.- Returns:
true
if Type Resolution is used.
-
setUsesMultifile
@Deprecated void setUsesMultifile()
Deprecated.SeeisMultifile()
Sets whether this Rule uses multi-file analysis.
-
setMultifile
@Deprecated void setMultifile(boolean multifile)
Deprecated.SeeisMultifile()
Sets whether this Rule uses multi-file analysis.
-
usesMultifile
@Deprecated boolean usesMultifile()
Deprecated.SeeisMultifile()
Gets whether this Rule uses multi-file analysis.- Returns:
true
if the multi file analysis is used.
-
isMultifile
@Deprecated boolean isMultifile()
Deprecated.Logic for multifile analysis is not implemented yet and probably won't be implemented this way. Will be removed in 7.0.0.Gets whether this Rule uses multi-file analysis.- Returns:
true
if the multi file analysis is used.
-
usesRuleChain
@Deprecated boolean usesRuleChain()
Deprecated.USeisRuleChain()
instead.Gets whether this Rule uses the RuleChain.- Returns:
true
if RuleChain is used.
-
isRuleChain
boolean isRuleChain()
Gets whether this Rule uses the RuleChain.- Returns:
true
if RuleChain is used.
-
getRuleChainVisits
List<String> getRuleChainVisits()
Gets the collection of AST node names visited by the Rule on the RuleChain.- Returns:
- the list of AST node names
-
addRuleChainVisit
void addRuleChainVisit(Class<? extends Node> nodeClass)
Adds an AST node by class to be visited by the Rule on the RuleChain.- Parameters:
nodeClass
- the AST node to add to the RuleChain visit list
-
addRuleChainVisit
void addRuleChainVisit(String astNodeName)
Adds an AST node by name to be visited by the Rule on the RuleChain.- Parameters:
astNodeName
- the AST node to add to the RuleChain visit list as string
-
start
void start(RuleContext ctx)
Start processing. Called once, before apply() is first called.- Parameters:
ctx
- the rule context
-
apply
void apply(List<? extends Node> nodes, RuleContext ctx)
Apply this rule to the given collection of nodes, using the given context.- Parameters:
nodes
- the nodesctx
- the rule context
-
end
void end(RuleContext ctx)
End processing. Called once, 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
-
-