Checks for Naming Conventions

Checkstyle supports checking that names in a Java code confirms to specified naming conventions which are specifed as regular expressions. The excellent Jakarta Regexp library is used by Checkstyle.

Format of members

The property checkstyle.pattern.member specifies the format for members (non static). The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

An example is:

    private int mySize = 0;

The property checkstyle.pattern.publicmember specifies the format for public members (non static public). The property type is regular expression and defaults to ^f[A-Z][a-zA-Z0-9]*$.

Tip

This is useful for the fields required for Container Managed Persistence (CMP) Enterprise JavaBeans 1.1. An example is:

    public int fCMPField;

Format of constants

The property checkstyle.pattern.const specifies the format for constants (static and final). The property type is regular expression and defaults to ^[A-Z](_?[A-Z0-9]+)*$.

The exception to the rule is serialVersionUID. An example is:

    public static final int MAX_ROWS = 2;

Format of statics

The property checkstyle.pattern.static specifies the format for static variables (static only). The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

An example is:

    private static int numCreated = 0;

Format of parameter names

The property checkstyle.pattern.parameter specifies the format for parameter names. The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

Format of package names

The property checkstyle.pattern.package specifies the format for class and interface names. The property type is regular expression and defaults to ^[a-z]+(\.[a-zA-Z_][a-zA-Z_0-9]*)*$.

Tip

The default value of checkstyle.pattern.package 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 projects should probably use checkstyle.pattern.package=^[a-z]+(\.[a-z][a-z0-9]*)*$

Format of type names

The property checkstyle.pattern.type specifies the format for class and interface names. The property type is regular expression and defaults to ^[A-Z][a-zA-Z0-9]*$.

Format of method names

The property checkstyle.pattern.method specifies the format for method names. The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

Format of local variable names

The property checkstyle.pattern.localvar specifies the format for local variables. The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

    int localInt = 3;

The property checkstyle.pattern.localfinalvar specifies the format for final local variables. The property type is regular expression and defaults to ^[a-z][a-zA-Z0-9]*$.

    final int finalLocalInt = 3;

Copyright © 2002 Oliver Burn. All rights Reserved.