Overview

Each of these naming modules validates identifiers for particular code elements. Valid identifiers for a naming module are specified by its format property. The value of format is a regular expression for valid identifiers.

AbbreviationAsWordInName

Description

The Check validate abbreviations(consecutive capital letters) length in identifier name, it also allows to enforce camel case naming. Please read more at Google Style Guide to get to know how to avoid long abbreviations in names.

Properties

name description type default value
allowedAbbreviationLength indicates on the allowed amount of capital letters in targeted identifiers (abbreviations in the classes, interfaces, variables and methods names, ... ). 3 true
allowedAbbreviations list of abbreviations that must be skipped for checking. Abbreviations should be separated by comma, no spaces are allowed. stringSet null
ignoreFinal allow to skip variables with final modifier. Boolean true
ignoreStatic allow to skip variables with static modifier. Boolean true
ignoreOverriddenMethods Allows to ignore methods tagged with @Override annotation (that usually mean inherited name). Boolean true
tokens tokens to check subset of tokens CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, ENUM_CONSTANT_DEF. CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF.

Examples

Default configuration

<module name="AbbreviationAsWordInName"/>
         

To configure to check variables and classes identifiers, do not ignore variables with static modifier and allow no abbreviations (enforce camel case phrase) and allow no abbreviations to use (camel case phrase) and allow XML and URL abbreviations.

<module name="AbbreviationAsWordInName">
    <property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/>
    <property name="ignoreStatic" value="false"/>
    <property name="allowedAbbreviationLength" value="1"/>
    <property name="allowedAbbreviations" value="XML,URL"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

AbstractClassName

Description

Validates identifiers for abstract classes.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^Abstract.+$
ignoreModifier Controls whether to ignore checking for the abstract modifier on classes that match the name. Boolean false
ignoreName Controls whether to ignore checking the name. Realistically only useful if using the check to identify that match name and do not have the abstract modifier. name. Boolean false

Examples

The following example shows how to configure the AbstractClassName to checks names, but ignore missing abstract modifiers:

<module name="AbstractClassName">
  <property name="ignoreModifier" value="true"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

CatchParameterName

Description

Checks that catch parameter names conform to a format specified by the format property. Default pattern has the following characteristic:

  • allows names beginning with two lowercase letters followed by at least one uppercase or lowercase letter
  • allows e abbreviation (suitable for exceptions end errors)
  • allows ex abbreviation (suitable for exceptions)
  • allows t abbreviation (suitable for throwables)
  • prohibits numbered abbreviations like e1 or t2
  • prohibits one letter prefixes like pException
  • prohibits two letter abbreviations like ie or ee
  • prohibits any other characters than letters

Properties

name description type default value
format Specifies valid identifiers. regular expression ^(e|t|ex|[a-z][a-z][a-zA-Z]+)$

Examples

To configure the check:

<module name="CatchParameterName"/>
        

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="CatchParameterName">
    <property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

ClassTypeParameterName

Description

Validates identifiers for class type parameters.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[A-Z]$

Examples

To configure the check:

<module name="ClassTypeParameterName"/>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

ConstantName

Description

Validates identifiers for constants (static, final fields).

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
applyToPublic Controls whether to apply the check to public member. Boolean true
applyToProtected Controls whether to apply the check to protected member. Boolean true
applyToPackage Controls whether to apply the check to package-private member. Boolean true
applyToPrivate Controls whether to apply the check to private member. Boolean true

Examples

Property format in module ConstantName is used to specify names to be allowed. The following configuration apart from names allowed by default allows log or logger:

<module name="ConstantName">
    <property name="format"
              value="^log(ger)?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

InterfaceTypeParameterName

Description

Validates identifiers for interface type parameters.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[A-Z]$

Examples

To configure the check:

<module name="InterfaceTypeParameterName"/>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

LocalFinalVariableName

Description

Validates identifiers for local, final variables, including catch parameters.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
tokens tokens to check subset of tokens VARIABLE_DEF, PARAMETER_DEF. VARIABLE_DEF, PARAMETER_DEF.

Examples

To configure the check:

<module name="LocalFinalVariableName"/>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

LocalVariableName

Description

