Class StaticMethodCandidateCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.github.sevntu.checkstyle.checks.design.StaticMethodCandidateCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable
,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class StaticMethodCandidateCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Checks whetherprivate
methods can be declared asstatic
.The check has option
skippedMethods
which allows to specify the list of comma separated names of methods to skip during the check. By default the private methods which a class can have when it implements Serializable are skipped: "readObject, writeObject, readObjectNoData, readResolve, writeReplace".The following configuration allows to skip method
foo
andbar
:<module name="NestedSwitchCheck"> <property name="skippedMethods" value="foo, bar"/> </module>
Limitations:
- Due to limitation of Checkstyle, there is no ability to distinguish overloaded methods, so we skip them from candidates.
- Private methods called by reflection are not supported and have to be suppressed.
- Since:
- 1.17.0
- Author:
- Vladislav Lisetskiy
-
-
Constructor Summary
Constructors Constructor Description StaticMethodCandidateCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
void
finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
int[]
getAcceptableTokens()
int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
leaveToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
void
setSkippedMethods(String skippedMethods)
Sets custom skipped methods.void
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, getFileContents, getFilePath, 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
-
-
-
-
Field Detail
-
MSG_KEY
public static final String MSG_KEY
Warning message key.- See Also:
- Constant Field Values
-
-
Method Detail
-
setSkippedMethods
public void setSkippedMethods(String skippedMethods)
Sets custom skipped methods.- Parameters:
skippedMethods
- user's skipped methods.
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
beginTree
public void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
- Overrides:
beginTree
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
visitToken
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
leaveToken
public void leaveToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
leaveToken
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
finishTree
public void finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
finishTree
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
-