net.sourceforge.pmd
Class RuleSet

java.lang.Object
  extended by 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
RuleSet()
           
 
Method Summary
 void addExcludePattern(String aPattern)
          Adds a new file exclusion pattern.
 void addExcludePatterns(Collection<String> someExcludePatterns)
          Adds new file exclusion patterns.
 void addIncludePattern(String aPattern)
          Adds a new inclusion pattern.
 void addIncludePatterns(Collection<String> someIncludePatterns)
          Adds new inclusion patterns.
 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)
          Executes the rules in this ruleset against each of the given nodes.
static RuleSet createFor(String name, Rule... theRules)
          A convenience constructor
 void end(RuleContext ctx)
          Triggers the end lifecycle event on each rule in the ruleset.
 boolean equals(Object o)
          Two rulesets are equals, if they have the same name and contain the same rules.
 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)
          Replaces the existing exclusion patterns with the given patterns.
 void setFileName(String fileName)
           
 void setIncludePatterns(Collection<String> theIncludePatterns)
          Replaces the existing inclusion patterns with the given patterns.
 void setName(String name)
           
 int size()
          Returns the number of rules in this ruleset
 void start(RuleContext ctx)
          Triggers that start lifecycle event on each rule in this ruleset.
 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 - the rule set name
theRules - the rules to add to the rule set
Returns:
a new rule set with the given rules added

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 - the new rule to add
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 - the new rule to add
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 - true if the ruleset should be added collectively or false to add individual references for each rule.

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 - true if the ruleset should be added collectively or false to add individual references for each rule.
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)
Triggers that start lifecycle event on each rule in this ruleset. Some rules perform initialization tasks on start.

Parameters:
ctx - the current context

apply

public void apply(List<? extends Node> acuList,
                  RuleContext ctx)
Executes the rules in this ruleset against each of the given nodes.

Parameters:
acuList - the node list, usually the root nodes like compilation units
ctx - the current context

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.
Returns:
true if the given rule matches the given language, which means, that the rule would be executed.

end

public void end(RuleContext ctx)
Triggers the end lifecycle event on each rule in the ruleset. Some rules perform a final summary calculation or cleanup in the end.

Parameters:
ctx - the current context

equals

public boolean equals(Object o)
Two rulesets are equals, if they have the same name and contain the same rules.

Overrides:
equals in class Object
Parameters:
o - the other ruleset to compare with
Returns:
true if o is a ruleset with the same name and rules, false otherwise

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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)
Adds a new file exclusion pattern.

Parameters:
aPattern - the pattern

addExcludePatterns

public void addExcludePatterns(Collection<String> someExcludePatterns)
Adds new file exclusion patterns.

Parameters:
someExcludePatterns - the patterns

setExcludePatterns

public void setExcludePatterns(Collection<String> theExcludePatterns)
Replaces the existing exclusion patterns with the given patterns.

Parameters:
theExcludePatterns - the new patterns

getIncludePatterns

public List<String> getIncludePatterns()

addIncludePattern

public void addIncludePattern(String aPattern)
Adds a new inclusion pattern.

Parameters:
aPattern - the pattern

addIncludePatterns

public void addIncludePatterns(Collection<String> someIncludePatterns)
Adds new inclusion patterns.

Parameters:
someIncludePatterns - the patterns

setIncludePatterns

public void setIncludePatterns(Collection<String> theIncludePatterns)
Replaces the existing inclusion patterns with the given patterns.

Parameters:
theIncludePatterns - the new patterns

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 - the removed rules will be added to this collection


Copyright © 2002-2015 InfoEther. All Rights Reserved.