Class AbstractMethodCallCheck
- 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
-
- com.thomasjensen.checkstyle.addons.checks.AbstractMethodCallCheck
-
- All Implemented Interfaces:
Configurable,Contextualizable
- Direct Known Subclasses:
IllegalMethodCallCheck,LocationReferenceCheck
public abstract class AbstractMethodCallCheck extends AbstractAddonsCheck
Checks deriving from this type are aware of method calls occurring anywhere in the source, and get explicitly notified when such calls are encountered. The full qualifier of the call is provided.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Constructor Summary
Constructors Constructor Description AbstractMethodCallCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidbeginTree(DetailAST pRootAst)StringgetCurrentMethodName()The current method name.Set<Integer>getRelevantTokens()The tokens which this check is interested in.protected abstract booleanisCheckActive()Determines if the check is configured to do anything at all.protected abstract booleanisRelevantCall(String pQualifier, String pMethodName)Filter method which determines if the given method call is considered relevant.protected voidleaveToken(BinaryName pBinaryClassName, DetailAST pAst)Called after all the child nodes have been processed.protected abstract voidvisitMethodCall(String pMethodName, DetailAST pMethodCallAst)Visitor method called when a relevant method call is encountered.protected voidvisitToken(BinaryName pBinaryClassName, DetailAST pAst)Called to process a token.-
Methods inherited from class com.thomasjensen.checkstyle.addons.checks.AbstractAddonsCheck
finishTree, finishTree, getAcceptableTokens, getApiFixer, getClassDeclarationPosition, getCurrentBinaryName, getCurrentSimpleName, getDefaultTokens, getMyPackage, getRequiredTokens, leaveKnownType, leaveToken, visitKnownType, visitToken
-
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 Set<Integer> getRelevantTokens()
Description copied from class:AbstractAddonsCheckThe tokens which this check is interested in. Will be added to the tokens of the base class.- Specified by:
getRelevantTokensin classAbstractAddonsCheck- Returns:
- the relevant tokens
-
isCheckActive
protected abstract boolean isCheckActive()
Determines if the check is configured to do anything at all.- Returns:
trueif processing should be performed
-
isRelevantCall
protected abstract boolean isRelevantCall(@Nullable String pQualifier, @Nonnull String pMethodName)
Filter method which determines if the given method call is considered relevant.- Parameters:
pQualifier- the qualifier of the method call (for a call likeFoo.Bar.call(), the qualifier isFoo.Bar)pMethodName- the simple name of the called method- Returns:
- indication of whether the call is relevant (
true) or not (false)
-
visitMethodCall
protected abstract void visitMethodCall(@Nonnull String pMethodName, @Nonnull DetailAST pMethodCallAst)
Visitor method called when a relevant method call is encountered. This method is called in addition to the other visitor methods.- Parameters:
pMethodName- the simple name of the called methodpMethodCallAst- AST of the call, useful for logging issues ( this is a METHOD_DEF, CTOR_CALL, or a SUPER_CTOR_CALL token)
-
getCurrentMethodName
@CheckForNull public String getCurrentMethodName()
The current method name."<init>"is used for constructors and instance initializers, and"<clinit>"is used for static initializers.- Returns:
- the method name, or
nullif we are not inside a method, constructor, or initializer
-
beginTree
public void beginTree(DetailAST pRootAst)
- Overrides:
beginTreein classAbstractAddonsCheck
-
visitToken
protected void visitToken(@Nullable BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Description copied from class:AbstractAddonsCheckCalled to process a token.- Overrides:
visitTokenin classAbstractAddonsCheck- Parameters:
pBinaryClassName- the currently active binary class namepAst- the token to process
-
leaveToken
protected void leaveToken(@Nullable BinaryName pBinaryClassName, @Nonnull DetailAST pAst)
Description copied from class:AbstractAddonsCheckCalled after all the child nodes have been processed.- Overrides:
leaveTokenin classAbstractAddonsCheck- Parameters:
pBinaryClassName- the currently active binary class namepAst- the token being completed
-
-