public abstract class AbstractRule extends Object implements Rule
name
property (String) and a priority
property
(integer 1..3).Constructor and Description |
---|
AbstractRule() |
Modifier and Type | Method and Description |
---|---|
List<Violation> |
applyTo(SourceCode sourceCode)
Apply this rule to the specified source and return a list of violations (or an empty List).
|
abstract void |
applyTo(SourceCode sourceCode,
List<Violation> violations)
Apply this rule to the specified source and return a list of violations (or an empty List)
|
protected Violation |
createViolation(Integer lineNumber)
Deprecated.
|
protected Violation |
createViolation(Integer lineNumber,
String message)
Deprecated.
|
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(SourceCode sourceCode,
org.codehaus.groovy.ast.ASTNode node)
Deprecated.
|
protected Violation |
createViolation(SourceCode sourceCode,
org.codehaus.groovy.ast.ASTNode node,
String message)
Create a new Violation for the AST node.
|
protected Violation |
createViolationForImport(SourceCode sourceCode,
org.codehaus.groovy.ast.ImportNode importNode)
Deprecated.
|
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,
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() |
String |
getDescription() |
String |
getDoNotApplyToFileNames() |
String |
getDoNotApplyToFilesMatching() |
abstract String |
getName() |
abstract int |
getPriority() |
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) |
abstract void |
setName(String name)
Set the unique name for this rule
|
abstract void |
setPriority(int priority)
Set the priority for this rule
|
void |
setViolationMessage(String violationMessage) |
String |
toString() |
void |
validate()
Allows rules to perform validation.
|
public abstract String getName()
public abstract void setName(String name)
name
- - the name for this rule; this should be uniquepublic abstract int getPriority()
getPriority
in interface Rule
public abstract void setPriority(int priority)
priority
- - the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive.public int getCompilerPhase()
getCompilerPhase
in interface Rule
Phases
)
of the AST of the SourceCode
handed to the rule via applyTo(SourceCode sourceCode)
public abstract void applyTo(SourceCode sourceCode, List<Violation> violations)
sourceCode
- - the source to apply this rule toviolations
- - the List of violations to which new violations from this rule are to be addedpublic List<Violation> applyTo(SourceCode sourceCode) throws Throwable
public boolean isReady()
public void validate()
assert
calls to verify required preconditions.protected Violation createViolation(Integer lineNumber, String sourceLine, String message)
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 null@Deprecated protected Violation createViolation(Integer lineNumber, String message)
lineNumber
- - the line number for the violation; may be null@Deprecated protected Violation createViolation(Integer lineNumber)
lineNumber
- - the line number for the violation; may be nullprotected Violation createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node, String message)
sourceCode
- - the SourceCodenode
- - the Groovy AST Nodemessage
- - the message for the violation; defaults to null@Deprecated protected Violation createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node)
sourceCode
- - the SourceCodenode
- - the Groovy AST Nodeprotected Violation createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode, String message)
sourceCode
- - the SourceCodeimportNode
- - the ImportNode for the import triggering the violation@Deprecated protected Violation createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)
sourceCode
- - the SourceCodeimportNode
- - the ImportNode for the import triggering the violationprotected Violation createViolationForImport(SourceCode sourceCode, String className, String alias, String violationMessage)
sourceCode
- - the SourceCodeclassName
- - the class name (as specified within the import statement)alias
- - the alias for the import statementviolationMessage
- - the violation message; may be nullpublic boolean isEnabled()
public void setEnabled(boolean enabled)
public String getApplyToFilesMatching()
public void setApplyToFilesMatching(String applyToFilesMatching)
public String getDoNotApplyToFilesMatching()
public void setDoNotApplyToFilesMatching(String doNotApplyToFilesMatching)
public String getApplyToFileNames()
public void setApplyToFileNames(String applyToFileNames)
public String getDoNotApplyToFileNames()
public void setDoNotApplyToFileNames(String doNotApplyToFileNames)
public String getViolationMessage()
public void setViolationMessage(String violationMessage)
public String getDescription()
public void setDescription(String description)
Copyright © 2022. All rights reserved.