ParameterName
Since Checkstyle 3.0
Description
accessModifiers property it is possible to specify different formats for methods at different visibility levels.
To validate catch parameters please use CatchParameterName.
To validate lambda parameters please use LambdaParameterName.
Properties
| name | description | type | default value | since |
|---|---|---|---|---|
| accessModifiers | Access modifiers of methods where parameters are checked. | AccessModifierOption[] | public, protected, package, private |
7.5 |
| format | Sets the pattern to match valid identifiers. | Pattern | ^[a-z][a-zA-Z0-9]*$ |
3.0 |
| ignoreOverridden | Allows to skip methods with Override annotation from validation. | boolean | false |
6.12.1 |
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName"/>
</module>
</module>
Code Example:
class Example1 {
void method0(int v) {}
void method1(int v1) {}
void method2(int V2) {} // violation 'Name 'V2' must match pattern'
@Override
public boolean equals(Object V3) { // violation 'Name 'V3' must match pattern'
return true;
}
}
An example of how to configure the check to skip methods with Override annotation from validation:
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="ignoreOverridden" value="true"/>
</module>
</module>
</module>
Code Example:
class Example3 {
void method0(int v) {}
void method1(int v1) {}
void method2(int V2) {} // violation 'Name 'V2' must match pattern'
@Override
public boolean equals(Object V3) {
return true;
}
}
An example of how to configure the check for names that begin with a lower case letter, followed by letters and digits is:
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
</module>
</module>
</module>
Code Example:
class Example4 {
void method0(int v) {} // violation 'Name 'v' must match pattern'
void method1(int v1) {}
void method2(int V2) {} // violation 'Name 'V2' must match pattern'
@Override
public boolean equals(Object V3) { // violation 'Name 'V3' must match pattern'
return true;
}
}
The following configuration checks that the parameters always start with two lowercase characters and, in addition, that public method parameters cannot be one character long:
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="accessModifiers" value="protected, package, private"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''"/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="accessModifiers" value="public"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''"/>
</module>
</module>
</module>
Code Example:
class Example5 {
void method0(int v) {}
void method1(int v1) {}
void method2(int V2) {}
@Override // violation above "Parameter name 'V2' must match pattern"
public boolean equals(Object V3) {
return true; // violation above "Parameter name 'V3' must match pattern"
}
}
An example of how to configure the check for names that begin with a lower case letter, followed by letters, digits, and underscores:
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="format" value="^[a-z][_a-zA-Z0-9]+$"/>
</module>
</module>
</module>
Code Example:
class Example2 {
void method0(int v) {} // violation 'Name 'v' must match pattern'
void method1(int v1) {}
void method2(int V2) {} // violation 'Name 'V2' must match pattern'
@Override
public boolean equals(Object V3) { // violation 'Name 'V3' must match pattern'
return 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.
Fully Qualified Name
com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck
Use this fully qualified class name in configuration when an exact class reference is required.






