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:
PropertySource,Rule
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 class net.sourceforge.pmd.properties.AbstractPropertySource
propertyDescriptors, propertyValuesByDescriptor
-
Fields inherited from interface net.sourceforge.pmd.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Constructor Summary
Constructors Constructor Description AbstractRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddExample(String example)Add a single example for this Rule.voidaddRuleChainVisit(Class<? extends Node> nodeClass)Adds an AST node by class to be visited by the Rule on the RuleChain.voidaddRuleChainVisit(String astNodeName)Adds an AST node by name to be visited by the Rule on the RuleChain.voidaddViolation(Object data, Node node)Deprecated.Replace withasCtx(data).addViolation(node).voidaddViolation(Object data, Node node, Object... args)Deprecated.Replace withasCtx(data).addViolation(node, arg1, arg2).voidaddViolation(Object data, Node node, String arg)Deprecated.Replace withasCtx(data).addViolation(node, arg).voidaddViolationWithMessage(Object data, Node node, String message)Deprecated.Replace withasCtx(data).addViolationWithMessage(node, message).voidaddViolationWithMessage(Object data, Node node, String message, int beginLine, int endLine)Deprecated.Replace withasCtx(data).addViolationWithPosition(node, beginLine, endLine, message).voidaddViolationWithMessage(Object data, Node node, String message, Object[] args)Deprecated.Replace withasCtx(data).addViolationWithMessage(node, message, args).protected RuleContextasCtx(Object ctx)Cast the argument to aRuleContext.RuledeepCopy()Creates a new copy of this rule.voiddeepCopyValuesTo(AbstractRule otherRule)Deprecated.UsedeepCopy()to create verbatim copies of rules.voidend(RuleContext ctx)End processing.booleanequals(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.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.ParserOptionsgetParserOptions()Deprecated.RulePrioritygetPriority()Get the priority of this Rule.protected StringgetPropertySourceType()List<String>getRuleChainVisits()Gets the collection of AST node names visited by the Rule on the RuleChain.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.inthashCode()booleanisDeprecated()Gets whether this Rule is deprecated.booleanisDfa()Gets whether this Rule uses Data Flow Analysis.booleanisMultifile()Gets whether this Rule uses multi-file analysis.booleanisRuleChain()Gets whether this Rule uses the RuleChain.booleanisTypeResolution()Gets whether this Rule uses Type Resolution.voidsetDeprecated(boolean deprecated)Sets whether this Rule is deprecated.voidsetDescription(String description)Set the description of this Rule.voidsetDfa(boolean isDfa)Sets whether this Rule uses Data Flow Analysis.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.voidsetMultifile(boolean multifile)Sets whether this Rule uses multi-file analysis.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 ruleSetName)Set the name of the RuleSet containing this Rule.voidsetSince(String since)Set the version of PMD in which this Rule was added.voidsetTypeResolution(boolean usingTypeResolution)Sets whether this Rule uses Type Resolution.voidsetUsesDFA()Deprecated.voidsetUsesMultifile()Deprecated.voidsetUsesTypeResolution()Deprecated.voidstart(RuleContext ctx)Start processing.booleanusesDFA()Deprecated.booleanusesMultifile()Deprecated.booleanusesRuleChain()Deprecated.booleanusesTypeResolution()Deprecated.-
Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, setProperty, useDefaultValueFor, usesDefaultValues
-
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, ignoredProperties, isPropertyOverridden, setProperty, setProperty, useDefaultValueFor, usesDefaultValues
-
-
-
-
Method Detail
-
getPropertySourceType
protected String getPropertySourceType()
- Specified by:
getPropertySourceTypein classAbstractPropertySource
-
deepCopyValuesTo
@Deprecated public void deepCopyValuesTo(AbstractRule otherRule)
Deprecated.UsedeepCopy()to create verbatim copies of rules.
-
getLanguage
public Language getLanguage()
Description copied from interface:RuleGet the Language of this Rule.- Specified by:
getLanguagein interfaceRule- Returns:
- the language
-
setLanguage
public void setLanguage(Language language)
Description copied from interface:RuleSet the Language of this Rule.- Specified by:
setLanguagein interfaceRule- Parameters:
language- the language
-
getMinimumLanguageVersion
public LanguageVersion 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
public void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)
Description copied from interface:RuleSet the minimum LanguageVersion to which this Rule applies.- Specified by:
setMinimumLanguageVersionin interfaceRule- Parameters:
minimumLanguageVersion- the minimum language version
-
getMaximumLanguageVersion
public LanguageVersion 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
public void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)
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
public String getName()
Description copied from interface:RuleGet the name of this Rule.- Specified by:
getNamein interfacePropertySource- Specified by:
getNamein interfaceRule- Returns:
- the name
-
setName
public void setName(String name)
Description copied from interface:RuleSet the name of this Rule.
-
getSince
public String getSince()
Description copied from interface:RuleGet the version of PMD in which this Rule was added. Returnnullif not applicable.
-
setSince
public void setSince(String since)
Description copied from interface:RuleSet the version of PMD in which this Rule was added.
-
getRuleClass
public String 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
public void setRuleClass(String ruleClass)
Description copied from interface:RuleSet the class of this Rule.- Specified by:
setRuleClassin interfaceRule- Parameters:
ruleClass- the class name of this rule.
-
getRuleSetName
public String 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:
RuleSet
-
setRuleSetName
public void setRuleSetName(String ruleSetName)
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:
RuleSet
-
getMessage
public String 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
public void setMessage(String message)
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
public String getDescription()
Description copied from interface:RuleGet the description of this Rule.- Specified by:
getDescriptionin interfaceRule- Returns:
- the description
-
setDescription
public void setDescription(String description)
Description copied from interface:RuleSet the description of this Rule.- Specified by:
setDescriptionin interfaceRule- Parameters:
description- the description
-
getExamples
public List<String> 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
public void addExample(String example)
Description copied from interface:RuleAdd a single example for this Rule.- Specified by:
addExamplein interfaceRule- Parameters:
example- a single example to add
-
getExternalInfoUrl
public String 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
public void setExternalInfoUrl(String externalInfoUrl)
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
public RulePriority getPriority()
Description copied from interface:RuleGet the priority of this Rule.- Specified by:
getPriorityin interfaceRule- Returns:
- the priority
-
setPriority
public void setPriority(RulePriority priority)
Description copied from interface:RuleSet the priority of this Rule.- Specified by:
setPriorityin interfaceRule- Parameters:
priority- the priority
-
getParserOptions
@Deprecated public ParserOptions getParserOptions()
Deprecated.This implementation returns a new instance ofParserOptionsusing default settings.- Specified by:
getParserOptionsin interfaceRule- Returns:
- the parser options
- See Also:
Rule.setPriority(RulePriority)
-
setUsesDFA
@Deprecated public void setUsesDFA()
Deprecated.Description copied from interface:RuleSets whether this Rule uses Data Flow Analysis.- Specified by:
setUsesDFAin interfaceRule
-
setDfa
public void setDfa(boolean isDfa)
Description copied from interface:RuleSets whether this Rule uses Data Flow Analysis.
-
usesDFA
@Deprecated public boolean usesDFA()
Deprecated.Description copied from interface:RuleGets whether this Rule uses Data Flow Analysis.
-
isDfa
public boolean isDfa()
Description copied from interface:RuleGets whether this Rule uses Data Flow Analysis.
-
setUsesTypeResolution
@Deprecated public void setUsesTypeResolution()
Deprecated.Description copied from interface:RuleSets whether this Rule uses Type Resolution.- Specified by:
setUsesTypeResolutionin interfaceRule
-
setTypeResolution
public void setTypeResolution(boolean usingTypeResolution)
Description copied from interface:RuleSets whether this Rule uses Type Resolution.- Specified by:
setTypeResolutionin interfaceRule
-
usesTypeResolution
@Deprecated public boolean usesTypeResolution()
Deprecated.Description copied from interface:RuleGets whether this Rule uses Type Resolution.- Specified by:
usesTypeResolutionin interfaceRule- Returns:
trueif Type Resolution is used.
-
isTypeResolution
public boolean isTypeResolution()
Description copied from interface:RuleGets whether this Rule uses Type Resolution.- Specified by:
isTypeResolutionin interfaceRule- Returns:
trueif Type Resolution is used.
-
setUsesMultifile
@Deprecated public void setUsesMultifile()
Deprecated.Description copied from interface:RuleSets whether this Rule uses multi-file analysis.- Specified by:
setUsesMultifilein interfaceRule
-
setMultifile
public void setMultifile(boolean multifile)
Description copied from interface:RuleSets whether this Rule uses multi-file analysis.- Specified by:
setMultifilein interfaceRule
-
usesMultifile
@Deprecated public boolean usesMultifile()
Deprecated.Description copied from interface:RuleGets whether this Rule uses multi-file analysis.- Specified by:
usesMultifilein interfaceRule- Returns:
trueif the multi file analysis is used.
-
isMultifile
public boolean isMultifile()
Description copied from interface:RuleGets whether this Rule uses multi-file analysis.- Specified by:
isMultifilein interfaceRule- Returns:
trueif the multi file analysis is used.
-
usesRuleChain
@Deprecated public boolean usesRuleChain()
Deprecated.Description copied from interface:RuleGets whether this Rule uses the RuleChain.- Specified by:
usesRuleChainin interfaceRule- Returns:
trueif RuleChain is used.
-
isRuleChain
public boolean isRuleChain()
Description copied from interface:RuleGets whether this Rule uses the RuleChain.- Specified by:
isRuleChainin interfaceRule- Returns:
trueif RuleChain is used.
-
getRuleChainVisits
public List<String> getRuleChainVisits()
Description copied from interface:RuleGets the collection of AST node names visited by the Rule on the RuleChain.- Specified by:
getRuleChainVisitsin interfaceRule- Returns:
- the list of AST node names
-
addRuleChainVisit
public void addRuleChainVisit(Class<? extends Node> nodeClass)
Description copied from interface:RuleAdds an AST node by class to be visited by the Rule on the RuleChain.- Specified by:
addRuleChainVisitin interfaceRule- Parameters:
nodeClass- the AST node to add to the RuleChain visit list
-
addRuleChainVisit
public void addRuleChainVisit(String astNodeName)
Description copied from interface:RuleAdds an AST node by name to be visited by the Rule on the RuleChain.- Specified by:
addRuleChainVisitin interfaceRule- Parameters:
astNodeName- the AST node to add to the RuleChain visit list as string
-
start
public void start(RuleContext ctx)
Description copied from interface:RuleStart processing. Called once, before apply() is first called.
-
end
public void end(RuleContext ctx)
Description copied from interface:RuleEnd processing. Called once, after apply() is last called.
-
asCtx
protected final RuleContext asCtx(Object ctx)
Cast the argument to aRuleContext. Use it to report violations:
In PMD 7, rules will have type-safe access to a RuleContext, and this will be deprecated as useless. In PMD 6, you can use this to stop using the deprecatedasCtx(data).addViolation(node); asCtx(data).addViolationWithMessage(node, "Some message");addViolation(Object, Node)overloads of this class.
-
addViolation
public void addViolation(Object data, Node node)
Deprecated.Replace withasCtx(data).addViolation(node).- See Also:
RuleContext.addViolation(Node)
-
addViolation
public void addViolation(Object data, Node node, String arg)
Deprecated.Replace withasCtx(data).addViolation(node, arg).- See Also:
RuleContext.addViolation(Node, Object[])
-
addViolation
public void addViolation(Object data, Node node, Object... args)
Deprecated.Replace withasCtx(data).addViolation(node, arg1, arg2).- See Also:
RuleContext.addViolation(Node, Object[])
-
addViolationWithMessage
public void addViolationWithMessage(Object data, Node node, String message)
Deprecated.Replace withasCtx(data).addViolationWithMessage(node, message).
-
addViolationWithMessage
public void addViolationWithMessage(Object data, Node node, String message, int beginLine, int endLine)
Deprecated.Replace withasCtx(data).addViolationWithPosition(node, beginLine, endLine, message).
-
addViolationWithMessage
public void addViolationWithMessage(Object data, Node node, String message, Object[] args)
Deprecated.Replace withasCtx(data).addViolationWithMessage(node, message, args).
-
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.
-
-