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:
+ regular expression for valid identifiers.
-
-
- All naming modules belong to package com.puppycrawl.tools.checkstyle.checks.naming and
- are submodules of TreeWalker.
-
| module | -validates identifiers for | -default value of format |
-
|---|---|---|
AbstractClassName |
- abstract classes |
- ^Abstract.+$|^.*Factory$ |
-
ClassTypeParameterName |
- class type parameters | -^[A-Z]$ |
-
ConstantName |
-
- constants (static,
- final fields)
- |
- ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ |
-
LocalFinalVariableName |
- local, final variables, including
- catch parameters |
- ^[a-z][a-zA-Z0-9]*$ |
-
LocalVariableName |
-
- local, non-final variables, including
- catch parameters
- |
- ^[a-z][a-zA-Z0-9]*$ |
-
MemberName |
- non-static fields |
- ^[a-z][a-zA-Z0-9]*$ |
-
MethodName |
- methods | -^[a-z][a-zA-Z0-9]*$ |
-
MethodTypeParameterName |
- method type parameters | -^[A-Z]$ |
-
InterfaceTypeParameterName |
- interface type parameters | -^[A-Z]$ |
-
PackageName |
- packages | -
- ^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$
- |
-
ParameterName |
- parameters | -^[a-z][a-zA-Z0-9]*$ |
-
StaticVariableName |
-
- static, non-final fields
- |
- ^[a-z][a-zA-Z0-9]*$ |
-
TypeName |
- classes, interfaces, enums, and annotations | -^[A-Z][a-zA-Z0-9]*$ |
-
- 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:
-
- The check provides the following properties: -
-| name | -description | -type | -default value | -
|---|---|---|---|
| allowOneCharVarInForLoop | -
- Allow one character variable name in initialization expressions in FOR loop. For example:
-
-for (int i = 1; i < 10; i++) {}
-
- |
- Boolean | -false |
-
- An example of how to configure the check to allow one character variable name in - - initialization expressions in FOR loop: -
-
- Module TypeName also has property
- tokens, which can be used to control the kind of type
- that the check applies to. The value of the tokens
- property is a comma-separated list of one or more of the following
- tokens: CLASS_DEF, INTERFACE_DEF,
- ENUM_DEF, ANNOTATION_DEF.
- For example, the following configuration element ensures that
- interface names begin with "I_", followed by
- letters and digits:
-
- Module MethodName also has the following
- properties:
-
| name | -description | -type | -default value | -
|---|---|---|---|
| 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 |
-
- Module AbstractClassName also has the following
- properties:
-
| name | -description | -type | -default value | -
|---|---|---|---|
| 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 |
-
- The following example shows how to configure the
- AbstractClassName to checks names, but ignore
- missing abstract modifiers:
-
- 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:
-
- The modules ConstantName,
- MemberName, StaticVariableName and
- TypeName also have the following properties:
-
| name | -description | -type | -default value | -
|---|---|---|---|
| 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 |
-
- 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
-
- com.puppycrawl.tools.checkstyle.checks.naming -
+com.puppycrawl.tools.checkstyle.checks.naming
Validates identifiers for abstract classes.
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^Abstract.+$|^.*Factory$ |
+
| 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 |
+
- TreeWalker
+ The following example shows how to configure the
+ AbstractClassName to checks names, but ignore
+ missing abstract modifiers:
com.puppycrawl.tools.checkstyle.checks.naming
+Validates identifiers for class type parameters.
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[A-Z]$ |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
+
+ Validates identifiers for constants (static,
+ final fields).
+
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 |
+
+ 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:
+
com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for interface type parameters. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[A-Z]$ |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
+
+ Validates identifiers for local, final variables, including
+ catch parameters.
+
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[a-z][a-zA-Z0-9]*$ |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
+
+ Validates identifiers for local, non-final variables, including
+ catch parameters.
+
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 |
+
+ The following
+ configuration element ensures that catch clause
+ parameters begin with "e", followed by letters
+ and digits:
+
+ An example of how to configure the check to allow one character variable name in + + initialization expressions in FOR loop: +
+com.puppycrawl.tools.checkstyle.checks.naming
+
+ Validates identifiers for non-static fields.
+
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 |
+
+ 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:
+
com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for methods. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for method type parameters. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[A-Z]$ |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for packages. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$ |
+
+ 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
+
com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for parameters. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[a-z][a-zA-Z0-9]*$ |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
+
+ Validates identifiers for static, non-final fields.
+
| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 |
+
+ To configure the check: +
+com.puppycrawl.tools.checkstyle.checks.naming
++ Validates identifiers for classes, interfaces, enums, and annotations. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| format | +Specifies valid identifiers. | +String | +^[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 | +Controls the kind of type that the check applies to. | ++ A comma-separated list of one or more of the following + tokens: + + CLASS_DEF, + + INTERFACE_DEF, + + ENUM_DEF, + + ANNOTATION_DEF. + | ++ + CLASS_DEF, + + INTERFACE_DEF, + + ENUM_DEF, + + ANNOTATION_DEF + | +
+ The following configuration element ensures that
+ interface names begin with "I_", followed by
+ letters and digits:
+
com.puppycrawl.tools.checkstyle.checks.naming
+