diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java index 95e012499..a1d6ed62b 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java @@ -39,8 +39,6 @@ public class AllChecksPresentOnAvailableChecksPageTest { private static final String CHECK_SUFFIX = "Check.java"; private static final String LINK_TEMPLATE = "(?s).*%1$s.*"; - private static final String NAMING_LINK_TEMPLATE = - "(?s).*%s.*"; private static final List IGNORE_LIST = Arrays.asList( "AbstractAccessControlNameCheck.java", @@ -79,8 +77,6 @@ public class AllChecksPresentOnAvailableChecksPageTest { private static boolean isPresent(String availableChecks, String checkName) { final String linkPattern = String.format(LINK_TEMPLATE, checkName); - final String namingLinkPattern = String.format(NAMING_LINK_TEMPLATE, checkName); - return availableChecks.matches(linkPattern) - || checkName.endsWith("Name") && availableChecks.matches(namingLinkPattern); + return availableChecks.matches(linkPattern); } } diff --git a/src/xdocs/checks.xml b/src/xdocs/checks.xml index 413bd4572..5c6a370a2 100644 --- a/src/xdocs/checks.xml +++ b/src/xdocs/checks.xml @@ -108,14 +108,14 @@ The number of other classes a given class relies on. - ClassTypeParameterName + ClassTypeParameterName Checks that class type parameter names conform to a format specified by the format property. - ConstantName + ConstantName Checks that constant names conform to a format specified by the format property. @@ -336,7 +336,7 @@ Use Interfaces only to define types. - InterfaceTypeParameterName + InterfaceTypeParameterName Checks that interface type parameter names conform to a format specified by the format property. @@ -386,7 +386,7 @@ Checks for long lines. - LocalFinalVariableName + LocalFinalVariableName Checks that local final variable names conform to a format specified by the format property. @@ -403,7 +403,7 @@ Checks for magic numbers. - MemberName + MemberName Checks that instance variable names conform to a format specified by the format property. @@ -431,7 +431,7 @@ and the left parenthesis of the parameter list. - MethodTypeParameterName + MethodTypeParameterName Checks that class type parameter names conform to a format specified by the format property. @@ -582,7 +582,7 @@ Ensures there is a package declaration and (optionally) in the correct directory. - PackageName + PackageName Checks that package names conform to a format specified by the format property. @@ -593,7 +593,7 @@ Disallow assignment of parameters. - ParameterName + ParameterName Checks that parameter names conform to a format specified by the format property. @@ -681,7 +681,7 @@ Checks for overly complicated boolean return statements. - StaticVariableName + StaticVariableName Checks that static, non-final variable names conform to a format specified by the format property. diff --git a/src/xdocs/config_naming.xml b/src/xdocs/config_naming.xml index 937db809b..f9f1016eb 100644 --- a/src/xdocs/config_naming.xml +++ b/src/xdocs/config_naming.xml @@ -32,533 +32,8 @@ 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: + regular expression for valid identifiers.

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

- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
modulevalidates identifiers fordefault value of format
AbstractClassNameabstract classes^Abstract.+$|^.*Factory$
ClassTypeParameterNameclass type parameters^[A-Z]$
ConstantName - constants (static, - final fields) - ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
LocalFinalVariableNamelocal, 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]*$
MemberNamenon-static fields^[a-z][a-zA-Z0-9]*$
MethodNamemethods^[a-z][a-zA-Z0-9]*$
MethodTypeParameterNamemethod type parameters^[A-Z]$
InterfaceTypeParameterNameinterface type parameters^[A-Z]$
PackageNamepackages - ^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$ -
ParameterNameparameters^[a-z][a-zA-Z0-9]*$
StaticVariableName - static, non-final fields - ^[a-z][a-zA-Z0-9]*$
TypeNameclasses, 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: -

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

- The check provides the following properties: -

-
- - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowOneCharVarInForLoop - Allow one character variable name in initialization expressions in FOR loop. For example: -
-for (int i = 1; i < 10; i++) {}
-              
-
Booleanfalse
-

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

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

- Module MethodName also has the following - properties: -

- - - - - - - - - - - - - - -
namedescriptiontypedefault 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
-}
-              
-
Booleanfalse
-
- - -

- Module AbstractClassName also has the following - properties: -

- - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
ignoreModifier - Controls whether to ignore checking for the - abstract modifier on classes that match the - name. - Booleanfalse
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. - Booleanfalse
- -

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

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

