Package net.sourceforge.pmd.lang.rule
Class AbstractRule
- java.lang.Object
-
- net.sourceforge.pmd.properties.AbstractPropertySource
-
- net.sourceforge.pmd.lang.rule.AbstractRule
-
- All Implemented Interfaces:
Rule
,PropertySource
- Direct Known Subclasses:
AbstractVisitorRule
,XPathRule
public abstract class AbstractRule extends AbstractPropertySource implements Rule
Basic abstract implementation of all parser-independent methods of the Rule interface.- Author:
- pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.rule.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Constructor Summary
Constructors Constructor Description AbstractRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExample(String example)
Add a single example for this Rule.protected RuleContext
asCtx(Object ctx)
Cast the argument to aRuleContext
.protected @NonNull RuleTargetSelector
buildTargetSelector()
Create the targeting strategy for this rule.Rule
deepCopy()
Creates a new copy of this rule.void
end(RuleContext ctx)
End processing.boolean
equals(Object o)
Rules are equal if: They have the same implementation class. They have the same name. They have the same priority. They share the same properties.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.RulePriority
getPriority()
Get the priority of this Rule.protected String
getPropertySourceType()
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.RuleTargetSelector
getTargetSelector()
Returns the object that selects the nodes to which this rule applies.int
hashCode()
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 ruleSetName)
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
start(RuleContext ctx)
Start processing.-
Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
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, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, isPropertyOverridden, setProperty
-
Methods inherited from interface net.sourceforge.pmd.lang.rule.Rule
apply, initialize
-
-
-
-
Method Detail
-
getPropertySourceType
protected String getPropertySourceType()
- Specified by:
getPropertySourceType
in classAbstractPropertySource
-
getLanguage
public Language getLanguage()
Description copied from interface:Rule
Get the Language of this Rule.- Specified by:
getLanguage
in interfaceRule
- Returns:
- the language
-
setLanguage
public void setLanguage(Language language)
Description copied from interface:Rule
Set the Language of this Rule.- Specified by:
setLanguage
in interfaceRule
- Parameters:
language
- the language
-
getMinimumLanguageVersion
public LanguageVersion getMinimumLanguageVersion()
Description copied from interface:Rule
Get the minimum LanguageVersion to which this Rule applies. If this value isnull
it indicates there is no minimum bound.- Specified by:
getMinimumLanguageVersion
in interfaceRule
- Returns:
- the minimum language version
-
setMinimumLanguageVersion
public void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)
Description copied from interface:Rule
Set the minimum LanguageVersion to which this Rule applies.- Specified by:
setMinimumLanguageVersion
in interfaceRule
- Parameters:
minimumLanguageVersion
- the minimum language version
-
getMaximumLanguageVersion
public LanguageVersion getMaximumLanguageVersion()
Description copied from interface:Rule
Get the maximum LanguageVersion to which this Rule applies. If this value isnull
it indicates there is no maximum bound.- Specified by:
getMaximumLanguageVersion
in interfaceRule
- Returns:
- the maximum language version
-
setMaximumLanguageVersion
public void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)
Description copied from interface:Rule
Set the maximum LanguageVersion to which this Rule applies.- Specified by:
setMaximumLanguageVersion
in interfaceRule
- Parameters:
maximumLanguageVersion
- the maximum language version
-
isDeprecated
public boolean isDeprecated()
Description copied from interface:Rule
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
- Specified by:
isDeprecated
in interfaceRule
- Returns:
true
if this rule is deprecated
-
setDeprecated
public void setDeprecated(boolean deprecated)
Description copied from interface:Rule
Sets whether this Rule is deprecated.- Specified by:
setDeprecated
in interfaceRule
- Parameters:
deprecated
- whether this rule is deprecated
-
getName
public String getName()
Description copied from interface:Rule
Get the name of this Rule.- Specified by:
getName
in interfacePropertySource
- Specified by:
getName
in interfaceRule
- Returns:
- the name
-
setName
public void setName(String name)
Description copied from interface:Rule
Set the name of this Rule.
-
getSince
public String getSince()
Description copied from interface:Rule
Get the version of PMD in which this Rule was added. Returnnull
if not applicable.
-
setSince
public void setSince(String since)
Description copied from interface:Rule
Set the version of PMD in which this Rule was added.
-
getRuleClass
public String getRuleClass()
Description copied from interface:Rule
Get the implementation class of this Rule.- Specified by:
getRuleClass
in interfaceRule
- Returns:
- the implementation class name of this rule.
-
setRuleClass
public void setRuleClass(String ruleClass)
Description copied from interface:Rule
Set the class of this Rule.- Specified by:
setRuleClass
in interfaceRule
- Parameters:
ruleClass
- the class name of this rule.
-
getRuleSetName
public String getRuleSetName()
Description copied from interface:Rule
Get the name of the RuleSet containing this Rule.- Specified by:
getRuleSetName
in interfaceRule
- Returns:
- the name of th ruleset containing this rule.
- See Also:
RuleSet
-
setRuleSetName
public void setRuleSetName(String ruleSetName)
Description copied from interface:Rule
Set the name of the RuleSet containing this Rule.- Specified by:
setRuleSetName
in interfaceRule
- Parameters:
ruleSetName
- the name of the ruleset containing this rule.- See Also:
RuleSet
-
getMessage
public String getMessage()
Description copied from interface:Rule
Get the message to show when this Rule identifies a violation.- Specified by:
getMessage
in interfaceRule
- Returns:
- the message to show for a violation.
-
setMessage
public void setMessage(String message)
Description copied from interface:Rule
Set the message to show when this Rule identifies a violation.- Specified by:
setMessage
in interfaceRule
- Parameters:
message
- the message to show for a violation.
-
getDescription
public String getDescription()
Description copied from interface:Rule
Get the description of this Rule.- Specified by:
getDescription
in interfaceRule
- Returns:
- the description
-
setDescription
public void setDescription(String description)
Description copied from interface:Rule
Set the description of this Rule.- Specified by:
setDescription
in interfaceRule
- Parameters:
description
- the description
-
getExamples
public List<String> getExamples()
Description copied from interface:Rule
Get the list of examples for this Rule.- Specified by:
getExamples
in interfaceRule
- Returns:
- the list of examples for this rule.
-
addExample
public void addExample(String example)
Description copied from interface:Rule
Add a single example for this Rule.- Specified by:
addExample
in interfaceRule
- Parameters:
example
- a single example to add
-
getExternalInfoUrl
public String getExternalInfoUrl()
Description copied from interface:Rule
Get a URL for external information about this Rule.- Specified by:
getExternalInfoUrl
in interfaceRule
- Returns:
- the URL for external information about this rule.
-
setExternalInfoUrl
public void setExternalInfoUrl(String externalInfoUrl)
Description copied from interface:Rule
Set a URL for external information about this Rule.- Specified by:
setExternalInfoUrl
in interfaceRule
- Parameters:
externalInfoUrl
- the URL for external information about this rule.
-
getPriority
public RulePriority getPriority()
Description copied from interface:Rule
Get the priority of this Rule.- Specified by:
getPriority
in interfaceRule
- Returns:
- the priority
-
setPriority
public void setPriority(RulePriority priority)
Description copied from interface:Rule
Set the priority of this Rule.- Specified by:
setPriority
in interfaceRule
- Parameters:
priority
- the priority
-
getTargetSelector
public final RuleTargetSelector getTargetSelector()
Description copied from interface:Rule
Returns the object that selects the nodes to which this rule applies. The selected nodes will be handed toRule.apply(Node, RuleContext)
.- Specified by:
getTargetSelector
in interfaceRule
-
buildTargetSelector
protected @NonNull RuleTargetSelector buildTargetSelector()
Create the targeting strategy for this rule. Use the factory methods ofRuleTargetSelector
.
-
start
public void start(RuleContext ctx)
Description copied from interface:Rule
Start processing. Called once per file, before apply() is first called.
-
end
public void end(RuleContext ctx)
Description copied from interface:Rule
End processing. Called once per file, after apply() is last called.
-
asCtx
protected final RuleContext asCtx(Object ctx)
Cast the argument to aRuleContext
. Use it to report violations:
In longer term, rules will have type-safe access to a RuleContext, when the rules use an appropriate visitor. Many rules have not been refactored yet. Once this is done, this method will be deprecated as useless. Until then, this is a way to hide the explicit cast toasCtx(data).addViolation(node); asCtx(data).addViolationWithMessage(node, "Some message");
RuleContext
in rules.
-
equals
public boolean equals(Object o)
Rules are equal if:- They have the same implementation class.
- They have the same name.
- They have the same priority.
- They share the same properties.
- Overrides:
equals
in classAbstractPropertySource
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractPropertySource
-
-