Class RuleReference

java.lang.Object
net.sourceforge.pmd.lang.rule.RuleReference
All Implemented Interfaces:
Rule, PropertySource

public class RuleReference extends Object implements Rule
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.
  • 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 rule
      theRuleSetReference - the rule set, where the rule is defined
  • Method Details

    • getRule

      public Rule getRule()
    • 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 interface Rule
      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 interface Rule
      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 interface Rule
      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 interface Rule
      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 interface Rule
      Parameters:
      name - the name
    • getName

      public String getName()
      Description copied from interface: Rule
      Get the name of this Rule.
      Specified by:
      getName in interface PropertySource
      Specified by:
      getName in interface Rule
      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 interface Rule
      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 interface Rule
      Parameters:
      description - the description
    • getOverriddenExamples

      public List<String> getOverriddenExamples()
    • addExample

      public void addExample(String example)
      Description copied from interface: Rule
      Add a single example for this Rule.
      Specified by:
      addExample in interface Rule
      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 interface Rule
      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 interface Rule
      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.
      Specified by:
      getOverriddenPropertyDescriptors in interface PropertySource
      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 interface PropertySource
      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.
      Specified by:
      getOverriddenPropertiesByPropertyDescriptor in interface PropertySource
      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 interface PropertySource
      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

      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 with PropertySource.getProperty(PropertyDescriptor) and PropertySource.setProperty(PropertyDescriptor, Object).
      Specified by:
      hasDescriptor in interface PropertySource
      Parameters:
      descriptor - The descriptor to look for
      Returns:
      true if the descriptor is defined, false otherwise.
    • 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 interface PropertySource
      Parameters:
      descriptor - The descriptor
      Returns:
      True if the property has been set
    • deepCopy

      public Rule deepCopy()
      Description copied from interface: Rule
      Creates a new copy of this rule.
      Specified by:
      deepCopy in interface 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.
    • getLanguage

      public Language getLanguage()
      Description copied from interface: Rule
      Get the Language of this Rule.
      Specified by:
      getLanguage in interface Rule
      Returns:
      the language
    • setLanguage

      public void setLanguage(Language language)
      Description copied from interface: Rule
      Set the Language of this Rule.
      Specified by:
      setLanguage in interface Rule
      Parameters:
      language - the 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
      Returns:
      the minimum language version
    • 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
      Returns:
      the maximum language version
    • 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
      Returns:
      version of PMD since when this rule was added
    • 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
      Parameters:
      since - the version of PMD since when this rule was added
    • getRuleClass

      public String getRuleClass()
      Description copied from interface: Rule
      Get the implementation class of this Rule.
      Specified by:
      getRuleClass in interface Rule
      Returns:
      the implementation class name of this rule.
    • setRuleClass

      public void setRuleClass(String ruleClass)
      Description copied from interface: Rule
      Set the class of this Rule.
      Specified by:
      setRuleClass in interface Rule
      Parameters:
      ruleClass - the class name of this rule.
    • getRuleSetName

      public String getRuleSetName()
      Description copied from interface: Rule
      Get the name of the RuleSet containing this Rule.
      Specified by:
      getRuleSetName in interface Rule
      Returns:
      the name of th ruleset containing this rule.
      See Also:
    • setRuleSetName

      public void setRuleSetName(String name)
      Description copied from interface: Rule
      Set the name of the RuleSet containing this Rule.
      Specified by:
      setRuleSetName in interface Rule
      Parameters:
      name - the name of the ruleset containing this rule.
      See Also:
    • 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
      Returns:
      the message to show for a violation.
    • getDescription

      public String getDescription()
      Description copied from interface: Rule
      Get the description of this Rule.
      Specified by:
      getDescription in interface Rule
      Returns:
      the description
    • getExamples

      public List<String> getExamples()
      Description copied from interface: Rule
      Get the list of examples for this Rule.
      Specified by:
      getExamples in interface Rule
      Returns:
      the list of examples for this rule.
    • getExternalInfoUrl

      public String getExternalInfoUrl()
      Description copied from interface: Rule
      Get a URL for external information about this Rule.
      Specified by:
      getExternalInfoUrl in interface Rule
      Returns:
      the URL for external information about this rule.
    • getPriority

      public RulePriority getPriority()
      Description copied from interface: Rule
      Get the priority of this Rule.
      Specified by:
      getPriority in interface Rule
      Returns:
      the priority
    • getTargetSelector

      public RuleTargetSelector getTargetSelector()
      Description copied from interface: Rule
      Returns the object that selects the nodes to which this rule applies. The selected nodes will be handed to Rule.apply(Node, RuleContext).
      Specified by:
      getTargetSelector in interface Rule
    • initialize

      public void initialize(LanguageProcessor languageProcessor)
      Description copied from interface: Rule
      Initialize the rule using the language processor if needed.
      Specified by:
      initialize in interface Rule
      Parameters:
      languageProcessor - The processor for the rule's language
    • start

      public void start(RuleContext ctx)
      Description copied from interface: Rule
      Start processing. Called once per file, before apply() is first called.
      Specified by:
      start in interface Rule
      Parameters:
      ctx - the rule context
    • apply

      public void apply(Node target, RuleContext ctx)
      Description copied from interface: Rule
      Process the given node. The nodes that are fed to this method are the nodes selected by Rule.getTargetSelector().
      Specified by:
      apply in interface Rule
      Parameters:
      target - Node on which to apply the rule
      ctx - Rule context, handling violations
    • end

      public void end(RuleContext ctx)
      Description copied from interface: Rule
      End processing. Called once per file, after apply() is last called.
      Specified by:
      end in interface Rule
      Parameters:
      ctx - the rule context
    • getPropertyDescriptor

      public PropertyDescriptor<?> getPropertyDescriptor(String name)
      Description copied from interface: PropertySource
      Get the PropertyDescriptor for the given property name.
      Specified by:
      getPropertyDescriptor in interface PropertySource
      Parameters:
      name - The name of the property.
      Returns:
      The PropertyDescriptor for the named property, null if there is no such property defined.
    • getPropertyDescriptors

      public List<PropertyDescriptor<?>> getPropertyDescriptors()
      Description copied from interface: PropertySource
      Get the descriptors of all defined properties. The properties are returned sorted by UI order.
      Specified by:
      getPropertyDescriptors in interface PropertySource
      Returns:
      The PropertyDescriptors in UI order.
    • getProperty

      public <T> T getProperty(PropertyDescriptor<T> propertyDescriptor)
      Description copied from interface: PropertySource
      Get the typed value for the given property. Multi valued properties return immutable lists.
      Specified by:
      getProperty in interface PropertySource
      Type Parameters:
      T - The underlying type of the property descriptor.
      Parameters:
      propertyDescriptor - The property descriptor.
      Returns:
      The property value.
    • getPropertiesByPropertyDescriptor

      public Map<PropertyDescriptor<?>,Object> getPropertiesByPropertyDescriptor()
      Description copied from interface: PropertySource
      Returns 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:
      getPropertiesByPropertyDescriptor in interface PropertySource
      Returns:
      An unmodifiable map of descriptors to property values
    • dysfunctionReason

      public String dysfunctionReason()
      Description copied from interface: PropertySource
      Returns 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:
      dysfunctionReason in interface PropertySource
      Returns:
      String