public class ParameterNumberCheck extends AbstractCheck
Checks the number of parameters that a method or constructor has.
The default allowable number of parameters is 7.
To change the number of allowable parameters, set property max.
Allows to ignore number of parameters for methods with
@Override
annotation.
An example of how to configure the check is:
<module name="ParameterNumber"/>
An example of how to configure the check to allow 10 parameters
and ignoring parameters for methods with @Override
annotation is:
<module name="ParameterNumber"> <property name="max" value="10"/> <property name="ignoreOverriddenMethods" value="true"/> </module>Java code that will be ignored:
@Override
public void needsLotsOfParameters(int a,
int b, int c, int d, int e, int f, int g, int h) {
...
}
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CANONICAL_OVERRIDE
Canonical
Override annotation name. |
private static int |
DEFAULT_MAX_PARAMETERS
Default maximum number of allowed parameters.
|
private boolean |
ignoreOverriddenMethods
Ignore overridden methods.
|
private int |
max
The maximum number of allowed parameters.
|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
private static java.lang.String |
OVERRIDE
Override annotation name. |
Constructor and Description |
---|
ParameterNumberCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
void |
setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
Ignore number of parameters for methods with
@
Override annotation. |
void |
setMax(int max)
Sets the maximum number of allowed parameters.
|
private boolean |
shouldIgnoreNumberOfParameters(DetailAST ast)
Determine whether to ignore number of parameters for the method.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public static final java.lang.String MSG_KEY
private static final java.lang.String OVERRIDE
Override
annotation name.private static final java.lang.String CANONICAL_OVERRIDE
Override
annotation name.private static final int DEFAULT_MAX_PARAMETERS
private int max
private boolean ignoreOverriddenMethods
public void setMax(int max)
max
- the max allowed parameterspublic void setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
Override
annotation.ignoreOverriddenMethods
- set ignore overridden methodspublic int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processprivate boolean shouldIgnoreNumberOfParameters(DetailAST ast)
ast
- the token to process