Since Checkstyle 3.0
Checks the number of parameters of a method or constructor.
name | description | type | default value | since |
---|---|---|---|---|
max | Specify the maximum number of parameters allowed. | int | 7 |
3.0 |
ignoreOverriddenMethods |
Ignore number of parameters for methods with @Override annotation.
|
boolean | false |
6.2 |
tokens | tokens to check | subset of tokens METHOD_DEF , CTOR_DEF . | METHOD_DEF , CTOR_DEF . | 3.0 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="ParameterNumber"/> </module> </module>
To configure the check to allow 10 parameters for a method:
<module name="Checker"> <module name="TreeWalker"> <module name="ParameterNumber"> <property name="max" value="10"/> <property name="tokens" value="METHOD_DEF"/> </module> </module> </module>
To configure the check to ignore number of parameters for methods with
@Override
or @java.lang.Override annotation
.
Rationale: developer may need to override method with many parameters from 3-rd party library. In this case developer has no control over number of parameters.
<module name="Checker"> <module name="TreeWalker"> <module name="ParameterNumber"> <property name="ignoreOverriddenMethods" value="true"/> </module> </module> </module>
Java code example:
@Override public void needsLotsOfParameters(int a, int b, int c, int d, int e, int f, int g, int h) { ... }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.sizes