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,UnnecessaryPmdSuppressionRule,XPathRule
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExample(String example) Add a single example for this Rule.protected final RuleContextCast the argument to aRuleContext.protected @NonNull RuleTargetSelectorCreate the targeting strategy for this rule.deepCopy()Creates a new copy of this rule.Returns a description of why the receiver may be dysfunctional.voidend(RuleContext ctx) End processing.booleanRules are equal if: They have the same implementation class. They have the same name. They have the same priority. They share the same properties.Get the description of this Rule.Get the list of examples for this Rule.Get a URL for external information about this Rule.Get the Language of this Rule.Get the maximum LanguageVersion to which this Rule applies.Get the message to show when this Rule identifies a violation.Get the minimum LanguageVersion to which this Rule applies.getName()Get the name of this Rule.Get the priority of this Rule.protected StringGet the implementation class of this Rule.Get the name of the RuleSet containing this Rule.getSince()Get the version of PMD in which this Rule was added.final RuleTargetSelectorReturns the object that selects the nodes to which this rule applies.inthashCode()booleanGets 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.voidSet 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 ruleSetName) Set the name of the RuleSet containing this Rule.voidSet the version of PMD in which this Rule was added.voidstart(RuleContext ctx) Start processing.Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
definePropertyDescriptor, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, isPropertyOverridden, setPropertyMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.sourceforge.pmd.properties.PropertySource
definePropertyDescriptor, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, isPropertyOverridden, setPropertyMethods inherited from interface net.sourceforge.pmd.lang.rule.Rule
apply, initialize
-
Constructor Details
-
AbstractRule
public AbstractRule()
-
-
Method Details
-
getPropertySourceType
- Specified by:
getPropertySourceTypein classAbstractPropertySource
-
getLanguage
Description copied from interface:RuleGet the Language of this Rule.- Specified by:
getLanguagein interfaceRule- Returns:
- the language
-
setLanguage
Description copied from interface:RuleSet the Language of this Rule.- Specified by:
setLanguagein interfaceRule- Parameters:
language- the language
-
getMinimumLanguageVersion
Description copied from interface:RuleGet the minimum LanguageVersion to which this Rule applies. If this value isnullit indicates there is no minimum bound.- Specified by:
getMinimumLanguageVersionin interfaceRule- Returns:
- the minimum language version
-
setMinimumLanguageVersion
Description copied from interface:RuleSet the minimum LanguageVersion to which this Rule applies.- Specified by:
setMinimumLanguageVersionin interfaceRule- Parameters:
minimumLanguageVersion- the minimum language version
-
getMaximumLanguageVersion
Description copied from interface:RuleGet the maximum LanguageVersion to which this Rule applies. If this value isnullit indicates there is no maximum bound.- Specified by:
getMaximumLanguageVersionin interfaceRule- Returns:
- the maximum language version
-
setMaximumLanguageVersion
Description copied from interface:RuleSet the maximum LanguageVersion to which this Rule applies.- Specified by:
setMaximumLanguageVersionin interfaceRule- Parameters:
maximumLanguageVersion- the maximum language version
-
isDeprecated
public boolean isDeprecated()Description copied from interface:RuleGets 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:
isDeprecatedin interfaceRule- Returns:
trueif this rule is deprecated
-
setDeprecated
public void setDeprecated(boolean deprecated) Description copied from interface:RuleSets whether this Rule is deprecated.- Specified by:
setDeprecatedin interfaceRule- Parameters:
deprecated- whether this rule is deprecated
-
getName
Description copied from interface:RuleGet the name of this Rule.- Specified by:
getNamein interfacePropertySource- Specified by:
getNamein interfaceRule- Returns:
- the name
-
setName
Description copied from interface:RuleSet the name of this Rule. -
getSince
Description copied from interface:RuleGet the version of PMD in which this Rule was added. Returnnullif not applicable. -
setSince
Description copied from interface:RuleSet the version of PMD in which this Rule was added. -
getRuleClass
Description copied from interface:RuleGet the implementation class of this Rule.- Specified by:
getRuleClassin interfaceRule- Returns:
- the implementation class name of this rule.
-
setRuleClass
Description copied from interface:RuleSet the class of this Rule.- Specified by:
setRuleClassin interfaceRule- Parameters:
ruleClass- the class name of this rule.
-
getRuleSetName
Description copied from interface:RuleGet the name of the RuleSet containing this Rule.- Specified by:
getRuleSetNamein interfaceRule- Returns:
- the name of th ruleset containing this rule.
- See Also:
-
setRuleSetName
Description copied from interface:RuleSet the name of the RuleSet containing this Rule.- Specified by:
setRuleSetNamein interfaceRule- Parameters:
ruleSetName- the name of the ruleset containing this rule.- See Also:
-
getMessage
Description copied from interface:RuleGet the message to show when this Rule identifies a violation.- Specified by:
getMessagein interfaceRule- Returns:
- the message to show for a violation.
-
setMessage
Description copied from interface:RuleSet the message to show when this Rule identifies a violation.- Specified by:
setMessagein interfaceRule- Parameters:
message- the message to show for a violation.
-
getDescription
Description copied from interface:RuleGet the description of this Rule.- Specified by:
getDescriptionin interfaceRule- Returns:
- the description
-
setDescription
Description copied from interface:RuleSet the description of this Rule.- Specified by:
setDescriptionin interfaceRule- Parameters:
description- the description
-
getExamples
Description copied from interface:RuleGet the list of examples for this Rule.- Specified by:
getExamplesin interfaceRule- Returns:
- the list of examples for this rule.
-
addExample
Description copied from interface:RuleAdd a single example for this Rule.- Specified by:
addExamplein interfaceRule- Parameters:
example- a single example to add
-
getExternalInfoUrl
Description copied from interface:RuleGet a URL for external information about this Rule.- Specified by:
getExternalInfoUrlin interfaceRule- Returns:
- the URL for external information about this rule.
-
setExternalInfoUrl
Description copied from interface:RuleSet a URL for external information about this Rule.- Specified by:
setExternalInfoUrlin interfaceRule- Parameters:
externalInfoUrl- the URL for external information about this rule.
-
getPriority
Description copied from interface:RuleGet the priority of this Rule.- Specified by:
getPriorityin interfaceRule- Returns:
- the priority
-
setPriority
Description copied from interface:RuleSet the priority of this Rule.- Specified by:
setPriorityin interfaceRule- Parameters:
priority- the priority
-
getTargetSelector
Description copied from interface:RuleReturns the object that selects the nodes to which this rule applies. The selected nodes will be handed toRule.apply(Node, RuleContext).- Specified by:
getTargetSelectorin interfaceRule
-
buildTargetSelector
Create the targeting strategy for this rule. Use the factory methods ofRuleTargetSelector. -
start
Description copied from interface:RuleStart processing. Called once per file, before apply() is first called. -
end
Description copied from interface:RuleEnd processing. Called once per file, after apply() is last called. -
asCtx
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");RuleContextin rules. -
equals
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:
equalsin classAbstractPropertySource
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractPropertySource
-
deepCopy
Description copied from interface:RuleCreates a new copy of this rule. -
dysfunctionReason
Description copied from interface:PropertySourceReturns 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:
dysfunctionReasonin interfacePropertySource- Returns:
- String
-