com.puppycrawl.tools.checkstyle.api
Class Check

java.lang.Object
  extended by com.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended by com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended by com.puppycrawl.tools.checkstyle.api.Check
All Implemented Interfaces:
Configurable, Contextualizable
Direct Known Subclasses:
AbstractClassCouplingCheck, AbstractComplexityCheck, AbstractFormatCheck, AbstractIllegalCheck, AbstractIllegalMethodCheck, AbstractNestedDepthCheck, AbstractOptionCheck, AbstractSuperCheck, AbstractTypeAwareCheck, AnnotationUseStyleCheck, AnonInnerLengthCheck, ArrayTrailingCommaCheck, ArrayTypeStyleCheck, AvoidInlineConditionalsCheck, AvoidNestedBlocksCheck, AvoidStarImportCheck, AvoidStaticImportCheck, BooleanExpressionComplexityCheck, CovariantEqualsCheck, DeclarationCollector, DeclarationOrderCheck, DefaultComesLastCheck, DescendantTokenCheck, DesignForExtensionCheck, EmptyStatementCheck, EqualsAvoidNullCheck, EqualsHashCodeCheck, ExecutableStatementCountCheck, ExplicitInitializationCheck, FallThroughCheck, FileContentsHolder, FinalClassCheck, FinalLocalVariableCheck, FinalParametersCheck, GenericWhitespaceCheck, HiddenFieldCheck, HideUtilityClassConstructorCheck, IllegalImportCheck, IllegalInstantiationCheck, IllegalTokenCheck, ImportControlCheck, IndentationCheck, InnerAssignmentCheck, InnerTypeLastCheck, InterfaceIsTypeCheck, JavadocStyleCheck, JavadocTypeCheck, JavadocVariableCheck, JavaNCSSCheck, JUnitTestCaseCheck, LineLengthCheck, MagicNumberCheck, MethodCountCheck, MethodLengthCheck, MissingDeprecatedCheck, MissingOverrideCheck, ModifiedControlVariableCheck, ModifierOrderCheck, MultipleStringLiteralsCheck, MultipleVariableDeclarationsCheck, NeedBracesCheck, NoWhitespaceAfterCheck, NoWhitespaceBeforeCheck, OneStatementPerLineCheck, OuterTypeFilenameCheck, OuterTypeNumberCheck, PackageAnnotationCheck, PackageDeclarationCheck, ParameterAssignmentCheck, ParameterNumberCheck, RedundantImportCheck, RedundantModifierCheck, RegexpSinglelineJavaCheck, SimplifyBooleanExpressionCheck, SimplifyBooleanReturnCheck, StringLiteralEqualityCheck, SuppressWarningsHolder, ThrowsCountCheck, UncommentedMainCheck, UnnecessaryParenthesesCheck, UnusedImportsCheck, UpperEllCheck, VisibilityModifierCheck, WhitespaceAfterCheck, WhitespaceAroundCheck, WriteTagCheck

public abstract class Check
extends AbstractViolationReporter

The base class for checks.

Version:
1.0
Author:
Oliver Burn
See Also:
Writing your own checks

Constructor Summary
Check()
           
 
Method Summary
 void beginTree(DetailAST aRootAST)
          Called before the starting to process a tree.
 void destroy()
          Destroy the check.
 void finishTree(DetailAST aRootAST)
          Called after finished processing a tree.
 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[] getLines()
          Returns the lines associated with the tree.
 int[] getRequiredTokens()
          The tokens that this check must be registered for.
protected  int getTabWidth()
           
 Set<String> getTokenNames()
          Returns the tokens registered for the check.
 void init()
          Initialise the check.
 void leaveToken(DetailAST aAST)
          Called after all the child nodes have been process.
 void log(int aLineNo, int aColNo, String aKey, Object... aArgs)
          Log a message that has column information.
 void log(int aLine, String aKey, Object... aArgs)
          Log a message that has no column information.
 void setClassLoader(ClassLoader aLoader)
          Set the class loader associated with the tree.
 void setFileContents(FileContents aContents)
          Set the file contents associated with the tree.
 void setMessages(LocalizedMessages aMessages)
          Set the global object used to collect messages.
 void setTabWidth(int aTabWidth)
          Set the tab width to report errors with.
 void setTokens(String[] aStrRep)
          Adds a set of tokens the check is interested in.
 void visitToken(DetailAST aAST)
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Check

public Check()
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 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 int[] getRequiredTokens()
The tokens that this check must be registered for.

Returns:
the token set this must be registered for.
See Also:
TokenTypes

setTokens

public final void setTokens(String[] aStrRep)
Adds a set of tokens the check is interested in.

Parameters:
aStrRep - 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 aMessages)
Set the global object used to collect messages.

Parameters:
aMessages - the messages to log with

init

public void init()
Initialise 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 aRootAST)
Called before the starting to process a tree. Ideal place to initialise information that is to be collected whilst processing a tree.

Parameters:
aRootAST - the root of the tree

finishTree

public void finishTree(DetailAST aRootAST)
Called after finished processing a tree. Ideal place to report on information collected whilst processing a tree.

Parameters:
aRootAST - the root of the tree

visitToken

public void visitToken(DetailAST aAST)
Called to process a token.

Parameters:
aAST - the token to process

leaveToken

public void leaveToken(DetailAST aAST)
Called after all the child nodes have been process.

Parameters:
aAST - the token leaving

getLines

public final String[] getLines()
Returns the lines associated with the tree.

Returns:
the file contents

setFileContents

public final void setFileContents(FileContents aContents)
Set the file contents associated with the tree.

Parameters:
aContents - 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 aLoader)
Set the class loader associated with the tree.

Parameters:
aLoader - 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()
Returns:
the tab width to report errors with

setTabWidth

public final void setTabWidth(int aTabWidth)
Set the tab width to report errors with.

Parameters:
aTabWidth - an int value

log

public final void log(int aLine,
                      String aKey,
                      Object... aArgs)
Description copied from class: AbstractViolationReporter
Log a message that has no column information.

Specified by:
log in class AbstractViolationReporter
Parameters:
aLine - the line number where the error was found
aKey - the message that describes the error
aArgs - the details of the message
See Also:
MessageFormat

log

public final void log(int aLineNo,
                      int aColNo,
                      String aKey,
                      Object... aArgs)
Description copied from class: AbstractViolationReporter
Log a message that has column information.

Specified by:
log in class AbstractViolationReporter
Parameters:
aLineNo - the line number where the error was found
aColNo - the column number where the error was found
aKey - the message that describes the error
aArgs - the details of the message
See Also:
MessageFormat


Copyright © 2001-2014. All Rights Reserved.