Class AbstractCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
- Direct Known Subclasses:
AbbreviationAsWordInNameCheck
,AbstractClassCouplingCheck
,AbstractClassNameCheck
,AbstractComplexityCheck
,AbstractDeclarationCollector
,AbstractFormatCheck
,AbstractIllegalCheck
,AbstractIllegalMethodCheck
,AbstractJavadocCheck
,AbstractNameCheck
,AbstractNestedDepthCheck
,AbstractOptionCheck
,AbstractParenPadCheck
,AbstractSuperCheck
,AbstractTypeAwareCheck
,AnnotationLocationCheck
,AnnotationUseStyleCheck
,AnonInnerLengthCheck
,ArrayTrailingCommaCheck
,ArrayTypeStyleCheck
,AvoidEscapedUnicodeCharactersCheck
,AvoidInlineConditionalsCheck
,AvoidNestedBlocksCheck
,AvoidStarImportCheck
,AvoidStaticImportCheck
,BooleanExpressionComplexityCheck
,CommentsIndentationCheck
,CovariantEqualsCheck
,CustomImportOrderCheck
,CyclomaticComplexityCheck
,DeclarationOrderCheck
,DefaultComesLastCheck
,DescendantTokenCheck
,DesignForExtensionCheck
,EmptyBlockCheck
,EmptyCatchBlockCheck
,EmptyForInitializerPadCheck
,EmptyForIteratorPadCheck
,EmptyLineSeparatorCheck
,EmptyStatementCheck
,EqualsAvoidNullCheck
,EqualsHashCodeCheck
,ExecutableStatementCountCheck
,ExplicitInitializationCheck
,FallThroughCheck
,FileContentsHolder
,FinalClassCheck
,FinalLocalVariableCheck
,FinalParametersCheck
,GenericWhitespaceCheck
,HiddenFieldCheck
,HideUtilityClassConstructorCheck
,IllegalCatchCheck
,IllegalImportCheck
,IllegalInstantiationCheck
,IllegalThrowsCheck
,IllegalTokenCheck
,IllegalTokenTextCheck
,IllegalTypeCheck
,ImportControlCheck
,ImportOrderCheck
,IndentationCheck
,InnerAssignmentCheck
,InnerTypeLastCheck
,InterfaceIsTypeCheck
,JavadocStyleCheck
,JavadocTypeCheck
,JavadocVariableCheck
,JavaNCSSCheck
,LeftCurlyCheck
,LineLengthCheck
,MagicNumberCheck
,MethodCountCheck
,MethodLengthCheck
,MethodParamPadCheck
,MissingCtorCheck
,MissingDeprecatedCheck
,MissingOverrideCheck
,MissingSwitchDefaultCheck
,ModifiedControlVariableCheck
,ModifierOrderCheck
,MultipleStringLiteralsCheck
,MultipleVariableDeclarationsCheck
,MutableExceptionCheck
,NeedBracesCheck
,NestedForDepthCheck
,NestedIfDepthCheck
,NestedTryDepthCheck
,NoCloneCheck
,NoFinalizerCheck
,NoLineWrapCheck
,NoWhitespaceAfterCheck
,NoWhitespaceBeforeCheck
,NPathComplexityCheck
,OneStatementPerLineCheck
,OneTopLevelClassCheck
,OperatorWrapCheck
,OuterTypeFilenameCheck
,OuterTypeNumberCheck
,OverloadMethodsDeclarationOrderCheck
,PackageAnnotationCheck
,PackageDeclarationCheck
,PackageNameCheck
,ParameterAssignmentCheck
,ParameterNumberCheck
,RedundantImportCheck
,RedundantModifierCheck
,RegexpCheck
,RegexpSinglelineJavaCheck
,RequireThisCheck
,ReturnCountCheck
,RightCurlyCheck
,SeparatorWrapCheck
,SimplifyBooleanExpressionCheck
,SimplifyBooleanReturnCheck
,SingleSpaceSeparatorCheck
,StringLiteralEqualityCheck
,SuppressWarningsCheck
,SuppressWarningsHolder
,ThrowsCountCheck
,TodoCommentCheck
,TrailingCommentCheck
,UncommentedMainCheck
,UnnecessaryParenthesesCheck
,UnusedImportsCheck
,UpperEllCheck
,VariableDeclarationUsageDistanceCheck
,VisibilityModifierCheck
,WhitespaceAfterCheck
,WhitespaceAroundCheck
,WriteTagCheck
public abstract class AbstractCheck extends AbstractViolationReporter
The base class for checks.- Author:
- Oliver Burn
- See Also:
- Writing your own checks
-
-
Constructor Summary
Constructors Constructor Description AbstractCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
beginTree(DetailAST rootAST)
Called before the starting to process a tree.void
destroy()
Destroy the check.void
finishTree(DetailAST rootAST)
Called after finished processing a tree.abstract int[]
getAcceptableTokens()
The configurable token set.ClassLoader
getClassLoader()
Returns the class loader associated with the tree.abstract int[]
getDefaultTokens()
Returns the default token a check is interested in.FileContents
getFileContents()
Returns the file contents associated with the tree.String
getLine(int index)
Returns the line associated with the tree.String[]
getLines()
Returns the lines associated with the tree.abstract int[]
getRequiredTokens()
The tokens that this check must be registered for.protected int
getTabWidth()
Get tab width to report errors with.Set<String>
getTokenNames()
Returns the tokens registered for the check.void
init()
Initialize the check.boolean
isCommentNodesRequired()
Whether comment nodes are required or not.void
leaveToken(DetailAST ast)
Called after all the child nodes have been process.void
log(int lineNo, int colNo, String key, Object... args)
Log a message that has column information.void
log(int line, String key, Object... args)
Log a message that has no column information.void
setClassLoader(ClassLoader classLoader)
Set the class loader associated with the tree.void
setFileContents(FileContents contents)
Set the file contents associated with the tree.void
setMessages(LocalizedMessages messages)
Set the global object used to collect messages.void
setTabWidth(int tabWidth)
Set the tab width to report errors with.void
setTokens(String... strRep)
Adds a set of tokens the check is interested in.void
visitToken(DetailAST ast)
Called to process a token.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
-
-
-
-
Constructor Detail
-
AbstractCheck
public AbstractCheck()
-
-
Method Detail
-
getDefaultTokens
public abstract int[] getDefaultTokens()
Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Returns:
- the default tokens
- See Also:
TokenTypes
-
getAcceptableTokens
public abstract int[] getAcceptableTokens()
The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Returns:
- the token set this check is designed for.
- See Also:
TokenTypes
-
getRequiredTokens
public abstract int[] getRequiredTokens()
The tokens that this check must be registered for.- Returns:
- the token set this must be registered for.
- See Also:
TokenTypes
-
isCommentNodesRequired
public boolean isCommentNodesRequired()
Whether comment nodes are required or not.- Returns:
- false as a default value.
-
setTokens
public final void setTokens(String... strRep)
Adds a set of tokens the check is interested in.- Parameters:
strRep
- the string representation of the tokens interested in
-
getTokenNames
public final Set<String> getTokenNames()
Returns the tokens registered for the check.- Returns:
- the set of token names
-
setMessages
public final void setMessages(LocalizedMessages messages)
Set the global object used to collect messages.- Parameters:
messages
- the messages to log with
-
init
public void init()
Initialize the check. This is the time to verify that the check has everything required to perform it job.
-
destroy
public void destroy()
Destroy the check. It is being retired from service.
-
beginTree
public void beginTree(DetailAST rootAST)
Called before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Parameters:
rootAST
- the root of the tree
-
finishTree
public void finishTree(DetailAST rootAST)
Called after finished processing a tree. Ideal place to report on information collected whilst processing a tree.- Parameters:
rootAST
- the root of the tree
-
visitToken
public void visitToken(DetailAST ast)
Called to process a token.- Parameters:
ast
- the token to process
-
leaveToken
public void leaveToken(DetailAST ast)
Called after all the child nodes have been process.- Parameters:
ast
- the token leaving
-
getLines
public final String[] getLines()
Returns the lines associated with the tree.- Returns:
- the file contents
-
getLine
public final String getLine(int index)
Returns the line associated with the tree.- Parameters:
index
- index of the line- Returns:
- the line from the file contents
-
setFileContents
public final void setFileContents(FileContents contents)
Set the file contents associated with the tree.- Parameters:
contents
- the manager
-
getFileContents
public final FileContents getFileContents()
Returns the file contents associated with the tree.- Returns:
- the file contents
-
setClassLoader
public final void setClassLoader(ClassLoader classLoader)
Set the class loader associated with the tree.- Parameters:
classLoader
- the class loader
-
getClassLoader
public final ClassLoader getClassLoader()
Returns the class loader associated with the tree.- Returns:
- the class loader
-
getTabWidth
protected final int getTabWidth()
Get tab width to report errors with.- Returns:
- the tab width to report errors with
-
setTabWidth
public final void setTabWidth(int tabWidth)
Set the tab width to report errors with.- Parameters:
tabWidth
- anint
value
-
log
public final void log(int line, String key, Object... args)
Description copied from class:AbstractViolationReporter
Log a message that has no column information.- Specified by:
log
in classAbstractViolationReporter
- Parameters:
line
- the line number where the error was foundkey
- the message that describes the errorargs
- the details of the message- See Also:
MessageFormat
-
log
public final void log(int lineNo, int colNo, String key, Object... args)
Description copied from class:AbstractViolationReporter
Log a message that has column information.- Specified by:
log
in classAbstractViolationReporter
- Parameters:
lineNo
- the line number where the error was foundcolNo
- the column number where the error was foundkey
- the message that describes the errorargs
- the details of the message- See Also:
MessageFormat
-
-