Package net.sourceforge.pmd.lang.rule
Class RuleReference
- java.lang.Object
-
- net.sourceforge.pmd.lang.rule.AbstractDelegateRule
-
- net.sourceforge.pmd.lang.rule.RuleReference
-
- All Implemented Interfaces:
PropertySource
,Rule
public class RuleReference extends AbstractDelegateRule
This class represents a Rule which is a reference to Rule defined in another RuleSet. All details of the Rule are delegated to the underlying referenced Rule, but those operations which modify overridden aspects of the rule are explicitly tracked. Modification operations which set a value to the current underlying value do not override.
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Constructor Summary
Constructors Constructor Description RuleReference()
Deprecated.to be removed with PMD 7.0.0.RuleReference(Rule theRule, RuleSetReference theRuleSetReference)
Create a new reference to the given rule.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addExample(String example)
Add a single example for this Rule.Rule
deepCopy()
Creates a new copy of this rule.void
definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor)
Defines a new property.String
getName()
Get the name of this Rule.String
getOriginalName()
String
getOverriddenDescription()
List<String>
getOverriddenExamples()
String
getOverriddenExternalInfoUrl()
Language
getOverriddenLanguage()
Deprecated.overriding the language of a rule is not supported.LanguageVersion
getOverriddenMaximumLanguageVersion()
String
getOverriddenMessage()
LanguageVersion
getOverriddenMinimumLanguageVersion()
String
getOverriddenName()
RulePriority
getOverriddenPriority()
Map<PropertyDescriptor<?>,Object>
getOverriddenPropertiesByPropertyDescriptor()
Returns a modifiable map of the property descriptors that don't use default values, to their overridden value.List<PropertyDescriptor<?>>
getOverriddenPropertyDescriptors()
Returns a modifiable list of the property descriptors that don't use default values.RuleSetReference
getRuleSetReference()
boolean
hasDescriptor(PropertyDescriptor<?> descriptor)
Returns whether the specified property is defined on this property source, in which case it can be set or retrieved withPropertySource.getProperty(PropertyDescriptor)
andPropertySource.setProperty(PropertyDescriptor, Object)
.boolean
hasOverriddenAttributes()
Checks whether this rule reference explicitly overrides any of the possible attributes of the referenced rule.boolean
hasOverriddenProperty(PropertyDescriptor<?> descriptor)
Deprecated.UseisPropertyOverridden(PropertyDescriptor)
insteadboolean
isDeprecated()
Gets whether this Rule is deprecated.Boolean
isOverriddenDeprecated()
boolean
isPropertyOverridden(PropertyDescriptor<?> descriptor)
Returns true if the given property has been set to a value somewhere in the XML.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)
Deprecated.overriding the language of a rule is not supported.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.<T> void
setProperty(PropertyDescriptor<T> propertyDescriptor, T value)
Set the property value specified.void
setRuleSetReference(RuleSetReference ruleSetReference)
Deprecated.There's no use in setting the ruleset reference after constructionvoid
useDefaultValueFor(PropertyDescriptor<?> desc)
Deprecated.boolean
usesDefaultValues()
Deprecated.-
Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractDelegateRule
addRuleChainVisit, addRuleChainVisit, apply, dysfunctionReason, end, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getParserOptions, getPriority, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, getRule, getRuleChainVisits, getRuleClass, getRuleSetName, getSince, ignoredProperties, isDfa, isMultifile, isRuleChain, isTypeResolution, setDfa, setMultifile, setProperty, setRule, setRuleClass, setRuleSetName, setSince, setTypeResolution, setUsesDFA, setUsesMultifile, setUsesTypeResolution, start, usesDFA, usesMultifile, usesRuleChain, usesTypeResolution
-
-
-
-
Constructor Detail
-
RuleReference
@Deprecated public RuleReference()
Deprecated.to be removed with PMD 7.0.0. when creating a rule reference, always provide the rule and the ruleset, see the constructor RuleReference(Rule, RuleSetReference)
-
RuleReference
public RuleReference(Rule theRule, RuleSetReference theRuleSetReference)
Create a new reference to the given rule.- Parameters:
theRule
- the referenced ruletheRuleSetReference
- the rule set, where the rule is defined
-
-
Method Detail
-
getOverriddenLanguage
@Deprecated public Language getOverriddenLanguage()
Deprecated.overriding the language of a rule is not supported.
-
setLanguage
@Deprecated public void setLanguage(Language language)
Deprecated.overriding the language of a rule is not supported.Description copied from interface:Rule
Set the Language of this Rule.- Specified by:
setLanguage
in interfaceRule
- Overrides:
setLanguage
in classAbstractDelegateRule
- Parameters:
language
- the language
-
getOverriddenMinimumLanguageVersion
public LanguageVersion getOverriddenMinimumLanguageVersion()
-
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
- Overrides:
setMinimumLanguageVersion
in classAbstractDelegateRule
- Parameters:
minimumLanguageVersion
- the minimum language version
-
getOverriddenMaximumLanguageVersion
public LanguageVersion getOverriddenMaximumLanguageVersion()
-
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
- Overrides:
setMaximumLanguageVersion
in classAbstractDelegateRule
- Parameters:
maximumLanguageVersion
- the maximum language version
-
isOverriddenDeprecated
public Boolean isOverriddenDeprecated()
-
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
- Overrides:
isDeprecated
in classAbstractDelegateRule
- 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
- Overrides:
setDeprecated
in classAbstractDelegateRule
- Parameters:
deprecated
- whether this rule is deprecated
-
getOverriddenName
public String getOverriddenName()
-
getOriginalName
public String getOriginalName()
-
setName
public void setName(String name)
Description copied from interface:Rule
Set the name of this Rule.- Specified by:
setName
in interfaceRule
- Overrides:
setName
in classAbstractDelegateRule
- Parameters:
name
- the name
-
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
- Overrides:
getName
in classAbstractDelegateRule
- Returns:
- the name
-
getOverriddenMessage
public String getOverriddenMessage()
-
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
- Overrides:
setMessage
in classAbstractDelegateRule
- Parameters:
message
- the message to show for a violation.
-
getOverriddenDescription
public String getOverriddenDescription()
-
setDescription
public void setDescription(String description)
Description copied from interface:Rule
Set the description of this Rule.- Specified by:
setDescription
in interfaceRule
- Overrides:
setDescription
in classAbstractDelegateRule
- Parameters:
description
- the description
-
addExample
public void addExample(String example)
Description copied from interface:Rule
Add a single example for this Rule.- Specified by:
addExample
in interfaceRule
- Overrides:
addExample
in classAbstractDelegateRule
- Parameters:
example
- a single example to add
-
getOverriddenExternalInfoUrl
public String getOverriddenExternalInfoUrl()
-
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
- Overrides:
setExternalInfoUrl
in classAbstractDelegateRule
- Parameters:
externalInfoUrl
- the URL for external information about this rule.
-
getOverriddenPriority
public RulePriority getOverriddenPriority()
-
setPriority
public void setPriority(RulePriority priority)
Description copied from interface:Rule
Set the priority of this Rule.- Specified by:
setPriority
in interfaceRule
- Overrides:
setPriority
in classAbstractDelegateRule
- Parameters:
priority
- the priority
-
getOverriddenPropertyDescriptors
public List<PropertyDescriptor<?>> getOverriddenPropertyDescriptors()
Description copied from interface:PropertySource
Returns a modifiable list of the property descriptors that don't use default values.- Returns:
- The descriptors that don't use default values
-
definePropertyDescriptor
public void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) throws IllegalArgumentException
Description copied from interface:PropertySource
Defines a new property. Properties must be defined before they can be set a value.- Specified by:
definePropertyDescriptor
in interfacePropertySource
- Overrides:
definePropertyDescriptor
in classAbstractDelegateRule
- Parameters:
propertyDescriptor
- The property descriptor.- Throws:
IllegalArgumentException
- If there is already a property defined the same name.
-
getOverriddenPropertiesByPropertyDescriptor
public Map<PropertyDescriptor<?>,Object> getOverriddenPropertiesByPropertyDescriptor()
Description copied from interface:PropertySource
Returns a modifiable map of the property descriptors that don't use default values, to their overridden value. Modifications on the returned map don't affect this property source.- Returns:
- The descriptors that don't use default values
-
setProperty
public <T> void setProperty(PropertyDescriptor<T> propertyDescriptor, T value)
Description copied from interface:PropertySource
Set the property value specified. This is also referred to as "overriding" the (default) value of a property.- Specified by:
setProperty
in interfacePropertySource
- Overrides:
setProperty
in classAbstractDelegateRule
- Type Parameters:
T
- The underlying type of the property descriptor.- Parameters:
propertyDescriptor
- The property descriptor.value
- The value to set.
-
getRuleSetReference
public RuleSetReference getRuleSetReference()
-
setRuleSetReference
@Deprecated public void setRuleSetReference(RuleSetReference ruleSetReference)
Deprecated.There's no use in setting the ruleset reference after construction
-
hasDescriptor
public boolean hasDescriptor(PropertyDescriptor<?> descriptor)
Description copied from interface:PropertySource
Returns whether the specified property is defined on this property source, in which case it can be set or retrieved withPropertySource.getProperty(PropertyDescriptor)
andPropertySource.setProperty(PropertyDescriptor, Object)
.- Specified by:
hasDescriptor
in interfacePropertySource
- Overrides:
hasDescriptor
in classAbstractDelegateRule
- Parameters:
descriptor
- The descriptor to look for- Returns:
true
if the descriptor is defined,false
otherwise.- See Also:
PropertySource.hasDescriptor(PropertyDescriptor)
-
hasOverriddenProperty
@Deprecated public boolean hasOverriddenProperty(PropertyDescriptor<?> descriptor)
Deprecated.UseisPropertyOverridden(PropertyDescriptor)
instead
-
isPropertyOverridden
public boolean isPropertyOverridden(PropertyDescriptor<?> descriptor)
Description copied from interface:PropertySource
Returns true if the given property has been set to a value somewhere in the XML.- Specified by:
isPropertyOverridden
in interfacePropertySource
- Overrides:
isPropertyOverridden
in classAbstractDelegateRule
- Parameters:
descriptor
- The descriptor- Returns:
- True if the property has been set
-
usesDefaultValues
@Deprecated public boolean usesDefaultValues()
Deprecated.Description copied from interface:PropertySource
Returns whether this Rule uses default values for properties.- Returns:
- boolean
true
if the properties all have default values,false
otherwise.
-
useDefaultValueFor
@Deprecated public void useDefaultValueFor(PropertyDescriptor<?> desc)
Deprecated.Description copied from interface:PropertySource
Clears out any user-specified value for the property allowing it to use the default value in the descriptor.- Parameters:
desc
- the property to clear out
-
deepCopy
public Rule deepCopy()
Description copied from interface:Rule
Creates a new copy of this rule.- Returns:
- A new exact copy of this rule
-
hasOverriddenAttributes
public boolean hasOverriddenAttributes()
Checks whether this rule reference explicitly overrides any of the possible attributes of the referenced rule.- Returns:
true
if there is at least one attribute overridden.false
if the referenced rule is referenced without any change.
-
-