Class RuleSet.RuleSetBuilder

java.lang.Object
net.sourceforge.pmd.lang.rule.RuleSet.RuleSetBuilder
Enclosing class:
RuleSet

public static class RuleSet.RuleSetBuilder extends Object
A builder class to create a ruleset.
Since:
7.14.0
See Also:
  • Field Details

    • description

      public String description
    • name

      public String name
    • fileName

      public String fileName
  • Method Details

    • addRule

      public RuleSet.RuleSetBuilder addRule(Rule newRule)
      Add a new rule to this ruleset. Note that this method does not check for duplicates.
      Parameters:
      newRule - the rule to be added
      Returns:
      The same builder, for a fluid programming interface
    • removeIf

      public boolean removeIf(Predicate<? super Rule> filter)
      Remove all rules that matched the predicate.
    • addRuleReplaceIfExists

      public RuleSet.RuleSetBuilder 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:
      The same builder, for a fluid programming interface
    • addRuleIfNotExists

      public RuleSet.RuleSetBuilder addRuleIfNotExists(Rule ruleOrRef)
      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:
      ruleOrRef - the new rule to add
      Returns:
      The same builder, for a fluid programming interface
    • addRuleByReference

      public RuleSet.RuleSetBuilder 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
      Returns:
      The same builder, for a fluid programming interface
    • addRuleSet

      public RuleSet.RuleSetBuilder addRuleSet(RuleSet ruleSet)
      Add all rules of a whole RuleSet to this RuleSet
      Parameters:
      ruleSet - the RuleSet to add
      Returns:
      The same builder, for a fluid programming interface
    • addRuleSetByReference

      public RuleSet.RuleSetBuilder 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.
      Returns:
      The same builder, for a fluid programming interface
    • addRuleSetByReference

      public RuleSet.RuleSetBuilder 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.
      Returns:
      The same builder, for a fluid programming interface
    • withFileExclusions

      public RuleSet.RuleSetBuilder withFileExclusions(Pattern p1, Pattern... rest)
      Adds some new file exclusion patterns.
      Parameters:
      p1 - The first pattern
      rest - Additional patterns
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • withFileExclusions

      public RuleSet.RuleSetBuilder withFileExclusions(Collection<? extends Pattern> patterns)
      Adds some new file exclusion patterns.
      Parameters:
      patterns - Exclusion patterns to add
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • replaceFileExclusions

      public RuleSet.RuleSetBuilder replaceFileExclusions(Collection<? extends Pattern> patterns)
      Replaces the existing exclusion patterns with the given patterns.
      Parameters:
      patterns - Exclusion patterns to set
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • withFileInclusions

      public RuleSet.RuleSetBuilder withFileInclusions(Pattern p1, Pattern... rest)
      Adds some new file inclusion patterns.
      Parameters:
      p1 - The first pattern
      rest - Additional patterns
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • withFileInclusions

      public RuleSet.RuleSetBuilder withFileInclusions(Collection<? extends Pattern> patterns)
      Adds some new file inclusion patterns.
      Parameters:
      patterns - Inclusion patterns to add
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • replaceFileInclusions

      public RuleSet.RuleSetBuilder replaceFileInclusions(Collection<? extends Pattern> patterns)
      Replaces the existing inclusion patterns with the given patterns.
      Parameters:
      patterns - Inclusion patterns to set
      Returns:
      This builder
      Throws:
      NullPointerException - If any of the specified patterns is null
    • withFileName

      public RuleSet.RuleSetBuilder withFileName(String fileName)
    • withName

      public RuleSet.RuleSetBuilder withName(String name)
    • withDescription

      public RuleSet.RuleSetBuilder withDescription(String description)
    • hasDescription

      public boolean hasDescription()
    • getName

      public String getName()
    • build

      public RuleSet build()
    • filterRulesByPriority

      public void filterRulesByPriority(RulePriority minimumPriority)