Checks that local, non-final variable names conform to a format specified by the format property.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
allowOneCharVarInForLoop Allow one character variable name in initialization expressions in FOR loop. For example:
for (int i = 1; i < 10; i++) {}
              
Boolean false

Examples

To configure the check to use the default configuration:

<module name="LocalVariableName"/>
        

An example of how to configure the check to allow one character variable name in initialization expressions in FOR loop:

<module name="LocalVariableName">
    <property name="allowOneCharVarInForLoop" value="true"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

MemberName

Description

Validates identifiers for non-static fields.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
applyToPublic Controls whether to apply the check to public member. Boolean true
applyToProtected Controls whether to apply the check to protected member. Boolean true
applyToPackage Controls whether to apply the check to package-private member. Boolean true
applyToPrivate Controls whether to apply the check to private member. Boolean true

Examples

This is an example of a configuration of the MemberName module to ensure that member identifiers begin with 'm', followed by an upper case letter, and then letters and digits:

<module name="MemberName">
  <property name="format" value="^m[A-Z][a-zA-Z0-9]*$"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

MethodName

Description

Validates identifiers for methods.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
allowClassName Controls whether to allow a method name to have the same name as the residing class name. This is not to be confused with a constructor. An easy mistake is to place a return type on a constructor declaration which turns it into a method. For example:
class MyClass {
    public void MyClass() {} //this is a method
    public MyClass() {} //this is a constructor
}
              
Boolean false
applyToPublic Controls whether to apply the check to public member. Boolean true
applyToProtected Controls whether to apply the check to protected member. Boolean true
applyToPackage Controls whether to apply the check to package-private member. Boolean true
applyToPrivate Controls whether to apply the check to private member. Boolean true

Examples

To configure the check:

<module name="MethodName"/>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

MethodTypeParameterName

Description

Validates identifiers for method type parameters.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[A-Z]$

Examples

To configure the check:

<module name="MethodTypeParameterName"/>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

PackageName

Description

Validates identifiers for packages.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$

Examples

The default value of format for module PackageName has been chosen to match the requirements in the Java Language specification and the Sun coding conventions. However both underscores and uppercase letters are rather uncommon, so most configurations should probably assign value ^[a-z]+(\.[a-z][a-z0-9]*)*$ to format for module PackageName, as in

<module name="PackageName">
    <property name="format"
              value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

ParameterName

Description

Checks that method and catch parameter names conform to a format specified by the format property.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
ignoreOverridden Allows to skip methods with Override annotation from validation. For example, the following method's parameter will be skipped from validation, if ignoreOverridden is true:
@Override
public boolean equals(Object o) {
  return super.equals(o);
}
              
Boolean false

Examples

To configure the check:

<module name="ParameterName"/>
        

An example of how to configure the check to skip methods with Override annotation from validation:

<module name="ParameterName">
    <property name="ignoreOverridden" value="true"/>
</module>
          

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="ParameterName">
    <property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

StaticVariableName

Description

Validates identifiers for static, non-final fields.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[a-z][a-zA-Z0-9]*$
applyToPublic Controls whether to apply the check to public member. Boolean true
applyToProtected Controls whether to apply the check to protected member. Boolean true
applyToPackage Controls whether to apply the check to package-private member. Boolean true
applyToPrivate Controls whether to apply the check to private member. Boolean true

Examples

To configure the check:

<module name="StaticVariableName"/>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker

TypeName

Description

Validates identifiers for classes, interfaces, enums, and annotations.

Properties

name description type default value
format Specifies valid identifiers. regular expression ^[A-Z][a-zA-Z0-9]*$
applyToPublic Controls whether to apply the check to public member. Boolean true
applyToProtected Controls whether to apply the check to protected member. Boolean true
applyToPackage Controls whether to apply the check to package-private member. Boolean true
applyToPrivate Controls whether to apply the check to private member. Boolean true
tokens tokens to check subset of tokens CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF. CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF.

Examples

The following configuration element ensures that interface names begin with "I_", followed by letters and digits:

<module name="TypeName">
    <property name="format"
              value="^I_[a-zA-Z0-9]*$"/>
    <property name="tokens"
              value="INTERFACE_DEF"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker