net.sourceforge.pmd

## Class RuleSet

- java.lang.Object
- - net.sourceforge.pmd.RuleSet

    public class RuleSet
    extends Object

This class represents a collection of rules along with some optional filter patterns that can preclude their application on specific files.

See Also:
  `Rule`

### Constructor Summary

Constructors
Constructor and Description
`RuleSet()`

### Method Summary

Methods
`void` `addExcludePattern(String aPattern)`
`void` `addExcludePatterns(Collection<String> someExcludePatterns)`
`void` `addIncludePattern(String aPattern)`
`void` `addIncludePatterns(Collection<String> someIncludePatterns)`
`void` `addRule(Rule rule)` Add a new rule to this ruleset.
`void` `addRuleByReference(String ruleSetFileName, Rule rule)` Add a new rule by reference to this ruleset.
`boolean` `addRuleIfNotExists(Rule rule)` Only adds a rule to the ruleset if no rule with the same name for the same language was added before, so that the existent rule configuration won't be overridden.
`boolean` `addRuleReplaceIfExists(Rule rule)` Adds a rule.
`void` `addRuleSet(RuleSet ruleSet)` Add a whole RuleSet to this RuleSet
`void` `addRuleSetByReference(RuleSet ruleSet, boolean allRules)` Add all rules by reference from one RuleSet to this RuleSet.
`void` `addRuleSetByReference(RuleSet ruleSet, boolean allRules, String... excludes)` Add all rules by reference from one RuleSet to this RuleSet.
`boolean` `applies(File file)` Check if a given source file should be checked by rules in this RuleSet.
`static boolean` `applies(Rule rule, LanguageVersion languageVersion)` Does the given Rule apply to the given LanguageVersion?
`void` `apply(List<? extends Node> acuList, RuleContext ctx)`
`static RuleSet` `createFor(String name, Rule... theRules)` A convenience constructor
`void` `end(RuleContext ctx)`
`boolean` `equals(Object o)`
`String` `getDescription()`
`List<String>` `getExcludePatterns()`
`String` `getFileName()`
`List<String>` `getIncludePatterns()`
`String` `getName()`
`Rule` `getRuleByName(String ruleName)` Returns the first Rule found with the given name (case-sensitive).
`Collection<Rule>` `getRules()` Returns the actual Collection of rules in this ruleset
`int` `hashCode()`
`void` `removeDysfunctionalRules(Collection<Rule> collector)` Remove and collect any misconfigured rules.
`void` `setDescription(String description)`
`void` `setExcludePatterns(Collection<String> theExcludePatterns)`
`void` `setFileName(String fileName)`
`void` `setIncludePatterns(Collection<String> theIncludePatterns)`
`void` `setName(String name)`
`int` `size()` Returns the number of rules in this ruleset
`void` `start(RuleContext ctx)`
`boolean` `usesDFA(Language language)` Does any Rule for the given Language use the DFA layer?
`boolean` `usesTypeResolution(Language language)` Does any Rule for the given Language use Type Resolution?

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### RuleSet

    public RuleSet()

### Method Detail

#### createFor

    public static RuleSet createFor(String name,
                    Rule... theRules)

A convenience constructor

Parameters:
  `name` -
  `theRules` -
Returns:

#### size

    public int size()

Returns the number of rules in this ruleset

Returns:
  an int representing the number of rules

#### addRule

    public void addRule(Rule rule)

Add a new rule to this ruleset. Note that this method does not check for duplicates.

Parameters:
  `rule` - the rule to be added

#### addRuleReplaceIfExists

    public boolean addRuleReplaceIfExists(Rule rule)

Adds a rule. If a rule with the same name and language already existed before in the ruleset, then the new rule will replace it. This makes sure that the rule configured is overridden.

Parameters:
  `rule` -
Returns:
  `true` if the new rule replaced an existing one, otherwise `false`.

#### addRuleIfNotExists

    public boolean addRuleIfNotExists(Rule rule)

Only adds a rule to the ruleset if no rule with the same name for the same language was added before, so that the existent rule configuration won't be overridden.

Parameters:
  `rule` -
Returns:
  `true` if the rule was added, `false` otherwise

