Naming Conventions

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. 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>

All naming modules belong to package com.puppycrawl.tools.checkstyle.checks.naming and are submodules of TreeWalker.

Modules

module validates identifiers for default value of format
  abstract classes  
  constants (static, final fields)  
  local, final variables, including catch parameters  
  local, non-final variables, including catch parameters  
  non-static fields  
  methods  
  packages ^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$
  parameters  
  static, non-final fields  
  classes and interfaces  

Notes

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>

Module LocalVariableName also has property tokens which can be used to control whether the check applies to variable declarations or catch clause parameters through tokens VARIABLE_DEF and PARAMETER_DEF. For example, the following configuration element ensures that catch clause parameters begin with "e", followed by letters and digits:

<module name="LocalVariableName">
    <property name="format" value="^e[a-zA-Z0-9]*$"/>
    <property name="tokens" value="PARAMETER_DEF"/>
</module>

Module TypeName also has property tokens which can be used to control whether the check applies to classes or interfaces through tokens CLASS_DEF and INTERFACE_DEF. For example, 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>

Module MemberName also has the following properties:

name description type default value
applyToPublic Controls whether to apply the check to public member.    
applyToProtected Controls whether to apply the check to protected member.    
applyToPackage Controls whether to apply the check to package-private member.    
applyToPrivate Controls whether to apply the check to pribvate member.    
Copyright © 2001-2005, Oliver Burn