public abstract class AbstractRule
Abstract superclass for Rules.
Each subclass must define anname
property (String) and a priority
property
(integer 1..3).
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. |
Apply this rule to the specified source and return a list of violations (or an empty List)
sourceCode
- - the source to apply this rule toviolations
- - the List of violations to which new violations from this rule are to be addedApply 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.
sourceCode
- - the source to apply this rule toCreate and return a new Violation for this rule and the specified values
lineNumber
- - the line number for the violation; may be nullsourceLine
- - the source line for the violation; may be nullmessage
- - the message for the violation; may be nullCreate and return a new Violation for this rule and the specified values
lineNumber
- - the line number for the violation; may be nullCreate and return a new Violation for this rule and the specified values
lineNumber
- - the line number for the violation; may be nullCreate a new Violation for the AST node.
sourceCode
- - the SourceCodenode
- - the Groovy AST Nodemessage
- - the message for the violation; defaults to nullCreate a new Violation for the AST node.
sourceCode
- - the SourceCodenode
- - the Groovy AST NodeCreate and return a new Violation for this rule and the specified import
sourceCode
- - the SourceCodeimportNode
- - the ImportNode for the import triggering the violationCreate and return a new Violation for this rule and the specified import
sourceCode
- - the SourceCodeimportNode
- - the ImportNode for the import triggering the violationCreate and return a new Violation for this rule and the specified import className and alias
sourceCode
- - the SourceCodeclassName
- - the class name (as specified within the import statement)alias
- - the alias for the import statementviolationMessage
- - the violation message; may be null
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.
Set the unique name for this rule
name
- - the name for this rule; this should be uniqueSet the priority for this rule
priority
- - the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive. 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.