#### addRuleByReference

    public void addRuleByReference(String ruleSetFileName,
                          Rule rule)

Add a new rule by reference to this ruleset.

Parameters:
  `ruleSetFileName` - the ruleset which contains the rule
  `rule` - the rule to be added

#### getRules

    public Collection<Rule> getRules()

Returns the actual Collection of rules in this ruleset

Returns:
  a Collection with the rules. All objects are of type `Rule`

#### usesDFA

    public boolean usesDFA(Language language)

Does any Rule for the given Language use the DFA layer?

Parameters:
  `language` - The Language.
Returns:
  `true` if a Rule for the Language uses the DFA layer, `false` otherwise.

#### getRuleByName

    public Rule getRuleByName(String ruleName)

Returns the first Rule found with the given name (case-sensitive). Note: Since we support multiple languages, rule names are not expected to be unique within any specific ruleset.

Parameters:
  `ruleName` - the exact name of the rule to find
Returns:
  the rule or null if not found

#### addRuleSet

    public void addRuleSet(RuleSet ruleSet)

Add a whole RuleSet to this RuleSet

Parameters:
  `ruleSet` - the RuleSet to add

#### addRuleSetByReference

    public void addRuleSetByReference(RuleSet ruleSet,
                             boolean allRules)

Add all rules by reference from one RuleSet to this RuleSet. The rules can be added as individual references, or collectively as an all rule reference.

Parameters:
  `ruleSet` - the RuleSet to add
  `allRules` -

#### addRuleSetByReference

    public void addRuleSetByReference(RuleSet ruleSet,
                             boolean allRules,
                             String... excludes)

Add all rules by reference from one RuleSet to this RuleSet. The rules can be added as individual references, or collectively as an all rule reference.

Parameters:
  `ruleSet` - the RuleSet to add
  `allRules` -
  `excludes` - names of the rules that should be excluded.

#### applies

    public boolean applies(File file)

Check if a given source file should be checked by rules in this RuleSet. A file should not be checked if there is an `exclude` pattern which matches the file, unless there is an `include` pattern which also matches the file. In other words, `include` patterns override `exclude` patterns.

Parameters:
  `file` - the source file to check
Returns:
  `true` if the file should be checked, `false` otherwise

#### start

    public void start(RuleContext ctx)

#### apply

    public void apply(List<? extends Node> acuList,
             RuleContext ctx)

#### applies

    public static boolean applies(Rule rule,
                  LanguageVersion languageVersion)

Does the given Rule apply to the given LanguageVersion? If so, the Language must be the same and be between the minimum and maximums versions on the Rule.

Parameters:
  `rule` - The rule.
  `languageVersion` - The language version.

#### end

    public void end(RuleContext ctx)

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`
See Also:
  `Object.equals(java.lang.Object)`

#### hashCode

    public int hashCode()

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

#### getFileName

    public String getFileName()

#### setFileName

    public void setFileName(String fileName)

#### getName

    public String getName()

#### setName

    public void setName(String name)

#### getDescription

    public String getDescription()

#### setDescription

    public void setDescription(String description)

#### getExcludePatterns

    public List<String> getExcludePatterns()

#### addExcludePattern

    public void addExcludePattern(String aPattern)

#### addExcludePatterns

    public void addExcludePatterns(Collection<String> someExcludePatterns)

#### setExcludePatterns

    public void setExcludePatterns(Collection<String> theExcludePatterns)

#### getIncludePatterns

    public List<String> getIncludePatterns()

#### addIncludePattern

    public void addIncludePattern(String aPattern)

#### addIncludePatterns

    public void addIncludePatterns(Collection<String> someIncludePatterns)

#### setIncludePatterns

    public void setIncludePatterns(Collection<String> theIncludePatterns)

#### usesTypeResolution

    public boolean usesTypeResolution(Language language)

Does any Rule for the given Language use Type Resolution?

Parameters:
  `language` - The Language.
Returns:
  `true` if a Rule for the Language uses Type Resolution, `false` otherwise.

#### removeDysfunctionalRules

    public void removeDysfunctionalRules(Collection<Rule> collector)

Remove and collect any misconfigured rules.

Parameters:
  `collector` -