net.sourceforge.pmd.lang.rule

## Class AbstractRule

- java.lang.Object
- - net.sourceforge.pmd.AbstractPropertySource
  - - net.sourceforge.pmd.lang.rule.AbstractRule

All Implemented Interfaces:
  PropertySource, Rule

Direct Known Subclasses:
  AbstractEcmascriptRule, AbstractJavaRule, AbstractJspRule, AbstractXmlRule, MockRule, 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 class net.sourceforge.pmd.AbstractPropertySource

`propertyDescriptors, propertyValuesByDescriptor`

### Fields inherited from interface net.sourceforge.pmd.Rule

`VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR`

### Constructor Summary

Constructors
Constructor and Description
`AbstractRule()`

### Method Summary

Methods
`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` `addViolation(Object data, Node node)`
`void` `addViolation(Object data, Node node, Object[] args)`
`void` `addViolation(Object data, Node node, String arg)`
`void` `addViolationWithMessage(Object data, Node node, String message)`
`void` `addViolationWithMessage(Object data, Node node, String message, int beginLine, int endLine)`
`void` `addViolationWithMessage(Object data, Node node, String message, Object[] args)`
`void` `deepCopyValuesTo(AbstractRule otherRule)`
`void` `end(RuleContext ctx)` End processing.
`boolean` `equals(Object o)` Rules are equal if: They have the same implementation class.
`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()` This implementation returns a new instance of `ParserOptions` using default settings.
`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 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.
`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` `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.

### Methods inherited from class net.sourceforge.pmd.AbstractPropertySource

`copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, dysfunctionReason, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, 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.Rule

`apply`

### Methods inherited from interface net.sourceforge.pmd.PropertySource

`definePropertyDescriptor, dysfunctionReason, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues`

### Constructor Detail

#### AbstractRule

    public AbstractRule()

### Method Detail

#### deepCopyValuesTo

    public void deepCopyValuesTo(AbstractRule otherRule)

#### getLanguage

    public Language getLanguage()

Description copied from interface: `Rule`
Get the Language of this Rule.

Specified by:
  `getLanguage` in interface `Rule`
See Also:
  `Rule.getLanguage()`

#### setLanguage

    public void setLanguage(Language language)

Description copied from interface: `Rule`
Set the Language of this Rule.

Specified by:
  `setLanguage` in interface `Rule`
See Also:
  `Rule.setLanguage(Language)`

#### getMinimumLanguageVersion

    public LanguageVersion getMinimumLanguageVersion()

Description copied from interface: `Rule`
Get the minimum LanguageVersion to which this Rule applies. If this value is `null` it indicates there is no minimum bound.

Specified by:
  `getMinimumLanguageVersion` in interface `Rule`
See Also:
  `Rule.getMinimumLanguageVersion()`

#### setMinimumLanguageVersion

    public void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion)

Description copied from interface: `Rule`
Set the minimum LanguageVersion to which this Rule applies.

Specified by:
  `setMinimumLanguageVersion` in interface `Rule`
See Also:
  `Rule.setMinimumLanguageVersion(LanguageVersion)`

#### getMaximumLanguageVersion

    public LanguageVersion getMaximumLanguageVersion()

Description copied from interface: `Rule`
Get the maximum LanguageVersion to which this Rule applies. If this value is `null` it indicates there is no maximum bound.

Specified by:
  `getMaximumLanguageVersion` in interface `Rule`
See Also:
  `Rule.getMaximumLanguageVersion()`

#### setMaximumLanguageVersion

    public void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion)

Description copied from interface: `Rule`
Set the maximum LanguageVersion to which this Rule applies.

Specified by:
  `setMaximumLanguageVersion` in interface `Rule`
See Also:
  `Rule.setMaximumLanguageVersion(LanguageVersion)`

#### 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 interface `Rule`
See Also:
  `Rule.isDeprecated()`

#### setDeprecated

    public void setDeprecated(boolean deprecated)

Description copied from interface: `Rule`
Sets whether this Rule is deprecated.

Specified by:
  `setDeprecated` in interface `Rule`
See Also:
  `Rule.setDeprecated(boolean)`

#### getName

    public String getName()

Description copied from interface: `Rule`
Get the name of this Rule.

Specified by:
  `getName` in interface `Rule`
Specified by:
  `getName` in class `AbstractPropertySource`
See Also:
  `Rule.getName()`

#### setName

    public void setName(String name)

Description copied from interface: `Rule`
Set the name of this Rule.

Specified by:
  `setName` in interface `Rule`
See Also:
  `Rule.setName(String)`

#### getSince

    public String getSince()

Description copied from interface: `Rule`
Get the version of PMD in which this Rule was added. Return `null` if not applicable.

Specified by:
  `getSince` in interface `Rule`
See Also:
  `Rule.getSince()`

#### setSince

    public void setSince(String since)

Description copied from interface: `Rule`
Set the version of PMD in which this Rule was added.

Specified by:
  `setSince` in interface `Rule`
See Also:
  `Rule.setSince(String)`

#### getRuleClass

    public String getRuleClass()

Description copied from interface: `Rule`
Get the class of this Rule.

Specified by:
  `getRuleClass` in interface `Rule`
See Also:
  `Rule.getRuleClass()`

#### setRuleClass

    public void setRuleClass(String ruleClass)

Description copied from interface: `Rule`
Set the class of this Rule.

Specified by:
  `setRuleClass` in interface `Rule`
See Also:
  `Rule.setRuleClass(String)`

#### getRuleSetName

    public String getRuleSetName()

Description copied from interface: `Rule`
Get the name of the RuleSet containing this Rule.

Specified by:
  `getRuleSetName` in interface `Rule`
See Also:
  `Rule.getRuleSetName()`

#### setRuleSetName

    public void setRuleSetName(String ruleSetName)

Description copied from interface: `Rule`
Set the name of the RuleSet containing this Rule.

Specified by:
  `setRuleSetName` in interface `Rule`
See Also:
  `Rule.setRuleSetName(String)`

#### getMessage

    public String getMessage()

Description copied from interface: `Rule`
Get the message to show when this Rule identifies a violation.

Specified by:
  `getMessage` in interface `Rule`
See Also:
  `Rule.getMessage()`

#### 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 interface `Rule`
See Also:
  `Rule.setMessage(String)`

#### getDescription

    public String getDescription()

Description copied from interface: `Rule`
Get the description of this Rule.

Specified by:
  `getDescription` in interface `Rule`
See Also:
  `Rule.getDescription()`

#### setDescription

    public void setDescription(String description)

Description copied from interface: `Rule`
Set the description of this Rule.

Specified by:
  `setDescription` in interface `Rule`
See Also:
  `Rule.setDescription(String)`

#### getExamples

    public List<String> getExamples()

Description copied from interface: `Rule`
Get the list of examples for this Rule.

Specified by:
  `getExamples` in interface `Rule`
See Also:
  `Rule.getExamples()`

#### addExample

    public void addExample(String example)

Description copied from interface: `Rule`
Add a single example for this Rule.

Specified by:
  `addExample` in interface `Rule`
See Also:
  `Rule.addExample(String)`

#### getExternalInfoUrl

    public String getExternalInfoUrl()

Description copied from interface: `Rule`
Get a URL for external information about this Rule.

Specified by:
  `getExternalInfoUrl` in interface `Rule`
See Also:
  `Rule.getExternalInfoUrl()`

#### setExternalInfoUrl

    public void setExternalInfoUrl(String externalInfoUrl)

Description copied from interface: `Rule`
Set a URL for external information about this Rule.

Specified by:
  `setExternalInfoUrl` in interface `Rule`
See Also:
  `Rule.setExternalInfoUrl(String)`

#### getPriority

    public RulePriority getPriority()

Description copied from interface: `Rule`
Get the priority of this Rule.

Specified by:
  `getPriority` in interface `Rule`
See Also:
  `Rule.getPriority()`

#### setPriority

    public void setPriority(RulePriority priority)

Description copied from interface: `Rule`
Set the priority of this Rule.

Specified by:
  `setPriority` in interface `Rule`
See Also:
  `Rule.setPriority(RulePriority)`

#### getParserOptions

    public ParserOptions getParserOptions()

This implementation returns a new instance of `ParserOptions` using default settings.

Specified by:
  `getParserOptions` in interface `Rule`
See Also:
  `Rule.setPriority(RulePriority)`

#### setUsesDFA

    public void setUsesDFA()

Description copied from interface: `Rule`
Sets whether this Rule uses Data Flow Analysis.

Specified by:
  `setUsesDFA` in interface `Rule`
See Also:
  `Rule.setUsesDFA()`

#### usesDFA

    public boolean usesDFA()

Description copied from interface: `Rule`
Gets whether this Rule uses Data Flow Analysis.

Specified by:
  `usesDFA` in interface `Rule`
See Also:
  `Rule.usesDFA()`

#### setUsesTypeResolution

    public void setUsesTypeResolution()

Description copied from interface: `Rule`
Sets whether this Rule uses Type Resolution.

Specified by:
  `setUsesTypeResolution` in interface `Rule`
See Also:
  `Rule.setUsesTypeResolution()`

#### usesTypeResolution

    public boolean usesTypeResolution()

Description copied from interface: `Rule`
Gets whether this Rule uses Type Resolution.

Specified by:
  `usesTypeResolution` in interface `Rule`
See Also:
  `Rule.usesTypeResolution()`

#### usesRuleChain

    public boolean usesRuleChain()

Description copied from interface: `Rule`
Gets whether this Rule uses the RuleChain.

Specified by:
  `usesRuleChain` in interface `Rule`
See Also:
  `Rule.usesRuleChain()`

#### getRuleChainVisits

    public List<String> getRuleChainVisits()

Description copied from interface: `Rule`
Gets the collection of AST node names visited by the Rule on the RuleChain.

Specified by:
  `getRuleChainVisits` in interface `Rule`
See Also:
  `Rule.getRuleChainVisits()`

#### addRuleChainVisit

    public void addRuleChainVisit(Class<? extends Node> nodeClass)

Description copied from interface: `Rule`
Adds an AST node by class to be visited by the Rule on the RuleChain.

Specified by:
  `addRuleChainVisit` in interface `Rule`
See Also:
  `Rule.addRuleChainVisit(Class)`

#### addRuleChainVisit

    public void addRuleChainVisit(String astNodeName)

Description copied from interface: `Rule`
Adds an AST node by name to be visited by the Rule on the RuleChain.

Specified by:
  `addRuleChainVisit` in interface `Rule`
See Also:
  `Rule.addRuleChainVisit(String)`

#### start

    public void start(RuleContext ctx)

Description copied from interface: `Rule`
Start processing. Called once, before apply() is first called.

Specified by:
  `start` in interface `Rule`
See Also:
  `Rule.start(RuleContext)`

#### end

    public void end(RuleContext ctx)

Description copied from interface: `Rule`
End processing. Called once, after apply() is last called.

Specified by:
  `end` in interface `Rule`
See Also:
  `Rule.end(RuleContext)`

#### addViolation

    public void addViolation(Object data,
                    Node node)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### addViolation

    public void addViolation(Object data,
                    Node node,
                    String arg)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### addViolation

    public void addViolation(Object data,
                    Node node,
                    Object[] args)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### addViolationWithMessage

    public void addViolationWithMessage(Object data,
                               Node node,
                               String message)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### addViolationWithMessage

    public void addViolationWithMessage(Object data,
                               Node node,
                               String message,
                               int beginLine,
                               int endLine)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### addViolationWithMessage

    public void addViolationWithMessage(Object data,
                               Node node,
                               String message,
                               Object[] args)

See Also:
  `RuleViolationFactory.addViolation(RuleContext, Rule, Node, String, Object[])`

#### equals

    public boolean equals(Object o)

Rules are equal if:

1. They have the same implementation class.
2. They have the same name.
3. They have the same priority.
4. They share the same properties.

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`
See Also:
  `equals(Object)`