Class AbstractAddonsCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.thomasjensen.checkstyle.addons.checks.AbstractAddonsCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
- Direct Known Subclasses:
AbstractMethodCallCheck
,LostInstanceCheck
,PropertyCatalogCheck
,RegexpOnStringCheck
public abstract class AbstractAddonsCheck extends AbstractCheck
Base class of all Checkstyle Addons checks.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractAddonsCheck()
protected
AbstractAddonsCheck(String pMockfile)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
beginTree(DetailAST pRootAst)
void
finishTree(DetailAST pRootAst)
protected void
finishTree(BinaryName pOuterClassName, DetailAST pRootAst)
Called after a tree is fully processed.int[]
getAcceptableTokens()
protected CheckstyleApiFixer
getApiFixer()
protected DetailAST
getClassDeclarationPosition(BinaryName pBinaryName)
protected BinaryName
getCurrentBinaryName()
Gets the binary name of the class currently being traversed on the AST.protected String
getCurrentSimpleName()
Gets the simple name of the current class, interface, annotation, or enum.int[]
getDefaultTokens()
protected String
getMyPackage()
abstract Set<Integer>
getRelevantTokens()
The tokens which this check is interested in.int[]
getRequiredTokens()
protected void
leaveKnownType(BinaryName pBinaryClassName, DetailAST pAst)
Called after leaving a CLASS_DEF, INTERFACE_DEF, ANNOTATION_DEF, or ENUM_DEF token and the type's binary class name is known.void
leaveToken(DetailAST pAst)
protected void
leaveToken(BinaryName pBinaryClassName, DetailAST pAst)
Called after all the child nodes have been processed.protected void
visitKnownType(BinaryName pBinaryClassName, DetailAST pAst)
Called after visiting a CLASS_DEF, INTERFACE_DEF, ANNOTATION_DEF, or ENUM_DEF token and successfully determining the type's binary class name.void
visitToken(DetailAST pAst)
protected void
visitToken(BinaryName pBinaryClassName, DetailAST pAst)
Called to process a token.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Method Detail
-
getRelevantTokens
public abstract Set<Integer> getRelevantTokens()
The tokens which this check is interested in. Will be added to the tokens of the base class.- Returns:
- the relevant tokens
-
getRequiredTokens
public final int[] getRequiredTokens()
- Specified by:
getRequiredTokens
in classAbstractCheck
-
getAcceptableTokens
public final int[] getAcceptableTokens()
- Specified by:
getAcceptableTokens
in classAbstractCheck
-
getDefaultTokens
public final int[] getDefaultTokens()
- Specified by:
getDefaultTokens
in classAbstractCheck
-
beginTree
public void beginTree(DetailAST pRootAst)
- Overrides:
beginTree
in classAbstractCheck
-
finishTree
public final void finishTree(DetailAST pRootAst)
- Overrides:
finishTree
in classAbstractCheck
-
finishTree
protected void finishTree(@Nonnull BinaryName pOuterClassName, @Nonnull DetailAST pRootAst)
Called after a tree is fully processed. Ideal place to report on information collected whilst processing a tree.- Parameters:
pOuterClassName
- the fully qualified class name of the outer classpRootAst
- the root of the tree
-
visitToken
protected void visitToken(@Nullable BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Called to process a token.- Parameters:
pBinaryClassName
- the currently active binary class namepAst
- the token to process
-
leaveToken
protected void leaveToken(@Nullable BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Called after all the child nodes have been processed.- Parameters:
pBinaryClassName
- the currently active binary class namepAst
- the token being completed
-
visitKnownType
protected void visitKnownType(@Nonnull BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Called after visiting a CLASS_DEF, INTERFACE_DEF, ANNOTATION_DEF, or ENUM_DEF token and successfully determining the type's binary class name. This is useful in a Java source file with nested inner classes. If the implementing check registers for any of the above tokens, the regular call tovisitToken(BinaryName, DetailAST)
will be performed in addition to (after) this one.- Parameters:
pBinaryClassName
- the binary class name of the visited typepAst
- the token to process
-
leaveKnownType
protected void leaveKnownType(@Nonnull BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Called after leaving a CLASS_DEF, INTERFACE_DEF, ANNOTATION_DEF, or ENUM_DEF token and the type's binary class name is known. This is useful in a Java source file with nested inner classes. If the implementing check registers for any of the above tokens, the regular call toleaveToken(BinaryName, DetailAST)
will be performed in addition to (before) this one.- Parameters:
pBinaryClassName
- the binary class name of the visited typepAst
- the token being completed
-
visitToken
public final void visitToken(DetailAST pAst)
- Overrides:
visitToken
in classAbstractCheck
-
getClassDeclarationPosition
@CheckForNull protected DetailAST getClassDeclarationPosition(@Nonnull BinaryName pBinaryName)
-
leaveToken
public final void leaveToken(DetailAST pAst)
- Overrides:
leaveToken
in classAbstractCheck
-
getCurrentBinaryName
@CheckForNull protected BinaryName getCurrentBinaryName()
Gets the binary name of the class currently being traversed on the AST. Normally, this is the single class in the .java file, but it could also be a (nested) named inner class. Whenever a new CLASS_DEF or similar token is visited, the result of this method would change.- Returns:
- current binary name, or
null
if no CLASS_DEF or similar token has been encountered yet (e.g. while we are still going through theimport
statements)
-
getCurrentSimpleName
@CheckForNull protected String getCurrentSimpleName()
Gets the simple name of the current class, interface, annotation, or enum.- Returns:
- the simple class name, or
null
if we are outside of a type definition
-
getMyPackage
protected String getMyPackage()
-
getApiFixer
@Nonnull protected CheckstyleApiFixer getApiFixer()
-
-