- The modules ConstantName, - MemberName, StaticVariableName and - TypeName also have the following properties: -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
applyToPublicControls whether to apply the check to public member.Booleantrue
applyToProtectedControls whether to apply the check to protected member.Booleantrue
applyToPackage - Controls whether to apply the check to package-private member. - Booleantrue
applyToPrivateControls whether to apply the check to private member.Booleantrue
-
-
- -
-
    -
  1. - AbstractClassName - -
  2. -
  3. - ClassTypeParameterName - -
  4. -
  5. - ConstantName - -
  6. -
  7. - LocalFinalVariableName - -
  8. -
  9. - LocalVariableName - -
  10. -
  11. - MemberName - -
  12. -
  13. - MethodName - -
  14. -
  15. - MethodTypeParameterName - -
  16. -
  17. - InterfaceTypeParameterName - -
  18. -
  19. - PackageName - -
  20. -
  21. - ParameterName - -
  22. -
  23. - StaticVariableName - -
  24. -
  25. - TypeName - -
  26. -
-
- -
-

- 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> -
@@ -582,7 +57,7 @@ class MyClass { allowedAbbreviationLength - indicates on the allowed amount of capital letters in targeted identifiers + indicates on the allowed amount of capital letters in targeted identifiers (abbreviations in the classes, interfaces, variables and methods names, ... ). 3 true @@ -653,15 +128,973 @@ class MyClass { -

- com.puppycrawl.tools.checkstyle.checks.naming -

+

com.puppycrawl.tools.checkstyle.checks.naming

+

TreeWalker

+
+
+ +
+ +

Validates identifiers for abstract classes.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^Abstract.+$|^.*Factory$
ignoreModifier + Controls whether to ignore checking for the + abstract modifier on classes that match the + name. + Booleanfalse
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. + Booleanfalse
+
+ +

- TreeWalker + 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> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

Validates identifiers for class type parameters.

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[A-Z]$
+
+ + +

+ To configure the check: +

+ +<module name="ClassTypeParameterName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for constants (static, + final fields). +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
applyToPublicControls whether to apply the check to public member.Booleantrue
applyToProtectedControls whether to apply the check to protected member.Booleantrue
applyToPackage + Controls whether to apply the check to package-private member. + Booleantrue
applyToPrivateControls whether to apply the check to private member.Booleantrue
+
+ + +

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

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for interface type parameters. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[A-Z]$
+
+ + +

+ To configure the check: +

+ +<module name="InterfaceTypeParameterName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

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

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[a-z][a-zA-Z0-9]*$
+
+ + +

+ To configure the check: +

+ +<module name="LocalFinalVariableName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for local, non-final variables, including + catch parameters. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies 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++) {}
+              
+
Booleanfalse
+
+ + +

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

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

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for non-static fields. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[a-z][a-zA-Z0-9]*$
applyToPublicControls whether to apply the check to public member.Booleantrue
applyToProtectedControls whether to apply the check to protected member.Booleantrue
applyToPackage + Controls whether to apply the check to package-private member. + Booleantrue
applyToPrivateControls whether to apply the check to private member.Booleantrue
+
+ + +

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

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for methods. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies 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
+}
+              
+
Booleanfalse
+
+ + +

+ To configure the check: +

+ +<module name="MethodName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for method type parameters. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[A-Z]$
+
+ + +

+ To configure the check: +

+ +<module name="MethodTypeParameterName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for packages. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies 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 +

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

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for parameters. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[a-z][a-zA-Z0-9]*$
+
+ + +

+ To configure the check: +

+ +<module name="ParameterName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

+ Validates identifiers for static, non-final fields. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[a-z][a-zA-Z0-9]*$
applyToPublicControls whether to apply the check to public member.Booleantrue
applyToProtectedControls whether to apply the check to protected member.Booleantrue
applyToPackage + Controls whether to apply the check to package-private member. + Booleantrue
applyToPrivateControls whether to apply the check to private member.Booleantrue
+
+ + +

+ To configure the check: +

+ +<module name="StaticVariableName"/> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker

+
+
+ +
+ +

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

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatSpecifies valid identifiers.String^[A-Z][a-zA-Z0-9]*$
applyToPublicControls whether to apply the check to public member.Booleantrue
applyToProtectedControls whether to apply the check to protected member.Booleantrue
applyToPackage + Controls whether to apply the check to package-private member. + Booleantrue
applyToPrivateControls whether to apply the check to private member.Booleantrue
tokensControls 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: +

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

com.puppycrawl.tools.checkstyle.checks.naming

+
+ + +

TreeWalker