Package net.sourceforge.pmd
Class RuleSet
- java.lang.Object
-
- net.sourceforge.pmd.RuleSet
-
- All Implemented Interfaces:
ChecksumAware
public class RuleSet extends Object implements ChecksumAware
This class represents a collection of rules along with some optional filter patterns that can preclude their application on specific files.- See Also:
Rule
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanapplies(File file)Check if a given source file should be checked by rules in this RuleSet.static booleanapplies(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.voidapply(List<? extends Node> acuList, RuleContext ctx)Executes the rules in this ruleset against each of the given nodes.static RuleSetcopy(RuleSet original)Creates a copy of the given ruleset.static RuleSetcreate(String name, String description, String fileName, Collection<Pattern> excludePatterns, Collection<Pattern> includePatterns, Iterable<? extends Rule> rules)Creates a new ruleset with the given metadata such as name, description, fileName, exclude/include patterns are used.voidend(RuleContext ctx)Triggers the end lifecycle event on each rule in the ruleset.booleanequals(Object o)Two rulesets are equals, if they have the same name and contain the same rules.static RuleSetforSingleRule(Rule rule)Creates a new ruleset containing a single rule.longgetChecksum()Retrieves the current instance checksumStringgetDescription()List<String>getExcludePatterns()Deprecated.List<Pattern>getFileExclusions()Returns the file exclusion patterns as an unmodifiable list.List<Pattern>getFileInclusions()Returns the file inclusion patterns as an unmodifiable list.StringgetFileName()List<String>getIncludePatterns()Deprecated.StringgetName()RulegetRuleByName(String ruleName)Returns the first Rule found with the given name (case-sensitive).Collection<Rule>getRules()Returns the actual Collection of rules in this rulesetinthashCode()voidremoveDysfunctionalRules(Collection<Rule> collector)Remove and collect any misconfigured rules.intsize()Returns the number of rules in this rulesetvoidstart(RuleContext ctx)Triggers that start lifecycle event on each rule in this ruleset.booleanusesDFA(Language language)Deprecated.SeeRule.isDfa()booleanusesMultifile(Language language)Deprecated.booleanusesTypeResolution(Language language)Deprecated.
-
-
-
Constructor Detail
-
RuleSet
public RuleSet(RuleSet rs)
-
-
Method Detail
-
forSingleRule
public static RuleSet forSingleRule(Rule rule)
Creates a new ruleset containing a single rule. The ruleset will have default description, name, and null file name.- Parameters:
rule- The rule being created- Returns:
- The newly created RuleSet
-
create
public static RuleSet create(String name, String description, String fileName, Collection<Pattern> excludePatterns, Collection<Pattern> includePatterns, Iterable<? extends Rule> rules)
Creates a new ruleset with the given metadata such as name, description, fileName, exclude/include patterns are used. The rules are taken from the given collection.Note: The rule instances are shared between the collection and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the rules of the collection are also referenced by other rulesets and used in different threads.
- Parameters:
name- the name of the rulesetdescription- the descriptionfileName- the filenameexcludePatterns- list of exclude patternsincludePatterns- list of include patterns, that override the exclude patternsrules- the collection with the rules to add to the new ruleset- Returns:
- the new ruleset
- Throws:
NullPointerException- If any parameter is null, or the collections contain null elements
-
copy
public static RuleSet copy(RuleSet original)
Creates a copy of the given ruleset. All properties like name, description, fileName and exclude/include patterns are copied.Note: The rule instances are shared between the original and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the original ruleset and the new ruleset are used in different threads.
- Parameters:
original- the original rule set to copy from- Returns:
- the copy
-
getExcludePatterns
@Deprecated public List<String> getExcludePatterns()
Deprecated.
-
size
public int size()
Returns the number of rules in this ruleset- Returns:
- an int representing the number of rules
-
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
-
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
-
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 anexcludepattern which matches the file, unless there is anincludepattern which also matches the file. In other words,includepatterns overrideexcludepatterns.- Parameters:
file- the source file to check- Returns:
trueif the file should be checked,falseotherwise
-
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 unitsctx- 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:
trueif 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.
-
getFileName
public String getFileName()
-
getName
public String getName()
-
getDescription
public String getDescription()
-
getIncludePatterns
@Deprecated public List<String> getIncludePatterns()
Deprecated.
-
getFileExclusions
public List<Pattern> getFileExclusions()
Returns the file exclusion patterns as an unmodifiable list.
-
getFileInclusions
public List<Pattern> getFileInclusions()
Returns the file inclusion patterns as an unmodifiable list.
-
usesDFA
@Deprecated public boolean usesDFA(Language language)
Deprecated.SeeRule.isDfa()Does any Rule for the given Language use the DFA layer?- Parameters:
language- The Language.- Returns:
trueif a Rule for the Language uses the DFA layer,falseotherwise.
-
usesTypeResolution
@Deprecated public boolean usesTypeResolution(Language language)
Deprecated.Does any Rule for the given Language use Type Resolution?- Parameters:
language- The Language.- Returns:
trueif a Rule for the Language uses Type Resolution,falseotherwise.
-
usesMultifile
@Deprecated public boolean usesMultifile(Language language)
Deprecated.Does any Rule for the given Language use multi-file analysis?- Parameters:
language- The Language.- Returns:
trueif a Rule for the Language uses multi file analysis,falseotherwise.
-
removeDysfunctionalRules
public void removeDysfunctionalRules(Collection<Rule> collector)
Remove and collect any misconfigured rules.- Parameters:
collector- the removed rules will be added to this collection
-
getChecksum
public long getChecksum()
Description copied from interface:ChecksumAwareRetrieves the current instance checksum- Specified by:
getChecksumin interfaceChecksumAware- Returns:
- The current checksum
-
-