|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD |
java.lang.Objectorg.codenarc.rule.AbstractRule
@SuppressWarnings('DuplicateLiteral') abstract class AbstractRule
Abstract superclass for Rules.
Each subclass must define anname
property (String) and a priority
property
(integer 1..3).
Property Summary | |
---|---|
static def |
LOG
|
String |
applyToFileNames
This rule is only applied to source code (file) names matching this value. |
String |
applyToFilesMatching
This rule is only applied to source code (file) pathnames matching this regular expression. |
String |
description
If not null, this is used as the description text for this rule, overriding any description text found in the i18n resource bundles. |
String |
doNotApplyToFileNames
This rule is NOT applied to source code (file) names matching this value. |
String |
doNotApplyToFilesMatching
This rule is NOT applied to source code (file) pathnames matching this regular expression. |
boolean |
enabled
Flag indicating whether this rule should be enabled (applied). |
String |
violationMessage
If not null, this is used as the message for all violations of this rule, overriding any message generated by the concrete rule subclass. |
Method Summary | |
---|---|
void
|
applyTo(SourceCode sourceCode, List violations)
Apply this rule to the specified source and return a list of violations (or an empty List) |
List
|
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 = null, String message = null)
Create and return a new Violation for this rule and the specified values |
protected Violation
|
createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node, def message = null)
Create a new Violation for the AST node. |
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)
Create and return a new Violation for this rule and the specified import className and alias |
protected List
|
getImportsSortedByLineNumber(def sourceCode)
|
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. |
boolean
|
isReady()
Allows rules to check whether preconditions are satisfied and short-circuit execution (i.e., do nothing) if those preconditions are not satisfied. |
protected String
|
packageNameForImport(org.codehaus.groovy.ast.ImportNode importNode)
Return the package name for the specified import statement or else an empty String |
void
|
setName(String name)
Set the unique name for this rule |
void
|
setPriority(int priority)
Set the priority for this rule |
protected def
|
sourceLineAndNumberForImport(SourceCode sourceCode, String className, String alias)
Return the source line and line number for the specified import class name and alias |
protected def
|
sourceLineAndNumberForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)
Return the source line and line number for the specified import |
String
|
toString()
|
void
|
validate()
Allows rules to perform validation. |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Property Detail |
---|
static final def LOG
String applyToFileNames
String applyToFilesMatching
String description
String doNotApplyToFileNames
String doNotApplyToFilesMatching
boolean enabled
String violationMessage
Method Detail |
---|
void applyTo(SourceCode sourceCode, List violations)
source
- - the source to apply this rule toviolations
- - the List of violations to which new violations from this rule are to be added
List applyTo(SourceCode sourceCode)
source
- - the source to apply this rule to
protected Violation createViolation(Integer lineNumber, String sourceLine = null, String message = null)
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
protected Violation createViolation(SourceCode sourceCode, org.codehaus.groovy.ast.ASTNode node, def message = null)
sourceCode
- - the SourceCodenode
- - the Groovy AST Nodemessage
- - the message for the violation; defaults to null
protected Violation createViolationForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)
sourceCode
- - the SourceCodeimportNode
- - the ImportNode for the import triggering the violation
protected Violation createViolationForImport(SourceCode sourceCode, String className, String alias)
sourceCode
- - the SourceCodeclassName
- - the class name (as specified within the import statemenet)alias
- - the alias for the import statemenet
protected List getImportsSortedByLineNumber(def sourceCode)
String getName()
int getPriority()
boolean isReady()
protected String packageNameForImport(org.codehaus.groovy.ast.ImportNode importNode)
importNode
- - the ImportNode for the import
void setName(String name)
name
- - the name for this rule; this should be unique
void setPriority(int priority)
priority
- - the priority of this rule, between 1 (highest priority) and 3 (lowest priority), inclusive.
protected def sourceLineAndNumberForImport(SourceCode sourceCode, String className, String alias)
sourceCode
- - the SourceCode being processedimportNode
- - the ImportNode representing the import
protected def sourceLineAndNumberForImport(SourceCode sourceCode, org.codehaus.groovy.ast.ImportNode importNode)
sourceCode
- - the SourceCode being processedimportNode
- - the ImportNode representing the import
String toString()
@SuppressWarnings('EmptyMethodInAbstractClass') void validate()
assert
calls to verify required preconditions.
Groovy Documentation