MethodParamPad
Since Checkstyle 3.4
Description
Checks the padding between the identifier of a method definition,
constructor definition, method call, constructor invocation, record, or record pattern;
and the left parenthesis of the parameter list. That is, if the
identifier and left parenthesis are on the same line, checks whether
a space is required immediately after the identifier or such a space
is forbidden. If they are not on the same line, reports a violation,
unless configured to allow line breaks. To allow linebreaks after
the identifier, set property
allowLineBreaks
to
true
.
Properties
name | description | type | default value | since |
---|---|---|---|---|
allowLineBreaks | Allow a line break between the identifier and left parenthesis. | boolean | false |
3.4 |
option | Specify policy on how to pad method parameter. | PadOption | nospace |
3.4 |
tokens | tokens to check | subset of tokens CTOR_DEF , CTOR_CALL , LITERAL_NEW , METHOD_CALL , METHOD_DEF , SUPER_CTOR_CALL , ENUM_CONSTANT_DEF , RECORD_DEF , RECORD_PATTERN_DEF . | CTOR_DEF , CTOR_CALL , LITERAL_NEW , METHOD_CALL , METHOD_DEF , SUPER_CTOR_CALL , ENUM_CONSTANT_DEF , RECORD_DEF , RECORD_PATTERN_DEF . | 3.4 |
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="MethodParamPad"/>
</module>
</module>
Example:
class Example1 {
public Example1() {
super();
}
public Example1 (int aParam) { // violation ''(' is preceded with whitespace'
super (); // violation ''(' is preceded with whitespace'
}
public void method() {}
public void methodWithVeryLongName
() {} // violation ''(' should be on the previous line.'
}
To configure the check to require a space after the identifier of a method definition, except if the left parenthesis occurs on a new line:
<module name="Checker">
<module name="TreeWalker">
<module name="MethodParamPad">
<property name="allowLineBreaks" value="true"/>
<property name="option" value="space"/>
<property name="tokens" value="METHOD_DEF"/>
</module>
</module>
</module>
Example:
class Example2 {
public Example2() {
super();
}
public Example2 (int aParam) {
super ();
}
public void method() {} // violation ''(' is not preceded with whitespace'
public void methodWithVeryLongName
() {} // OK, because allowLineBreaks is true
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.whitespace