Package: java.org.codenarc.rule

## [Java] Class AbstractRule

- java.org.codenarc.rule.AbstractRule

- All Implemented Interfaces and Traits:
    Rule

      public abstract class AbstractRule

  Abstract superclass for Rules.

  Each subclass must define an `name` property (String) and a `priority` property (integer 1..3).
  Authors:
    Chris Mair
    Hamlet D'Arcy

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `void` | `applyTo(SourceCode sourceCode, List<Violation> violations)` Apply this rule to the specified source and return a list of violations (or an empty List)
    `` | `List<Violation>` | `applyTo(SourceCode sourceCode)` Apply this rule to the specified source and return a list of violations (or an empty List).
    `` | `protected Violation` | `createViolation(Integer lineNumber, String sourceLine, String message)` Create and return a new Violation for this rule and the specified values
    `` | `protected Violation` | `createViolation(Integer lineNumber, String message)` Create and return a new Violation for this rule and the specified values
    `` | `protected Violation` | `createViolation(Integer lineNumber)` Create and return a new Violation for this rule and the specified values
    `` | `protected Violation` | `createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node, String message)` Create a new Violation for the AST node.
    `` | `protected Violation` | `createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node)` Create a new Violation for the AST node.
    `` | `protected Violation` | `createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode, String message)` Create and return a new Violation for this rule and the specified import
    `` | `protected Violation` | `createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)` Create and return a new Violation for this rule and the specified import
    `` | `protected Violation` | `createViolationForImport(SourceCode sourceCode, String className, String alias, String violationMessage)` Create and return a new Violation for this rule and the specified import className and alias
    `` | `String` | `getApplyToFileNames()`
    `` | `String` | `getApplyToFilesMatching()`
    `` | `int` | `getCompilerPhase()` @return the required compiler phase (as in org.codehaus.groovy.control.Phases) of the AST of the SourceCode handed to the rule via applyTo(SourceCode sourceCode)
    `` | `String` | `getDescription()`
    `` | `String` | `getDoNotApplyToFileNames()`
    `` | `String` | `getDoNotApplyToFilesMatching()`
    `` | `String` | `getName()` @return the unique name for this rule
    `` | `int` | `getPriority()` @return the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive.
    `` | `String` | `getViolationMessage()`
    `` | `boolean` | `isEnabled()`
    `` | `boolean` | `isReady()` Allows rules to check whether preconditions are satisfied and short-circuit execution (i.e., do nothing) if those preconditions are not satisfied.
    `` | `void` | `setApplyToFileNames(String applyToFileNames)`
    `` | `void` | `setApplyToFilesMatching(String applyToFilesMatching)`
    `` | `void` | `setDescription(String description)`
    `` | `void` | `setDoNotApplyToFileNames(String doNotApplyToFileNames)`
    `` | `void` | `setDoNotApplyToFilesMatching(String doNotApplyToFilesMatching)`
    `` | `void` | `setEnabled(boolean enabled)`
    `` | `void` | `setName(String name)` Set the unique name for this rule
    `` | `void` | `setPriority(int priority)` Set the priority for this rule
    `` | `void` | `setViolationMessage(String violationMessage)`
    `` | `String` | `toString()`
    `` | `void` | `validate()` Allows rules to perform validation.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, toString, hashCode, getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### public void applyTo(SourceCode sourceCode, List<Violation> violations)

      Apply this rule to the specified source and return a list of violations (or an empty List)

      Parameters:
        `sourceCode` - - the source to apply this rule to
        `violations` - - the List of violations to which new violations from this rule are to be added

    - #### public List<Violation> applyTo(SourceCode sourceCode)

      Apply this rule to the specified source and return a list of violations (or an empty List). This implementation delegates to the abstract applyCode(SourceCode,List), provided by concrete subclasses. This template method simplifies subclass implementations and also enables common handling of enablement logic.

      Parameters:
        `sourceCode` - - the source to apply this rule to
      Returns:
        the List of violations; may be empty

    - #### protected Violation createViolation(Integer lineNumber, String sourceLine, String message)

      Create and return a new Violation for this rule and the specified values

      Parameters:
        `lineNumber` - - the line number for the violation; may be null
        `sourceLine` - - the source line for the violation; may be null
        `message` - - the message for the violation; may be null
      Returns:
        a new Violation object

    - #### @Deprecated // should really supply an AST Node protected Violation createViolation(Integer lineNumber, String message)

      Create and return a new Violation for this rule and the specified values

      Parameters:
        `lineNumber` - - the line number for the violation; may be null
      Returns:
        a new Violation object

    - #### @Deprecated protected Violation createViolation(Integer lineNumber)

      Create and return a new Violation for this rule and the specified values

      Parameters:
        `lineNumber` - - the line number for the violation; may be null
      Returns:
        a new Violation object

    - #### protected Violation createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node, String message)

      Create a new Violation for the AST node.

      Parameters:
        `sourceCode` - - the SourceCode
        `node` - - the Groovy AST Node
        `message` - - the message for the violation; defaults to null

    - #### @Deprecated // should really supply a message protected Violation createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node)

      Create a new Violation for the AST node.

      Parameters:
        `sourceCode` - - the SourceCode
        `node` - - the Groovy AST Node

    - #### protected Violation createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode, String message)

      Create and return a new Violation for this rule and the specified import

      Parameters:
        `sourceCode` - - the SourceCode
        `importNode` - - the ImportNode for the import triggering the violation
      Returns:
        a new Violation object

    - #### @Deprecated // should really supply a message protected Violation createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)

      Create and return a new Violation for this rule and the specified import

      Parameters:
        `sourceCode` - - the SourceCode
        `importNode` - - the ImportNode for the import triggering the violation
      Returns:
        a new Violation object

    - #### protected Violation createViolationForImport(SourceCode sourceCode, String className, String alias, String violationMessage)

      Create and return a new Violation for this rule and the specified import className and alias

      Parameters:
        `sourceCode` - - the SourceCode
        `className` - - the class name (as specified within the import statement)
        `alias` - - the alias for the import statement
        `violationMessage` - - the violation message; may be null
      Returns:
        a new Violation object

    - #### public String getApplyToFileNames()

    - #### public String getApplyToFilesMatching()

    - #### public int getCompilerPhase()

      Returns:
        the required compiler phase (as in org.codehaus.groovy.control.Phases) of the AST of the SourceCode handed to the rule via applyTo(SourceCode sourceCode)

    - #### public String getDescription()

    - #### public String getDoNotApplyToFileNames()

    - #### public String getDoNotApplyToFilesMatching()

    - #### public String getName()

      Returns:
        the unique name for this rule

    - #### public int getPriority()

      Returns:
        the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive.

    - #### public String getViolationMessage()

    - #### public boolean isEnabled()

    - #### public boolean isReady()

      Allows rules to check whether preconditions are satisfied and short-circuit execution (i.e., do nothing) if those preconditions are not satisfied. Return true by default. This method is provided as a placeholder so subclasses can optionally override.

      Returns:
        true if all preconditions for this rule are satisfied

    - #### public void setApplyToFileNames(String applyToFileNames)

    - #### public void setApplyToFilesMatching(String applyToFilesMatching)

    - #### public void setDescription(String description)

    - #### public void setDoNotApplyToFileNames(String doNotApplyToFileNames)

    - #### public void setDoNotApplyToFilesMatching(String doNotApplyToFilesMatching)

    - #### public void setEnabled(boolean enabled)

    - #### public void setName(String name)

      Set the unique name for this rule

      Parameters:
        `name` - - the name for this rule; this should be unique

    - #### public void setPriority(int priority)

      Set the priority for this rule

      Parameters:
        `priority` - - the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive.

    - #### public void setViolationMessage(String violationMessage)

    - #### public String toString()

    - #### public void validate()

      Allows rules to perform validation. Do nothing by default. This method is provided as a placeholder so subclasses can optionally override. Subclasses will typically use `assert` calls to verify required preconditions.