Package net.sourceforge.pmd.lang.rule
Class RuleReference
java.lang.Object
net.sourceforge.pmd.lang.rule.RuleReference
- All Implemented Interfaces:
Rule,PropertySource
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.lang.rule.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR -
Constructor Summary
ConstructorsConstructorDescriptionRuleReference(Rule theRule, net.sourceforge.pmd.lang.rule.internal.RuleSetReference theRuleSetReference) Create a new reference to the given rule. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExample(String example) Add a single example for this Rule.voidapply(Node target, RuleContext ctx) Process the given node.deepCopy()Creates a new copy of this rule.voiddefinePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) Defines a new property.Returns a description of why the receiver may be dysfunctional.voidend(RuleContext ctx) End processing.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.Returns a modifiable map of the property descriptors that don't use default values, to their overridden value.Returns a modifiable list of the property descriptors that don't use default values.Get the priority of this Rule.Returns an unmodifiable map of descriptors to property values for the current receiver.<T> TgetProperty(PropertyDescriptor<T> propertyDescriptor) Get the typed value for the given property.getPropertyDescriptor(String name) Get the PropertyDescriptor for the given property name.Get the descriptors of all defined properties.getRule()Get the implementation class of this Rule.Get the name of the RuleSet containing this Rule.net.sourceforge.pmd.lang.rule.internal.RuleSetReferencegetSince()Get the version of PMD in which this Rule was added.Returns the object that selects the nodes to which this rule applies.booleanhasDescriptor(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).booleanChecks whether this rule reference explicitly overrides any of the possible attributes of the referenced rule.voidinitialize(LanguageProcessor languageProcessor) Initialize the rule using the language processor if needed.booleanGets whether this Rule is deprecated.booleanisPropertyOverridden(PropertyDescriptor<?> descriptor) Returns true if the given property has been set to a value somewhere in the XML.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.<T> voidsetProperty(PropertyDescriptor<T> propertyDescriptor, T value) Set the property value specified.voidsetRuleClass(String ruleClass) Set the class of this Rule.voidsetRuleSetName(String name) 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.
-
Constructor Details
-
RuleReference
public RuleReference(Rule theRule, net.sourceforge.pmd.lang.rule.internal.RuleSetReference theRuleSetReference) Create a new reference to the given rule.- Parameters:
theRule- the referenced ruletheRuleSetReference- the rule set, where the rule is defined
-
-
Method Details
-
getRule
-
getOverriddenMinimumLanguageVersion
-
setMinimumLanguageVersion
Description copied from interface:RuleSet the minimum LanguageVersion to which this Rule applies.- Specified by:
setMinimumLanguageVersionin interfaceRule- Parameters:
minimumLanguageVersion- the minimum language version
-
getOverriddenMaximumLanguageVersion
-
setMaximumLanguageVersion
Description copied from interface:RuleSet the maximum LanguageVersion to which this Rule applies.- Specified by:
setMaximumLanguageVersionin interfaceRule- Parameters:
maximumLanguageVersion- the maximum language version
-
isOverriddenDeprecated
-
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
-
getOverriddenName
-
getOriginalName
-
setName
Description copied from interface:RuleSet the name of this Rule. -
getName
Description copied from interface:RuleGet the name of this Rule.- Specified by:
getNamein interfacePropertySource- Specified by:
getNamein interfaceRule- Returns:
- the name
-
getOverriddenMessage
-
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.
-
getOverriddenDescription
-
setDescription
Description copied from interface:RuleSet the description of this Rule.- Specified by:
setDescriptionin interfaceRule- Parameters:
description- the description
-
getOverriddenExamples
-
addExample
Description copied from interface:RuleAdd a single example for this Rule.- Specified by:
addExamplein interfaceRule- Parameters:
example- a single example to add
-
getOverriddenExternalInfoUrl
-
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.
-
getOverriddenPriority
-
setPriority
Description copied from interface:RuleSet the priority of this Rule.- Specified by:
setPriorityin interfaceRule- Parameters:
priority- the priority
-
getOverriddenPropertyDescriptors
Description copied from interface:PropertySourceReturns a modifiable list of the property descriptors that don't use default values.- Specified by:
getOverriddenPropertyDescriptorsin interfacePropertySource- Returns:
- The descriptors that don't use default values
-
definePropertyDescriptor
public void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) throws IllegalArgumentException Description copied from interface:PropertySourceDefines a new property. Properties must be defined before they can be set a value.- Specified by:
definePropertyDescriptorin interfacePropertySource- Parameters:
propertyDescriptor- The property descriptor.- Throws:
IllegalArgumentException- If there is already a property defined the same name.
-
getOverriddenPropertiesByPropertyDescriptor
Description copied from interface:PropertySourceReturns 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.- Specified by:
getOverriddenPropertiesByPropertyDescriptorin interfacePropertySource- Returns:
- The descriptors that don't use default values
-
setProperty
Description copied from interface:PropertySourceSet the property value specified. This is also referred to as "overriding" the (default) value of a property.- Specified by:
setPropertyin interfacePropertySource- Type Parameters:
T- The underlying type of the property descriptor.- Parameters:
propertyDescriptor- The property descriptor.value- The value to set.
-
getRuleSetReference
public net.sourceforge.pmd.lang.rule.internal.RuleSetReference getRuleSetReference() -
hasDescriptor
Description copied from interface:PropertySourceReturns 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:
hasDescriptorin interfacePropertySource- Parameters:
descriptor- The descriptor to look for- Returns:
trueif the descriptor is defined,falseotherwise.
-
isPropertyOverridden
Description copied from interface:PropertySourceReturns true if the given property has been set to a value somewhere in the XML.- Specified by:
isPropertyOverriddenin interfacePropertySource- Parameters:
descriptor- The descriptor- Returns:
- True if the property has been set
-
deepCopy
Description copied from interface:RuleCreates a new 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:
trueif there is at least one attribute overridden.falseif the referenced rule is referenced without any change.
-
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
-
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
-
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:
name- 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.
-
getDescription
Description copied from interface:RuleGet the description of this Rule.- Specified by:
getDescriptionin interfaceRule- Returns:
- 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.
-
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.
-
getPriority
Description copied from interface:RuleGet the priority of this Rule.- Specified by:
getPriorityin interfaceRule- Returns:
- 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
-
initialize
Description copied from interface:RuleInitialize the rule using the language processor if needed.- Specified by:
initializein interfaceRule- Parameters:
languageProcessor- The processor for the rule's language
-
start
Description copied from interface:RuleStart processing. Called once per file, before apply() is first called. -
apply
Description copied from interface:RuleProcess the given node. The nodes that are fed to this method are the nodes selected byRule.getTargetSelector(). -
end
Description copied from interface:RuleEnd processing. Called once per file, after apply() is last called. -
getPropertyDescriptor
Description copied from interface:PropertySourceGet the PropertyDescriptor for the given property name.- Specified by:
getPropertyDescriptorin interfacePropertySource- Parameters:
name- The name of the property.- Returns:
- The PropertyDescriptor for the named property,
nullif there is no such property defined.
-
getPropertyDescriptors
Description copied from interface:PropertySourceGet the descriptors of all defined properties. The properties are returned sorted by UI order.- Specified by:
getPropertyDescriptorsin interfacePropertySource- Returns:
- The PropertyDescriptors in UI order.
-
getProperty
Description copied from interface:PropertySourceGet the typed value for the given property. Multi valued properties return immutable lists.- Specified by:
getPropertyin interfacePropertySource- Type Parameters:
T- The underlying type of the property descriptor.- Parameters:
propertyDescriptor- The property descriptor.- Returns:
- The property value.
-
getPropertiesByPropertyDescriptor
Description copied from interface:PropertySourceReturns an unmodifiable map of descriptors to property values for the current receiver. The returned map has an entry for every defined descriptor (PropertySource.getPropertyDescriptors()), if they were not specified explicitly, then default values are used.- Specified by:
getPropertiesByPropertyDescriptorin interfacePropertySource- Returns:
- An unmodifiable map of descriptors to property values
-
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
-