public interface Rule extends PropertySource
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.
Modifier and Type | Field and 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.
|
Modifier and Type | Method and 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.
|
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()
Get the parser options for this Rule.
|
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.
|
void |
setDeprecated(boolean deprecated)
Sets whether this Rule is deprecated.
|
void |
setDescription(String description)
Set the description of this Rule.
|
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 |
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 |
setUsesDFA()
Sets whether this Rule uses Data Flow Analysis.
|
void |
setUsesTypeResolution()
Sets whether this Rule uses Type Resolution.
|
void |
start(RuleContext ctx)
Start processing.
|
boolean |
usesDFA()
Gets whether this Rule uses Data Flow Analysis.
|
boolean |
usesRuleChain()
Gets whether this Rule uses the RuleChain.
|
boolean |
usesTypeResolution()
Gets whether this Rule uses Type Resolution.
|
definePropertyDescriptor, dysfunctionReason, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues
static final StringProperty VIOLATION_SUPPRESS_REGEX_DESCRIPTOR
static final StringProperty VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
Language getLanguage()
void setLanguage(Language language)
language
- the languageLanguageVersion getMinimumLanguageVersion()
null
it indicates there is no minimum bound.void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)
minimumLanguageVersion
- the minimum language versionLanguageVersion getMaximumLanguageVersion()
null
it indicates there is no maximum bound.void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)
maximumLanguageVersion
- the maximum language versionboolean isDeprecated()
true
if this rule is deprecatedvoid setDeprecated(boolean deprecated)
deprecated
- whether this rule is deprecatedString getName()
void setName(String name)
name
- the nameString getSince()
null
if not applicable.void setSince(String since)
since
- the version of PMD since when this rule was addedString getRuleClass()
void setRuleClass(String ruleClass)
ruleClass
- the class name of this rule.String getRuleSetName()
RuleSet
void setRuleSetName(String name)
name
- the name of the ruleset containing this rule.RuleSet
String getMessage()
void setMessage(String message)
message
- the message to show for a violation.String getDescription()
void setDescription(String description)
description
- the descriptionList<String> getExamples()
void addExample(String example)
example
- a single example to addString getExternalInfoUrl()
void setExternalInfoUrl(String externalInfoUrl)
externalInfoUrl
- the URL for external information about this rule.RulePriority getPriority()
void setPriority(RulePriority priority)
priority
- the priorityParserOptions getParserOptions()
Parser
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.void setUsesDFA()
boolean usesDFA()
true
if Data Flow Analysis is used.void setUsesTypeResolution()
boolean usesTypeResolution()
true
if Type Resolution is used.boolean usesRuleChain()
true
if RuleChain is used.List<String> getRuleChainVisits()
void addRuleChainVisit(Class<? extends Node> nodeClass)
nodeClass
- the AST node to add to the RuleChain visit listvoid addRuleChainVisit(String astNodeName)
astNodeName
- the AST node to add to the RuleChain visit list as stringvoid start(RuleContext ctx)
ctx
- the rule contextvoid apply(List<? extends Node> nodes, RuleContext ctx)
nodes
- the nodesctx
- the rule contextvoid end(RuleContext ctx)
ctx
- the rule contextCopyright © 2002–2017 PMD. All rights reserved.