Package net.sourceforge.pmd.lang.rule
Class RuleSet
java.lang.Object
net.sourceforge.pmd.lang.rule.RuleSet
- All Implemented Interfaces:
net.sourceforge.pmd.cache.internal.ChecksumAware
This class represents a collection of rules along with some optional filter
patterns that can preclude their application on specific files.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder class to create a ruleset. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RuleSetCreates 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.booleanTwo 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.longRetrieves the current instance checksumReturns the file exclusion patterns as an unmodifiable list.Returns the file inclusion patterns as an unmodifiable list.getName()getRuleByName(String ruleName) Returns the first Rule found with the given name (case-sensitive).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 rulesetReturn a ruleset builder used to create rules.
-
Constructor Details
-
RuleSet
-
-
Method Details
-
forSingleRule
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
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
-
toBuilder
Return a ruleset builder used to create rules. It is initialized with the configuration of this ruleset. -
size
public int size()Returns the number of rules in this ruleset- Returns:
- an int representing the number of rules
-
getRules
Returns the actual Collection of rules in this ruleset- Returns:
- a Collection with the rules. All objects are of type
Rule
-
getRuleByName
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
-
equals
Two rulesets are equals, if they have the same name and contain the same rules. -
hashCode
public int hashCode() -
getFileName
-
getName
-
getDescription
-
getFileExclusions
Returns the file exclusion patterns as an unmodifiable list. -
getFileInclusions
Returns the file inclusion patterns as an unmodifiable list. -
removeDysfunctionalRules
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:net.sourceforge.pmd.cache.internal.ChecksumAwareRetrieves the current instance checksum- Specified by:
getChecksumin interfacenet.sourceforge.pmd.cache.internal.ChecksumAware- Returns:
- The current checksum
-