diff --git a/src/xdocs/config_annotation.xml b/src/xdocs/config_annotation.xml index ca5cb3463..036523975 100644 --- a/src/xdocs/config_annotation.xml +++ b/src/xdocs/config_annotation.xml @@ -21,6 +21,154 @@ +
+ +

+ Check location of annotation on language elements. + By default, Check enforce to locate annotations immediately + after documentation block and before target element, annotation should be located on separate line from target element. +

+

+ Example: +

+ +@Override +@Nullable +public String getNameIfPresent() { ... } + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowSamelineMultipleAnnotationsTo allow annotation to be located on the same line as target element.booleanfalse
allowSamelineSingleParameterlessAnnotationTo allow single prameterless annotation to be located on the same line as target element.booleantrue
allowSamelineParameterizedAnnotationTo allow parameterized annotation to be located on the same line as target element.booleanfalse
tokenstokens to checksubset of tokens + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF, + PARAMETER_DEF, + ANNOTATION_DEF, + TYPECAST, + LITERAL_THROWS, + IMPLEMENTS_CLAUSE, + TYPE_ARGUMENT, + LITERAL_NEW, + DOT, + ANNOTATION_FIELD_DEF. + + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF. +
+
+ + +

+ Example to allow single parameterless annotation on the same line +

+ +@Override public int hashCode() { ... } + +

+ Use following configuration: +

+ +<module name="AnnotationLocation"> + <property name="allowSamelineMultipleAnnotations" value="false"/> + <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> + <property name="allowSamelineParameterizedAnnotation" value="false"/> +</module> + +

+ Example to allow multiple parameterized annotations on the same line +

+ +@SuppressWarnings("deprecation") @Mock DataLoader loader; + +

+ Use following configuration: +

+ +<module name="AnnotationLocation"> + <property name="allowSamelineMultipleAnnotations" value="true"/> + <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> + <property name="allowSamelineParameterizedAnnotation" value="true"/> +</module> + +

+ Example to allow multiple parameterless annotations on the same line +

+ +@Partial @Mock DataLoader loader; + +

+ Use following configuration: +

+ +<module name="AnnotationLocation"> + <property name="allowSamelineMultipleAnnotations" value="true"/> + <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> + <property name="allowSamelineParameterizedAnnotation" value="false"/> +</module> + +
+ + + + + + +

com.puppycrawl.tools.checkstyle.checks.annotation

+
+ + +

TreeWalker

+
+
+

This check controls the style with the usage of annotations. @@ -469,153 +617,5 @@

- -
- -

- Check location of annotation on language elements. - By default, Check enforce to locate annotations immediately - after documentation block and before target element, annotation should be located on separate line from target element. -

-

- Example: -

- -@Override -@Nullable -public String getNameIfPresent() { ... } - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowSamelineMultipleAnnotationsTo allow annotation to be located on the same line as target element.booleanfalse
allowSamelineSingleParameterlessAnnotationTo allow single prameterless annotation to be located on the same line as target element.booleantrue
allowSamelineParameterizedAnnotationTo allow parameterized annotation to be located on the same line as target element.booleanfalse
tokenstokens to checksubset of tokens - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF, - PARAMETER_DEF, - ANNOTATION_DEF, - TYPECAST, - LITERAL_THROWS, - IMPLEMENTS_CLAUSE, - TYPE_ARGUMENT, - LITERAL_NEW, - DOT, - ANNOTATION_FIELD_DEF. - - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF. -
-
- - -

- Example to allow single parameterless annotation on the same line -

- -@Override public int hashCode() { ... } - -

- Use following configuration: -

- -<module name="AnnotationLocation"> - <property name="allowSamelineMultipleAnnotations" value="false"/> - <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> - <property name="allowSamelineParameterizedAnnotation" value="false"/> -</module> - -

- Example to allow multiple parameterized annotations on the same line -

- -@SuppressWarnings("deprecation") @Mock DataLoader loader; - -

- Use following configuration: -

- -<module name="AnnotationLocation"> - <property name="allowSamelineMultipleAnnotations" value="true"/> - <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> - <property name="allowSamelineParameterizedAnnotation" value="true"/> -</module> - -

- Example to allow multiple parameterless annotations on the same line -

- -@Partial @Mock DataLoader loader; - -

- Use following configuration: -

- -<module name="AnnotationLocation"> - <property name="allowSamelineMultipleAnnotations" value="true"/> - <property name="allowSamelineSingleParameterlessAnnotation" value="true"/> - <property name="allowSamelineParameterizedAnnotation" value="false"/> -</module> - -
- - - - - - -

com.puppycrawl.tools.checkstyle.checks.annotation

-
- - -

TreeWalker

-
-
diff --git a/src/xdocs/config_blocks.xml b/src/xdocs/config_blocks.xml index f3c401b91..6e7fd9993 100644 --- a/src/xdocs/config_blocks.xml +++ b/src/xdocs/config_blocks.xml @@ -21,6 +21,119 @@ +
+ +

+ Finds nested blocks, i.e. blocks that are used freely in the code. +

+ +

+ Rationale: Nested blocks are often leftovers from the + debugging process, they confuse the reader. +

+ +

+ For example this Check finds the obsolete braces in +

+ +public void guessTheOutput() +{ + int whichIsWhich = 0; + { + int whichIsWhich = 2; + } + System.out.println("value = " + whichIsWhich); +} + + +

and debugging / refactoring leftovers such as

+ +// if (conditionThatIsNotUsedAnyLonger) +{ + System.out.println("unconditional"); +} + + +

+ A case in a switch statement does not implicitly form a block. + Thus to be able to introduce local variables that have case + scope it is necessary to open a nested block. This is + supported, set the allowInSwitchCase property to true and + include all statements of the case in the block. +

+ +switch (a) +{ + case 0: + // Never OK, break outside block + { + x = 1; + } + break; + case 1: + // Never OK, statement outside block + System.out.println("Hello"); + { + x = 2; + break; + } + case 1: + // OK if allowInSwitchCase is true + { + System.out.println("Hello"); + x = 2; + break; + } +} + +
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowInSwitchCaseAllow nested blocks in case statementsbooleanfalse
+
+ + +

To configure the check:

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

com.puppycrawl.tools.checkstyle.checks.blocks

+
+ + +

TreeWalker

+
+
+

Checks for empty blocks.

@@ -645,118 +758,5 @@ switch (num) {

TreeWalker

- -
- -

- Finds nested blocks, i.e. blocks that are used freely in the code. -

- -

- Rationale: Nested blocks are often leftovers from the - debugging process, they confuse the reader. -

- -

- For example this Check finds the obsolete braces in -

- -public void guessTheOutput() -{ - int whichIsWhich = 0; - { - int whichIsWhich = 2; - } - System.out.println("value = " + whichIsWhich); -} - - -

and debugging / refactoring leftovers such as

- -// if (conditionThatIsNotUsedAnyLonger) -{ - System.out.println("unconditional"); -} - - -

- A case in a switch statement does not implicitly form a block. - Thus to be able to introduce local variables that have case - scope it is necessary to open a nested block. This is - supported, set the allowInSwitchCase property to true and - include all statements of the case in the block. -

- -switch (a) -{ - case 0: - // Never OK, break outside block - { - x = 1; - } - break; - case 1: - // Never OK, statement outside block - System.out.println("Hello"); - { - x = 2; - break; - } - case 1: - // OK if allowInSwitchCase is true - { - System.out.println("Hello"); - x = 2; - break; - } -} - -
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowInSwitchCaseAllow nested blocks in case statementsbooleanfalse
-
- - -

To configure the check:

- -<module name="AvoidNestedBlocks"/> - -
- - - - - - -

com.puppycrawl.tools.checkstyle.checks.blocks

-
- - -

TreeWalker

-
-
diff --git a/src/xdocs/config_coding.xml b/src/xdocs/config_coding.xml index ab1150d70..b4e611775 100644 --- a/src/xdocs/config_coding.xml +++ b/src/xdocs/config_coding.xml @@ -171,6 +171,168 @@ String b = (a==null || a.length<1) ? null : a.substring(1); +
+ +

+ According to + Code Conventions for the Java Programming Language , the parts + of a class or interface declaration should appear in the following + order: +

+ +
    +
  1. + Class (static) variables. First the public class variables, then + protected, then package level (no access modifier), and then + private. +
  2. +
  3. + Instance variables. First the public class variables, then + protected, then package level (no access modifier), and then + private. +
  4. +
  5. Constructors
  6. +
  7. Methods
  8. +
+ +

+ Purpose of ignore* option is to ignore related violations, however it still impacts on other class members. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
ignoreConstructorswhether to ignore constructorsBooleanfalse
ignoreModifierswhether to ignore modifiersBooleanfalse
+
+ + +

+ To configure the check: +

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

+ For example: + + class K { + int a; + void m(){} + K(){} <-- "Constructor definition in wrong order" + int b; <-- "Instance variable definition in wrong order" + } + +

+

+ With ignoreConstructors option: + + class K { + int a; + void m(){} + K(){} + int b; <-- "Instance variable definition in wrong order" + } + +

+

+ With ignoreConstructors option and without a method definition in a source class: + + class K { + int a; + K(){} + int b; <-- "Instance variable definition in wrong order" + } + +

+
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Check that the default is after all the + cases in a switch statement. +

+ +

+ Rationale: Java allows default anywhere + within the switch statement. But it is + more readable if it comes after the last case. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -345,6 +507,175 @@ String nullString = null;

+
+ +

+ Checks if any class or object member is explicitly initialized to + default for its type value (null for + object references, zero for numeric types and char and false for + boolean. +

+ +

+ Rationale: Each instance variable gets initialized twice, to the + same value. Java initializes each instance variable to its default + value (0 or null) before performing any initialization specified in + the code. So in this case, x gets initialized to 0 twice, and bar + gets initialized to null twice. So there is a minor inefficiency. + This style of coding is a holdover from C/C++ style coding, and it + shows that the developer isn't really confident that Java + initializes instance variables to default values. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks for fall-through in switch + statements. Finds locations where a case + contains Java code but lacks a break, return, + throw or continue + statement. +

+

+ The check honors special comments to suppress the warning. By + default the text "fallthru", "fall through", "fallthrough", + "falls through" and "fallsthrough" are recognized (case + sensitive). The comment containing these words must be all on one line, and must + be on the last non-empty line before the + case triggering the warning or on + the same line before the case + (ugly, but possible). +

+ +switch (i){ +case 0: + i++; // fall through + +case 1: + i++; + // falls through +case 2: +case 3: +case 4: { + i++; +} +// fallthrough +case 5: + i++; +/* fallthru */case 6: + i++ + break; +} + +

+ Note: The check assumes that there is no unreachable + code in the case. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
checkLastCaseGroup + Whether the last case group must be checked. + Booleanfalse
reliefPattern + Regular expression to match the relief comment that suppresses + the warning about a fall through. + regular expressionfallthru|falls? ?through
+
+ + +

+ To configure the check: +

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

+ or +

+ +<module name="FallThrough"> + <property name="reliefPattern" value="continue in next case"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -670,6 +1001,71 @@ class SomeClass

+
+ +

+ Checks that certain exception types do not appear in a catch statement. +

+ +

+ Rationale: + Catching java.lang.Exception, java.lang.Error or + java.lang.RuntimeException is almost never acceptable. + Novice developers often simply catch Exception in an + attempt to handle multiple exception classes. This unfortunately + leads to code that inadvertently catches NullPointerException, OutOfMemoryError, etc. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
illegalClassNamesexception class names to rejectlist of strings"java.lang.Exception, + java.lang.Throwable, java.lang.RuntimeException"
+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -773,6 +1169,103 @@ class SomeClass

+
+ +

+ This check can be used to ensure that types are not declared + to be thrown. Declaring that a method throws java.lang.Error or + java.lang.RuntimeException is almost never acceptable. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
illegalClassNamesthrow class names to rejectlist of strings + "java.lang.Throwable, + java.lang.Error, java.lang.RuntimeException" +
ignoredMethodNamesnames of methods to ignorelist of stringsfinalize
ignoreOverriddenMethodsignore checking overridden methods (marked with Override or java.lang.Override + annotation).Booleantrue
+
+ + +

+ To configure the check: +

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

+ To configure the check rejecting throws NullPointerException from methods: +

+ +<module name="IllegalThrows"> + <property name="illegalClassNames" value="NullPointerException"/> +</module> + +

+ To configure the check ignoring method named "foo()": +

+ +<module name="IllegalThrows"> + <property name="ignoredMethodNames" value="foo"/> +</module> + +

+ To configure the check to warn on overridden methods: +

+ +<module name="IllegalThrows"> + <property name="ignoreOverriddenMethods" value="false"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -937,6 +1430,126 @@ class SomeClass

+
+ +

+ Checks that particular classes are never used as types in variable + declarations, return values or parameters. +

+ +

+ Rationale: Helps reduce coupling on concrete classes. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
validateAbstractClassNamesWhether to validate abstract class namesbooleanfalse
illegalClassNamesClasses that should not be used as types in variable + declarations, return values or parametersString Set"java.util.HashSet, java.util.HashMap, java.util.LinkedHashMap, + java.util.LinkedHashSet, java.util.TreeSet, + java.util.TreeMap"
legalAbstractClassNamesAbstract classes that may be used as types. String Set +
ignoredMethodNamesMethods that should not be checked.String Set"getInitialContext, getEnvironment"
formatPattern for illegal class names.regular expression^(.*[\\.])?Abstract.*$
memberModifiersCheck methods and fields with only corresponding modifiers.List of tokensnull
tokenstokens to check + subset of tokens + VARIABLE_DEF, + PARAMETER_DEF, + METHOD_DEF. + + VARIABLE_DEF, + PARAMETER_DEF, + METHOD_DEF. +
+
+ + +

+ To configure the check so that it ignores getInstance() methods: +

+ +<module name="IllegalType"> + <property name="ignoredMethodNames" value="getInstance"/> +</module> + +

+ To configure the Check so that it verifies only public, protected and static + methods and fields: +

+ +<module name="IllegalType"> + <property name="memberModifiers" value="LITERAL_PUBLIC, + LITERAL_PROTECTED, LITERAL_STATIC"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -1218,6 +1831,45 @@ class MyClass {

+
+ +

+ Checks that classes (except abstract ones) define a constructor and don't + rely on the default one. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -1380,37 +2032,107 @@ class MyClass {

-
+

- Checks for over-complicated boolean expressions. Currently finds - code like if (b == true), b || true, !false, - etc. + Checks for multiple occurrences of the same string literal within a + single file.

- Rationale: Complex boolean logic makes code hard to understand and - maintain. + Rationale: Code duplication makes maintenance more difficult, so it + can be better to replace the multiple occurrences with a constant.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowedDuplicates + The maximum number of occurrences to allow without generating a + warning + Integer1
ignoreStringsRegexp + Regular expression pattern for ignored strings (with quotation marks) + regular expression^""$ (ignore empty strings)
ignoreOccurrenceContext + Token type names where duplicate strings are ignored even if they don't match + ignoredStringsRegexp. This allows you to exclude syntactical contexts like + annotations or static initializers from the check. + + list of + token type + names + + ANNOTATION + (ignore strings inside the context of an annotation) +
+
+

To configure the check:

-<module name="SimplifyBooleanExpression"/> +<module name="MultipleStringLiterals"/> + + +

+ To configure the check so that it allows two occurrences of each + string: +

+ +<module name="MultipleStringLiterals"> + <property name="allowedDuplicates" value="2"/> +</module> + + +

+ To configure the check so that it ignores ", " and empty strings: +

+ +<module name="MultipleStringLiterals"> + <property name="ignoreStringsRegexp" value='^(("")|(", "))$'/> +</module> + + +

+ To configure the check so that it flags duplicate strings in all + syntactical contexts, even in annotations like + @SuppressWarnings("unchecked"): +

+ +<module name="MultipleStringLiterals"> + <property name="ignoreOccurrenceContext" value=""/> +</module>
@@ -1429,29 +2151,18 @@ class MyClass {
-
+

- Checks for over-complicated boolean return statements. For example - the following code + Checks that each variable declaration is in its own statement and on + its own line.

- -if (valid()) - return false; -else - return true; -

- could be written as -

- -return !valid(); - - -

- The idea for this Check has been shamelessly stolen from the - equivalent PMD rule. + Rationale: + the Java code conventions chapter 6.1 recommends that + declarations should be one per line/statement.

@@ -1460,69 +2171,18 @@ return !valid(); To configure the check:

-<module name="SimplifyBooleanReturn"/> +<module name="MultipleVariableDeclarations"/> - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that string literals are not used with == or - !=. -

- -

- Rationale: Novice Java programmers often use code like: -

- -if (x == "something") - - -

when they mean

- -if ("something".equals(x)) - -
- - -

- To configure the check: -

- -<module name="StringLiteralEquality"/> - -
- - - @@ -1830,33 +2490,64 @@ if ("something".equals(x))
-
+
-

- Checks that an overriding clone() method invokes - super.clone(). Does not check native methods, as - they have no possible java defined implementation. -

- -

- Reference: Object.clone(). -

+

+ Checks that there is only one statement per line. +

+

+ Rationale: It's very difficult to read multiple statements on one line. +

+

+ In the Java programming language, statements are the fundamental unit of + execution. All statements except blocks are terminated by a semicolon. + Blocks are denoted by open and close curly braces. +

+

+ OneStatementPerLineCheck checks the following types of statements: + variable declaration statements, empty statements, import statements, + assignment statements, expression statements, increment statements, + object creation statements, 'for loop' statements, 'break' statements, + 'continue' statements, 'return' statements. +

+

+ The following examples will be flagged as a violation: +

+ +//Each line causes violation: +int var1; int var2; +var1 = 1; var2 = 2; +int var1 = 1; int var2 = 2; +var1++; var2++; +Object obj1 = new Object(); Object obj2 = new Object(); +import java.io.EOFException; import java.io.BufferedReader; +;; //two empty statements on the same line. + +//Multi-line statements: +int var1 = 1 +; var2 = 2; //violation here +int o = 1, p = 2, +r = 5; int t; //violation here +

- To configure the check: + An example of how to configure this Check:

-<module name="SuperClone"/> +<module name="OneStatementPerLine"/>
@@ -1875,196 +2566,39 @@ if ("something".equals(x))
-
+

- Checks that an overriding finalize() method invokes - super.finalize(). Does not check native methods, as - they have no possible java defined implementation. -

- -

- Reference: - Use Finalization Only When You Must. + Checks that overload methods are grouped together.

- To configure the check: + Example of incorrect grouping overload methods:

-<module name="SuperFinalize"/> +public void foo(int i) {} +public void foo(String s) {} +public void notFoo() {} // Have to be after foo(int i, String s) +public void foo(int i, String s) {} -
+

+ An example of how to configure the check is: +

+ +<module name="OverloadMethodsDeclarationOrder"/> + + - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that certain exception types do not appear in a catch statement. -

- -

- Rationale: - Catching java.lang.Exception, java.lang.Error or - java.lang.RuntimeException is almost never acceptable. - Novice developers often simply catch Exception in an - attempt to handle multiple exception classes. This unfortunately - leads to code that inadvertently catches NullPointerException, OutOfMemoryError, etc. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
illegalClassNamesexception class names to rejectlist of strings"java.lang.Exception, - java.lang.Throwable, java.lang.RuntimeException"
-
- - -

- To configure the check: -

- -<module name="IllegalCatch"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- This check can be used to ensure that types are not declared - to be thrown. Declaring that a method throws java.lang.Error or - java.lang.RuntimeException is almost never acceptable. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
illegalClassNamesthrow class names to rejectlist of strings - "java.lang.Throwable, - java.lang.Error, java.lang.RuntimeException" -
ignoredMethodNamesnames of methods to ignorelist of stringsfinalize
ignoreOverriddenMethodsignore checking overridden methods (marked with Override or java.lang.Override - annotation).Booleantrue
-
- - -

- To configure the check: -

- -<module name="IllegalThrows"/> - -

- To configure the check rejecting throws NullPointerException from methods: -

- -<module name="IllegalThrows"> - <property name="illegalClassNames" value="NullPointerException"/> -</module> - -

- To configure the check ignoring method named "foo()": -

- -<module name="IllegalThrows"> - <property name="ignoredMethodNames" value="foo"/> -</module> - -

- To configure the check to warn on overridden methods: -

- -<module name="IllegalThrows"> - <property name="ignoreOverriddenMethods" value="false"/> -</module> - -
- - - @@ -2127,6 +2661,121 @@ if ("something".equals(x))
+
+ +

Disallows assignment of parameters.

+

+ Rationale: Parameter assignment is often considered poor programming + practice. Forcing developers to declare parameters as final is often + onerous. Having a check ensure that parameters are never assigned + would give the best of both worlds. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that references to instance variables and methods of the present + object are explicitly of the form "this.varName" or + "this.methodName(args)" and that those references don't + rely on the default behavior when "this." is absent. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
checkFieldsWhether to check references to fields.booleantrue
checkMethodsWhether to check references to methods.booleantrue
+
+ + +

+ To configure the default check: +

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

+ To configure to check the this qualifier for fields only: +

+ +<module name="RequireThis"> + <property name="checkMethods" value="false"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+

@@ -2244,251 +2893,17 @@ if ("something".equals(x))

-
+

- Checks that particular classes are never used as types in variable - declarations, return values or parameters. + Checks for over-complicated boolean expressions. Currently finds + code like if (b == true), b || true, !false, + etc.

- Rationale: Helps reduce coupling on concrete classes. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
validateAbstractClassNamesWhether to validate abstract class namesbooleanfalse
illegalClassNamesClasses that should not be used as types in variable - declarations, return values or parametersString Set"java.util.HashSet, java.util.HashMap, java.util.LinkedHashMap, - java.util.LinkedHashSet, java.util.TreeSet, - java.util.TreeMap"
legalAbstractClassNamesAbstract classes that may be used as types. String Set -
ignoredMethodNamesMethods that should not be checked.String Set"getInitialContext, getEnvironment"
formatPattern for illegal class names.regular expression^(.*[\\.])?Abstract.*$
memberModifiersCheck methods and fields with only corresponding modifiers.List of tokensnull
tokenstokens to check - subset of tokens - VARIABLE_DEF, - PARAMETER_DEF, - METHOD_DEF. - - VARIABLE_DEF, - PARAMETER_DEF, - METHOD_DEF. -
-
- - -

- To configure the check so that it ignores getInstance() methods: -

- -<module name="IllegalType"> - <property name="ignoredMethodNames" value="getInstance"/> -</module> - -

- To configure the Check so that it verifies only public, protected and static - methods and fields: -

- -<module name="IllegalType"> - <property name="memberModifiers" value="LITERAL_PUBLIC, - LITERAL_PROTECTED, LITERAL_STATIC"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- According to - Code Conventions for the Java Programming Language , the parts - of a class or interface declaration should appear in the following - order: -

- -
    -
  1. - Class (static) variables. First the public class variables, then - protected, then package level (no access modifier), and then - private. -
  2. -
  3. - Instance variables. First the public class variables, then - protected, then package level (no access modifier), and then - private. -
  4. -
  5. Constructors
  6. -
  7. Methods
  8. -
- -

- Purpose of ignore* option is to ignore related violations, however it still impacts on other class members. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
ignoreConstructorswhether to ignore constructorsBooleanfalse
ignoreModifierswhether to ignore modifiersBooleanfalse
-
- - -

- To configure the check: -

- -<module name="DeclarationOrder"/> - - -

- For example: - - class K { - int a; - void m(){} - K(){} <-- "Constructor definition in wrong order" - int b; <-- "Instance variable definition in wrong order" - } - -

-

- With ignoreConstructors option: - - class K { - int a; - void m(){} - K(){} - int b; <-- "Instance variable definition in wrong order" - } - -

-

- With ignoreConstructors option and without a method definition in a source class: - - class K { - int a; - K(){} - int b; <-- "Instance variable definition in wrong order" - } - -

-
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

Disallows assignment of parameters.

-

- Rationale: Parameter assignment is often considered poor programming - practice. Forcing developers to declare parameters as final is often - onerous. Having a check ensure that parameters are never assigned - would give the best of both worlds. + Rationale: Complex boolean logic makes code hard to understand and + maintain.

@@ -2497,14 +2912,18 @@ if ("something".equals(x)) To configure the check:

-<module name="ParameterAssignment"/> +<module name="SimplifyBooleanExpression"/> @@ -2523,24 +2942,29 @@ if ("something".equals(x))
-
+

- Checks if any class or object member is explicitly initialized to - default for its type value (null for - object references, zero for numeric types and char and false for - boolean. + Checks for over-complicated boolean return statements. For example + the following code

+ +if (valid()) + return false; +else + return true; +

- Rationale: Each instance variable gets initialized twice, to the - same value. Java initializes each instance variable to its default - value (0 or null) before performing any initialization specified in - the code. So in this case, x gets initialized to 0 twice, and bar - gets initialized to null twice. So there is a minor inefficiency. - This style of coding is a holdover from C/C++ style coding, and it - shows that the developer isn't really confident that Java - initializes instance variables to default values. + could be written as +

+ +return !valid(); + + +

+ The idea for this Check has been shamelessly stolen from the + equivalent PMD rule.

@@ -2549,14 +2973,18 @@ if ("something".equals(x)) To configure the check:

-<module name="ExplicitInitialization"/> +<module name="SimplifyBooleanReturn"/> @@ -2575,17 +3003,68 @@ if ("something".equals(x))
-
+

- Check that the default is after all the - cases in a switch statement. + Checks that string literals are not used with == or + !=.

- Rationale: Java allows default anywhere - within the switch statement. But it is - more readable if it comes after the last case. + Rationale: Novice Java programmers often use code like: +

+ +if (x == "something") + + +

when they mean

+ +if ("something".equals(x)) + +
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.coding +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that an overriding clone() method invokes + super.clone(). Does not check native methods, as + they have no possible java defined implementation. +

+ +

+ Reference: Object.clone().

@@ -2594,14 +3073,14 @@ if ("something".equals(x)) To configure the check:

-<module name="DefaultComesLast"/> +<module name="SuperClone"/> @@ -2620,11 +3099,18 @@ if ("something".equals(x))
-
+

- Checks that classes (except abstract ones) define a constructor and don't - rely on the default one. + Checks that an overriding finalize() method invokes + super.finalize(). Does not check native methods, as + they have no possible java defined implementation. +

+ +

+ Reference: + Use Finalization Only When You Must.

@@ -2633,373 +3119,14 @@ if ("something".equals(x)) To configure the check:

-<module name="MissingCtor"/> +<module name="SuperFinalize"/> - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks for fall-through in switch - statements. Finds locations where a case - contains Java code but lacks a break, return, - throw or continue - statement. -

-

- The check honors special comments to suppress the warning. By - default the text "fallthru", "fall through", "fallthrough", - "falls through" and "fallsthrough" are recognized (case - sensitive). The comment containing these words must be all on one line, and must - be on the last non-empty line before the - case triggering the warning or on - the same line before the case - (ugly, but possible). -

- -switch (i){ -case 0: - i++; // fall through - -case 1: - i++; - // falls through -case 2: -case 3: -case 4: { - i++; -} -// fallthrough -case 5: - i++; -/* fallthru */case 6: - i++ - break; -} - -

- Note: The check assumes that there is no unreachable - code in the case. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
checkLastCaseGroup - Whether the last case group must be checked. - Booleanfalse
reliefPattern - Regular expression to match the relief comment that suppresses - the warning about a fall through. - regular expressionfallthru|falls? ?through
-
- - -

- To configure the check: -

- -<module name="FallThrough"/> - -

- or -

- -<module name="FallThrough"> - <property name="reliefPattern" value="continue in next case"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks for multiple occurrences of the same string literal within a - single file. -

- -

- Rationale: Code duplication makes maintenance more difficult, so it - can be better to replace the multiple occurrences with a constant. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowedDuplicates - The maximum number of occurrences to allow without generating a - warning - Integer1
ignoreStringsRegexp - Regular expression pattern for ignored strings (with quotation marks) - regular expression^""$ (ignore empty strings)
ignoreOccurrenceContext - Token type names where duplicate strings are ignored even if they don't match - ignoredStringsRegexp. This allows you to exclude syntactical contexts like - annotations or static initializers from the check. - - list of - token type - names - - ANNOTATION - (ignore strings inside the context of an annotation) -
-
- - -

- To configure the check: -

- -<module name="MultipleStringLiterals"/> - - -

- To configure the check so that it allows two occurrences of each - string: -

- -<module name="MultipleStringLiterals"> - <property name="allowedDuplicates" value="2"/> -</module> - - -

- To configure the check so that it ignores ", " and empty strings: -

- -<module name="MultipleStringLiterals"> - <property name="ignoreStringsRegexp" value='^(("")|(", "))$'/> -</module> - - -

- To configure the check so that it flags duplicate strings in all - syntactical contexts, even in annotations like - @SuppressWarnings("unchecked"): -

- -<module name="MultipleStringLiterals"> - <property name="ignoreOccurrenceContext" value=""/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that each variable declaration is in its own statement and on - its own line. -

- -

- Rationale: - the Java code conventions chapter 6.1 recommends that - declarations should be one per line/statement. -

-
- - -

- To configure the check: -

- -<module name="MultipleVariableDeclarations"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that references to instance variables and methods of the present - object are explicitly of the form "this.varName" or - "this.methodName(args)" and that those references don't - rely on the default behavior when "this." is absent. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
checkFieldsWhether to check references to fields.booleantrue
checkMethodsWhether to check references to methods.booleantrue
-
- - -

- To configure the default check: -

- -<module name="RequireThis"/> - - -

- To configure to check the this qualifier for fields only: -

- -<module name="RequireThis"> - <property name="checkMethods" value="false"/> -</module> - -
- - - @@ -3120,82 +3247,6 @@ case 5:
-
- -

- Checks that there is only one statement per line. -

-

- Rationale: It's very difficult to read multiple statements on one line. -

-

- In the Java programming language, statements are the fundamental unit of - execution. All statements except blocks are terminated by a semicolon. - Blocks are denoted by open and close curly braces. -

-

- OneStatementPerLineCheck checks the following types of statements: - variable declaration statements, empty statements, import statements, - assignment statements, expression statements, increment statements, - object creation statements, 'for loop' statements, 'break' statements, - 'continue' statements, 'return' statements. -

-
- - -

- The following examples will be flagged as a violation: -

- -//Each line causes violation: -int var1; int var2; -var1 = 1; var2 = 2; -int var1 = 1; int var2 = 2; -var1++; var2++; -Object obj1 = new Object(); Object obj2 = new Object(); -import java.io.EOFException; import java.io.BufferedReader; -;; //two empty statements on the same line. - -//Multi-line statements: -int var1 = 1 -; var2 = 2; //violation here -int o = 1, p = 2, -r = 5; int t; //violation here - -

- An example of how to configure this Check: -

- -<module name="OneStatementPerLine"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
-

@@ -3400,56 +3451,5 @@ cal.set(Calendar.MINUTE, minutes);

-
- -

- Checks that overload methods are grouped together. -

-
- - -

- Example of incorrect grouping overload methods: -

- -public void foo(int i) {} -public void foo(String s) {} -public void notFoo() {} // Have to be after foo(int i, String s) -public void foo(int i, String s) {} - -

- An example of how to configure the check is: -

- -<module name="OverloadMethodsDeclarationOrder"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.coding -

-
- - -

- TreeWalker -

-
-
- diff --git a/src/xdocs/config_design.xml b/src/xdocs/config_design.xml index 45d730e17..7431c9b16 100644 --- a/src/xdocs/config_design.xml +++ b/src/xdocs/config_design.xml @@ -21,6 +21,631 @@
+
+ +

+ The Check finds classes that are designed for extension (subclass creation). +

+

+ Problem is described at "Effective Java, 2nd Edition by Josh Bloch" book, chapter "Item 17: Design and document for inheritance or else prohibit it". +

+

+ Some quotes from book: +

+
The class must document its self-use of overridable methods. +By convention, a method that invokes overridable methods contains a description +of these invocations at the end of its documentation comment. The description +begins with the phrase “This implementation.” +
+
The best solution to this problem is to prohibit subclassing in classes that +are not designed and documented to be safely subclassed. +
+
If a concrete class does not implement a standard interface, then you may +inconvenience some programmers by prohibiting inheritance. If you feel that you +must allow inheritance from such a class, one reasonable approach is to ensure +that the class never invokes any of its overridable methods and to document this +fact. In other words, eliminate the class’s self-use of overridable methods entirely. +In doing so, you’ll create a class that is reasonably safe to subclass. Overriding a +method will never affect the behavior of any other method. +
+

+ The exact rule is that non-private, non-static methods of classes that + can be subclassed must +

+ +
    +
  • be abstract or
  • +
  • be final or
  • +
  • have an empty implementation.
  • +
+ +

+ Rationale: This API design style protects superclasses against + being broken by subclasses. The downside is that subclasses are + limited in their flexibility, in particular they cannot prevent + execution of code in the superclass, but that also means that + subclasses cannot corrupt the state of the superclass by forgetting + to call the superclass's method. +

+

+ More specifically, + it enforces a programming style where superclasses provide empty + "hooks" that can be implemented by subclasses. +

+

+ Example of code that cause violation as it is designed for extension: +

+ +public abstract class Plant { + private String roots; + private String trunk; + + protected void validate() { + if (roots == null) throw new IllegalArgumentException("No roots!"); + if (trunk == null) throw new IllegalArgumentException("No trunk!"); + } + + public abstract void grow(); +} + +public class Tree extends Plant { + private List leaves; + + @Overrides + protected void validate() { + super.validate(); + if (leaves == null) throw new IllegalArgumentException("No leaves!"); + } + + public void grow() { + validate(); + } +} + +

+ Example of code without violation: +

+ +public abstract class Plant { + private String roots; + private String trunk; + + private void validate() { + if (roots == null) throw new IllegalArgumentException("No roots!"); + if (trunk == null) throw new IllegalArgumentException("No trunk!"); + validateEx(); + } + + protected void validateEx() { } + + public abstract void grow(); +} + +
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that a class which has only private constructors is declared + as final. Doesn't check for classes nested in interfaces + or annotations, as they are always final there. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Makes sure that utility classes (classes that contain only static + methods or fields in their API) do not have a public constructor. +

+ +

+ Rationale: Instantiating utility classes does not make sense. Hence + the constructors should either be private or (if you want to allow + subclassing) protected. A common mistake is forgetting to hide the + default constructor. +

+ +

+ If you make the constructor protected you may want to consider the + following constructor implementation technique to disallow + instantiating subclasses: +

+ + +public class StringUtils // not final to allow subclassing +{ + protected StringUtils() { + // prevents calls from subclass + throw new UnsupportedOperationException(); + } + + public static int count(char c, String s) { + // ... + } +} + +
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Check nested (inner) classes/interfaces are declared at the + bottom of the class after all method and field declarations. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Implements Joshua Bloch, Effective Java, Item 17 - Use Interfaces only to + define types. +

+ +

+ According to Bloch, an interface should describe a type. + It is therefore inappropriate to define an interface that does not + contain any methods but only constants. The Standard class javax.swing.SwingConstants + is an example of a class that would be flagged by this check. +

+ +

+ The check can be configured to also disallow marker interfaces like + java.io.Serializable, that do not contain methods or + constants at all. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowMarkerInterfaces + Controls whether marker interfaces like Serializable are + allowed. + Booleantrue
+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Ensures that exception classes (classes with names conforming to some regular + expression and explicitly extending classes with names conforming to other + regular expression) are immutable, that is, that they have only final fields. +

+ +

+ The current algorithm is very simple: it checks that all members of + exception are final. The user can still mutate an exception's instance + (e.g. Throwable has a method called setStackTrace + which changes the exception's stack trace). But, at least, all information + provided by this exception type is unchangeable. +

+ +

+ Rationale: Exception instances should represent an error + condition. Having non final fields not only allows the state to be + modified by accident and therefore mask the original condition but + also allows developers to accidentally forget to set the initial state. + In both cases, code catching the exception could draw incorrect + conclusions based on the state. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatpattern for exception class namesregular expression^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormatpattern for extended class namesregular expression^.*Exception$|^.*Error$|^.*Throwable$
+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that each top-level class, interface or + enum resides in a source file of its own. + Official description of a 'top-level' term:7.6. Top Level Type Declarations. + If file doesn't contains public class, enum or interface, + top-level type is the first type in file. +

+
+ + +

+ An example of check's configuration: +

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

+ ATTENTION: This Check does not support customization of validated tokens, so do not use the "tokens" property. +

+

+ An example of code with violations: +

+ +public class Foo{ + //methods +} + +class Foo2{ + //methods +} + +

+ An example of code without public top-level type: +

+ +class Foo{ // top-level class + //methods +} + +class Foo2{ + //methods +} + +

+ An example of code without violations: +

+ +public class Foo{ + //methods +} + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Restricts throws statements to a specified count (4 by default). + Methods with "Override" or "java.lang.Override" annotation are skipped + from validation as current class cannot change signature of these methods. +

+ +

+ Rationale: Exceptions form part of a method's interface. Declaring a + method to throw too many differently rooted exceptions makes + exception handling onerous and leads to poor programming practices + such as writing code like catch(Exception ex). + 4 is the empirical value which is based on reports that we had for + the ThrowsCountCheck over big projects such as OpenJDK. + This check also forces developers to put exceptions into a hierarchy + such that in the simplest case, only one type of exception need be + checked for by a caller but any subclasses can be caught specifically + if necessary.For more information on rules for the exceptions and + their issues, see Effective Java: Programming Language Guide + Second Edition by Joshua Bloch pages 264-273. +

+ +

+ ignorePrivateMethods - allows to skip private methods as they do + not cause problems for other classes. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
maxmaximum allowed number of throws statementsInteger4
ignorePrivateMethodswhether private methods must be ignoredBooleantrue
+
+ + +

+ To configure the check so that it doesn't allow more than two throws + per method: +

+ +<module name="ThrowsCount"> + <property name="max" value="2"/> +</module> + + +

+ To configure the check so that it doesn't skip private methods: +

+ +<module name="ThrowsCount"> + <property name="ignorePrivateMethods" value="false"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.design +

+
+ + +

+ TreeWalker +

+
+
+

@@ -312,630 +937,5 @@ class SomeClass

- -
- -

- Checks that a class which has only private constructors is declared - as final. Doesn't check for classes nested in interfaces - or annotations, as they are always final there. -

-
- - -

- To configure the check: -

- -<module name="FinalClass"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Implements Joshua Bloch, Effective Java, Item 17 - Use Interfaces only to - define types. -

- -

- According to Bloch, an interface should describe a type. - It is therefore inappropriate to define an interface that does not - contain any methods but only constants. The Standard class javax.swing.SwingConstants - is an example of a class that would be flagged by this check. -

- -

- The check can be configured to also disallow marker interfaces like - java.io.Serializable, that do not contain methods or - constants at all. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowMarkerInterfaces - Controls whether marker interfaces like Serializable are - allowed. - Booleantrue
-
- - -

- To configure the check: -

- -<module name="InterfaceIsType"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Makes sure that utility classes (classes that contain only static - methods or fields in their API) do not have a public constructor. -

- -

- Rationale: Instantiating utility classes does not make sense. Hence - the constructors should either be private or (if you want to allow - subclassing) protected. A common mistake is forgetting to hide the - default constructor. -

- -

- If you make the constructor protected you may want to consider the - following constructor implementation technique to disallow - instantiating subclasses: -

- - -public class StringUtils // not final to allow subclassing -{ - protected StringUtils() { - // prevents calls from subclass - throw new UnsupportedOperationException(); - } - - public static int count(char c, String s) { - // ... - } -} - -
- - -

- To configure the check: -

- -<module name="HideUtilityClassConstructor"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- The Check finds classes that are designed for extension (subclass creation). -

-

- Problem is described at "Effective Java, 2nd Edition by Josh Bloch" book, chapter "Item 17: Design and document for inheritance or else prohibit it". -

-

- Some quotes from book: -

-
The class must document its self-use of overridable methods. -By convention, a method that invokes overridable methods contains a description -of these invocations at the end of its documentation comment. The description -begins with the phrase “This implementation.” -
-
The best solution to this problem is to prohibit subclassing in classes that -are not designed and documented to be safely subclassed. -
-
If a concrete class does not implement a standard interface, then you may -inconvenience some programmers by prohibiting inheritance. If you feel that you -must allow inheritance from such a class, one reasonable approach is to ensure -that the class never invokes any of its overridable methods and to document this -fact. In other words, eliminate the class’s self-use of overridable methods entirely. -In doing so, you’ll create a class that is reasonably safe to subclass. Overriding a -method will never affect the behavior of any other method. -
-

- The exact rule is that non-private, non-static methods of classes that - can be subclassed must -

- -
    -
  • be abstract or
  • -
  • be final or
  • -
  • have an empty implementation.
  • -
- -

- Rationale: This API design style protects superclasses against - being broken by subclasses. The downside is that subclasses are - limited in their flexibility, in particular they cannot prevent - execution of code in the superclass, but that also means that - subclasses cannot corrupt the state of the superclass by forgetting - to call the superclass's method. -

-

- More specifically, - it enforces a programming style where superclasses provide empty - "hooks" that can be implemented by subclasses. -

-

- Example of code that cause violation as it is designed for extension: -

- -public abstract class Plant { - private String roots; - private String trunk; - - protected void validate() { - if (roots == null) throw new IllegalArgumentException("No roots!"); - if (trunk == null) throw new IllegalArgumentException("No trunk!"); - } - - public abstract void grow(); -} - -public class Tree extends Plant { - private List leaves; - - @Overrides - protected void validate() { - super.validate(); - if (leaves == null) throw new IllegalArgumentException("No leaves!"); - } - - public void grow() { - validate(); - } -} - -

- Example of code without violation: -

- -public abstract class Plant { - private String roots; - private String trunk; - - private void validate() { - if (roots == null) throw new IllegalArgumentException("No roots!"); - if (trunk == null) throw new IllegalArgumentException("No trunk!"); - validateEx(); - } - - protected void validateEx() { } - - public abstract void grow(); -} - -
- - -

- To configure the check: -

- - -<module name="DesignForExtension"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Ensures that exception classes (classes with names conforming to some regular - expression and explicitly extending classes with names conforming to other - regular expression) are immutable, that is, that they have only final fields. -

- -

- The current algorithm is very simple: it checks that all members of - exception are final. The user can still mutate an exception's instance - (e.g. Throwable has a method called setStackTrace - which changes the exception's stack trace). But, at least, all information - provided by this exception type is unchangeable. -

- -

- Rationale: Exception instances should represent an error - condition. Having non final fields not only allows the state to be - modified by accident and therefore mask the original condition but - also allows developers to accidentally forget to set the initial state. - In both cases, code catching the exception could draw incorrect - conclusions based on the state. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
formatpattern for exception class namesregular expression^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormatpattern for extended class namesregular expression^.*Exception$|^.*Error$|^.*Throwable$
-
- - -

- To configure the check: -

- -<module name="MutableException"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Restricts throws statements to a specified count (4 by default). - Methods with "Override" or "java.lang.Override" annotation are skipped - from validation as current class cannot change signature of these methods. -

- -

- Rationale: Exceptions form part of a method's interface. Declaring a - method to throw too many differently rooted exceptions makes - exception handling onerous and leads to poor programming practices - such as writing code like catch(Exception ex). - 4 is the empirical value which is based on reports that we had for - the ThrowsCountCheck over big projects such as OpenJDK. - This check also forces developers to put exceptions into a hierarchy - such that in the simplest case, only one type of exception need be - checked for by a caller but any subclasses can be caught specifically - if necessary.For more information on rules for the exceptions and - their issues, see Effective Java: Programming Language Guide - Second Edition by Joshua Bloch pages 264-273. -

- -

- ignorePrivateMethods - allows to skip private methods as they do - not cause problems for other classes. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
maxmaximum allowed number of throws statementsInteger4
ignorePrivateMethodswhether private methods must be ignoredBooleantrue
-
- - -

- To configure the check so that it doesn't allow more than two throws - per method: -

- -<module name="ThrowsCount"> - <property name="max" value="2"/> -</module> - - -

- To configure the check so that it doesn't skip private methods: -

- -<module name="ThrowsCount"> - <property name="ignorePrivateMethods" value="false"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Check nested (inner) classes/interfaces are declared at the - bottom of the class after all method and field declarations. -

-
- - -

- To configure the check: -

- -<module name="InnerTypeLast"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that each top-level class, interface or - enum resides in a source file of its own. - Official description of a 'top-level' term:7.6. Top Level Type Declarations. - If file doesn't contains public class, enum or interface, - top-level type is the first type in file. -

-
- - -

- An example of check's configuration: -

- -<module name="OneTopLevelClass"/> - -

- ATTENTION: This Check does not support customization of validated tokens, so do not use the "tokens" property. -

-

- An example of code with violations: -

- -public class Foo{ - //methods -} - -class Foo2{ - //methods -} - -

- An example of code without public top-level type: -

- -class Foo{ // top-level class - //methods -} - -class Foo2{ - //methods -} - -

- An example of code without violations: -

- -public class Foo{ - //methods -} - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.design -

-
- - -

- TreeWalker -

-
-
diff --git a/src/xdocs/config_filters.xml b/src/xdocs/config_filters.xml index fd5bc5123..730a191e5 100644 --- a/src/xdocs/config_filters.xml +++ b/src/xdocs/config_filters.xml @@ -89,221 +89,6 @@
-
- -

- Filter SuppressionFilter rejects - audit events for Check errors according to - a suppressions XML - document in a file. If there is no configured - suppressions file, the Filter accepts all audit events. -

-
- - - - - - - - - - - - - - -
namedescriptiontypedefault value
file - the location of the suppressions XML document file. - The order the location is checked is: -
    -
  1. as a filesystem location
  2. -
  3. - if no file found, and the location starts with either - http:// or https://, then it - is interpreted as a URL -
  4. -
  5. - if no file found, then passed to the - ClassLoader.getResource() method. -
  6. -
-
stringnone
-
- -

- For example, the following configuration fragment directs the - Checker to use a SuppressionFilter - with suppressions - file config/suppressions.xml: -

- -<module name="SuppressionFilter"> - <property name="file" value="config/suppressions.xml"/> -</module> - -

- A suppressions XML - document contains a set - of suppress elements, where - each suppress element can have the - following attributes: -

-
    -
  • - files - - a regular expression - matched against the file name associated with an audit - event. It is mandatory. -
  • -
  • - checks - - a regular expression - matched against the name of the check associated with an audit - event. Optional if id is specified. -
  • -
  • - id - - a string - matched against the ID of the check associated with an audit - event. Optional if checks is specified. -
  • -
  • - lines - a comma-separated list of - values, where each value is - an integer or a - range of integers denoted by integer-integer. It is optional. -
  • -
  • - columns - a comma-separated list of - values, where each value is - an integer or a - range of integers denoted by integer-integer. It is optional. -
  • -
-

- Each audit event is checked against - each suppress element. It is - suppressed if all specified attributes match against the audit - event. -

-

- You can download template of empty suppression filter - here. -

-

- The following suppressions XML document directs - a SuppressionFilter to - reject JavadocStyleCheck errors for - lines 82 and 108 to 122 of - file AbstractComplexityCheck.java, - and MagicNumberCheck errors for line - 221 of file JavadocStyleCheck.java: -

- -<?xml version="1.0"?> - -<!DOCTYPE suppressions PUBLIC -"-//Puppy Crawl//DTD Suppressions 1.1//EN" -"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> - -<suppressions> -<suppress checks="JavadocStyleCheck" - files="AbstractComplexityCheck.java" - lines="82,108-122"/> -<suppress checks="MagicNumberCheck" - files="JavadocStyleCheck.java" - lines="221"/> -</suppressions> - -

- As another example to suppress Check by module id: -

- -<module name="DescendantToken"> - <property name="id" value="stringEqual"/> - <property name="tokens" value="EQUAL,NOT_EQUAL"/> - <property name="limitedTokens" value="STRING_LITERAL"/> - <property name="maximumNumber" value="0"/> - <property name="maximumDepth" value="1"/> -</module> - -<module name="DescendantToken"> - <property name="id" value="switchNoDefault"/> - <property name="tokens" value="LITERAL_SWITCH"/> - <property name="maximumDepth" value="2"/> - <property name="limitedTokens" value="LITERAL_DEFAULT"/> - <property name="minimumNumber" value="1"/> -</module> - -

- Then the following can be used to suppress only the first - check and not the second by using - the id attribute: -

- -<suppress id="stringEqual" files="SomeTestCode.java"/> - -

- Suppress checks for hidden files and folders: -

- -<suppress files="[/\\]\..+" checks=".*"/> - -

- Suppress checks for Maven-generated code: -

- -<suppress files="[/\\]target[/\\]" checks=".*"/> - -

- Suppress checks for archives, classes and other binary files: -

- -<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/> - -

- Suppress checks for image files: -

- -<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/> - -

- Suppress checks for non-java files: -

- -<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$" checks=".*"/> - -

- Suppress all checks in generated sources: -

- -<suppress checks=".*" files="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/> - -

- Suppress FileLength check on integration tests in certain folder: -

- -<suppress checks="FileLength" files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/> - -
- - - - -

com.puppycrawl.tools.checkstyle.filters

-
- - -

Checker

-
-
-

@@ -550,6 +335,288 @@ HashSet hashSet; // Warning here: Declaring variables, return values or paramete

+
+ +

+ Filter SuppressionFilter rejects + audit events for Check errors according to + a suppressions XML + document in a file. If there is no configured + suppressions file, the Filter accepts all audit events. +

+
+ + + + + + + + + + + + + + +
namedescriptiontypedefault value
file + the location of the suppressions XML document file. + The order the location is checked is: +
    +
  1. as a filesystem location
  2. +
  3. + if no file found, and the location starts with either + http:// or https://, then it + is interpreted as a URL +
  4. +
  5. + if no file found, then passed to the + ClassLoader.getResource() method. +
  6. +
+
stringnone
+
+ +

+ For example, the following configuration fragment directs the + Checker to use a SuppressionFilter + with suppressions + file config/suppressions.xml: +

+ +<module name="SuppressionFilter"> + <property name="file" value="config/suppressions.xml"/> +</module> + +

+ A suppressions XML + document contains a set + of suppress elements, where + each suppress element can have the + following attributes: +

+
    +
  • + files - + a regular expression + matched against the file name associated with an audit + event. It is mandatory. +
  • +
  • + checks - + a regular expression + matched against the name of the check associated with an audit + event. Optional if id is specified. +
  • +
  • + id - + a string + matched against the ID of the check associated with an audit + event. Optional if checks is specified. +
  • +
  • + lines - a comma-separated list of + values, where each value is + an integer or a + range of integers denoted by integer-integer. It is optional. +
  • +
  • + columns - a comma-separated list of + values, where each value is + an integer or a + range of integers denoted by integer-integer. It is optional. +
  • +
+

+ Each audit event is checked against + each suppress element. It is + suppressed if all specified attributes match against the audit + event. +

+

+ You can download template of empty suppression filter + here. +

+

+ The following suppressions XML document directs + a SuppressionFilter to + reject JavadocStyleCheck errors for + lines 82 and 108 to 122 of + file AbstractComplexityCheck.java, + and MagicNumberCheck errors for line + 221 of file JavadocStyleCheck.java: +

+ +<?xml version="1.0"?> + +<!DOCTYPE suppressions PUBLIC +"-//Puppy Crawl//DTD Suppressions 1.1//EN" +"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> + +<suppressions> +<suppress checks="JavadocStyleCheck" + files="AbstractComplexityCheck.java" + lines="82,108-122"/> +<suppress checks="MagicNumberCheck" + files="JavadocStyleCheck.java" + lines="221"/> +</suppressions> + +

+ As another example to suppress Check by module id: +

+ +<module name="DescendantToken"> + <property name="id" value="stringEqual"/> + <property name="tokens" value="EQUAL,NOT_EQUAL"/> + <property name="limitedTokens" value="STRING_LITERAL"/> + <property name="maximumNumber" value="0"/> + <property name="maximumDepth" value="1"/> +</module> + +<module name="DescendantToken"> + <property name="id" value="switchNoDefault"/> + <property name="tokens" value="LITERAL_SWITCH"/> + <property name="maximumDepth" value="2"/> + <property name="limitedTokens" value="LITERAL_DEFAULT"/> + <property name="minimumNumber" value="1"/> +</module> + +

+ Then the following can be used to suppress only the first + check and not the second by using + the id attribute: +

+ +<suppress id="stringEqual" files="SomeTestCode.java"/> + +

+ Suppress checks for hidden files and folders: +

+ +<suppress files="[/\\]\..+" checks=".*"/> + +

+ Suppress checks for Maven-generated code: +

+ +<suppress files="[/\\]target[/\\]" checks=".*"/> + +

+ Suppress checks for archives, classes and other binary files: +

+ +<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/> + +

+ Suppress checks for image files: +

+ +<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/> + +

+ Suppress checks for non-java files: +

+ +<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$" checks=".*"/> + +

+ Suppress all checks in generated sources: +

+ +<suppress checks=".*" files="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/> + +

+ Suppress FileLength check on integration tests in certain folder: +

+ +<suppress checks="FileLength" files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/> + +
+ + + + +

com.puppycrawl.tools.checkstyle.filters

+
+ + +

Checker

+
+
+ +
+ +

+ Filter SuppressWarningsFilter uses annotations to + suppress audit events. +

+

+ Rationale: Same as for + SuppressionCommentFilter. In the contrary to it + here, comments are not used comments but the builtin syntax of + @SuppressWarnings. This can be perceived as a + more elegant solution than using comments. Also this approach + maybe supported by various IDE. +

+

+ Usage: This filter only works in conjunction with a + SuppressWarningsHolder, since that check finds + the annotations in the Java files and makes them available for + the filter. Because of that, a configuration that includes + this filter must also include + SuppressWarningsHolder as a child module of the + TreeWalker. Name of check in annotation is case-insensitive + and should be written with any dotted prefix or "Check" suffix removed. +

+
+ +

+ To configure the check that makes tha annotations available to + the filter. +

+ +<module name="TreeWalker"> + ... +<module name="SuppressWarningsHolder" /> + ... +</module> + +

To configure filter to suppress audit events for annotations add:

+ +<module name="SuppressWarningsFilter" /> + + +@SuppressWarnings({"memberName"}) +private int J; // should NOT fail MemberNameCheck + +@SuppressWarnings({"MemberName"}) +@SuppressWarnings({"NoWhitespaceAfter"}) +private int [] ARRAY; // should NOT fail MemberNameCheck and NoWhitespaceAfterCheck + +
+ + + + +

com.puppycrawl.tools.checkstyle.filters

+
+ + +

Checker

+
+
+

@@ -740,72 +807,5 @@ public static final int [] array; // @cs.suppress ConstantName | NoWhitespaceAft

Checker

- -
- -

- Filter SuppressWarningsFilter uses annotations to - suppress audit events. -

-

- Rationale: Same as for - SuppressionCommentFilter. In the contrary to it - here, comments are not used comments but the builtin syntax of - @SuppressWarnings. This can be perceived as a - more elegant solution than using comments. Also this approach - maybe supported by various IDE. -

-

- Usage: This filter only works in conjunction with a - SuppressWarningsHolder, since that check finds - the annotations in the Java files and makes them available for - the filter. Because of that, a configuration that includes - this filter must also include - SuppressWarningsHolder as a child module of the - TreeWalker. Name of check in annotation is case-insensitive - and should be written with any dotted prefix or "Check" suffix removed. -

-
- -

- To configure the check that makes tha annotations available to - the filter. -

- -<module name="TreeWalker"> - ... -<module name="SuppressWarningsHolder" /> - ... -</module> - -

To configure filter to suppress audit events for annotations add:

- -<module name="SuppressWarningsFilter" /> - - -@SuppressWarnings({"memberName"}) -private int J; // should NOT fail MemberNameCheck - -@SuppressWarnings({"MemberName"}) -@SuppressWarnings({"NoWhitespaceAfter"}) -private int [] ARRAY; // should NOT fail MemberNameCheck and NoWhitespaceAfterCheck - -
- - - - -

com.puppycrawl.tools.checkstyle.filters

-
- - -

Checker

-
-
diff --git a/src/xdocs/config_imports.xml b/src/xdocs/config_imports.xml index 64088d951..b9bf32d6e 100644 --- a/src/xdocs/config_imports.xml +++ b/src/xdocs/config_imports.xml @@ -195,588 +195,6 @@
-
- -

- Checks for imports from a set of illegal packages. By default, the - check rejects all sun.* packages since - programs that contain direct calls to the sun.* packages are "not guaranteed - to work on all Java-compatible platforms". To reject other packages, set property illegalPkgs to a list of the illegal packages. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
illegalPkgspackages to rejectlist of stringssun
-
- - -

- To configure the check: -

- -<module name="IllegalImport"/> - - -

- To configure the check so that it rejects packages java.io.* and java.sql.*: -

- -<module name="IllegalImport"> - <property name="illegalPkgs" value="java.io, java.sql"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.imports -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks for redundant import statements. An import statement is - considered redundant if: -

- -
    -
  • - It is a duplicate of another import. This is, when a class is - imported more than once. -
  • -
  • - The class non-statically imported is from the java.lang - package, e.g. importing java.lang.String. -
  • -
  • - The class non-statically imported is from the same package as the current package. -
  • -
-
- - -

- To configure the check: -

- -<module name="RedundantImport"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.imports -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks for unused import statements. Checkstyle uses a simple but - very reliable algorithm to report on unused import statements. An - import statement is considered unused if: -

- -
    -
  • - It is not referenced in the file. The algorithm does not support - wild-card imports like import - java.io.*;. Most IDE's provide very sophisticated checks - for imports that handle wild-card imports. -
  • - -
  • - It is a duplicate of another import. This is when a class is - imported more than once. -
  • - -
  • - The class imported is from the java.lang - package. For example importing java.lang.String. -
  • - -
  • - The class imported is from the same package. -
  • -
  • - Optionally: it is referenced in Javadoc comments. This check - is off by default, as it is considered bad practice to introduce - a compile time dependency for documentation purposes only. - As an example, the import java.util.Date would be - considered referenced with the Javadoc comment - {@link Date}. The alternative to avoid introducing a - compile time dependency would be to write the Javadoc comment as - {@link java.util.Date}. -
  • -
-

- The main limitation of this check is handling the case where - an imported type has the same name as a declaration, such as a - member variable. -

-

- For example, in the following case the import java.awt.Component will not be flagged as - unused: -

- -import java.awt.Component; -class FooBar { - private Object Component; // a bad practice in my opinion - ... -} - -
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
processJavadocwhether to process Javadocbooleanfalse
-
- - -

- To configure the check: -

- -<module name="UnusedImports"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.imports -

-
- - -

- TreeWalker -

-
-
- -
- -

Checks the ordering/grouping of imports. Features are:

-
    -
  • groups imports: ensures that groups of imports come in a - specific order (e.g., java. comes first, javax. comes second, - then everything else)
  • -
  • adds a separation between groups : ensures that a blank - line sit between each group
  • -
  • sorts imports inside each group: ensures that imports - within each group are in lexicographic order
  • -
  • sorts according to case: ensures that the comparison - between imports is case sensitive, in - ASCII sort order
  • -
  • groups static imports: ensures the relative order between - regular imports and static imports (see - import orders)
  • -
-

- Examples section contains examples that - work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
optionpolicy on the relative order between regular imports and static importsimport orderunder
groups - list of imports groups (every group identified either by a - common prefix string, or by a regular expression enclosed - in forward slashes (e.g. /regexp/) - list of stringsempty list
orderedwhether imports within group should be sortedBooleantrue
separated - whether imports groups should be separated by, at least, one - blank line - Booleanfalse
caseSensitivewhether string comparison should be case sensitive or not. - Case sensitive sorting is in - ASCII sort order - Booleantrue
sortStaticImportsAlphabeticallywhether static imports grouped by top or bottom option - are sorted alphabetically or notBooleanfalse
tokenstokens to check - subset of tokens - STATIC_IMPORT. - - STATIC_IMPORT. -
-
- - -

To configure the check so that it matches default Eclipse formatter configuration - (tested on Kepler and Luna releases):

-
    -
  • group of static imports is on the top
  • -
  • groups of non-static imports: "java" and "javax" packages first, - then "org" and then all other imports
  • -
  • imports will be sorted in the groups
  • -
  • groups are separated by, at least, one blank line
  • -
-

Notes:

-
    -
  • "com" package is not mentioned on configuration, because it is - ignored by Eclipse Kepler and Luna (looks like Eclipse defect)
  • -
  • configuration below doesn't work in all 100% cases due to inconsistent behavior - prior to Mars release, but covers most scenarios
  • -
- - -<module name="ImportOrder"> - <property name="groups" value="/^javax?\./,org"/> - <property name="ordered" value="true"/> - <property name="separated" value="true"/> - <property name="option" value="above"/> - <property name="sortStaticImportsAlphabetically" value="true"/> -</module> - - -

To configure the check so that it matches default Eclipse formatter - configuration (tested on Mars release):

-
    -
  • group of static imports is on the top
  • -
  • groups of non-static imports: "java" and "javax" packages first, - then "org" and "com", then all other imports as one group
  • -
  • imports will be sorted in the groups
  • -
  • groups are separated by, at least, one blank line
  • -
- - -<module name="ImportOrder"> - <property name="groups" value="/^javax?\./,org,com"/> - <property name="ordered" value="true"/> - <property name="separated" value="true"/> - <property name="option" value="above"/> - <property name="sortStaticImportsAlphabetically" value="true"/> -</module> - - -

To configure the check so that it matches default IntelliJ IDEA formatter - configuration (tested on v14):

-
    -
  • group of static imports is on the bottom
  • -
  • groups of non-static imports: all imports except of "javax" - and "java", then "javax" and "java"
  • -
  • imports will be sorted in the groups
  • -
  • groups are separated by, at least, one blank line
  • -
- -

- Note: "separated" option is disabled because IDEA default has blank line - between "java" and static imports, and no blank line between - "javax" and "java" -

- - -<module name="ImportOrder"> - <property name="groups" value="*,javax,java"/> - <property name="ordered" value="true"/> - <property name="separated" value="false"/> - <property name="option" value="bottom"/> - <property name="sortStaticImportsAlphabetically" value="true"/> -</module> - - -

To configure the check so that it matches default NetBeans formatter configuration - (tested on v8):

-
    -
  • groups of non-static imports are not defined, all imports will be sorted as a one - group
  • -
  • static imports are not separated, they will be sorted along with other imports
  • -
- - -<module name="ImportOrder"> - <property name="option" value="inflow"/> -</module> - - -

- To configure the Check allows static imports grouped to the top - being sorted alphabetically: -

- - -<module name="ImportOrder"> - <property name="sortStaticImportsAlphabetically" value="true"/> - <property name="option" value="top"/> -</module> - - - -import static java.lang.Math.PI; -import static java.lang.Math.abs; // OK, alphabetical case sensitive ASCII order, 'P' < 'a' -import static org.abego.treelayout.Configuration.AlignmentInLevel; // OK, alphabetical order - -import org.abego.*; - -import java.util.Set; // Wrong order for 'java.util.Set' import. - -public class SomeClass { ... } - - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.imports -

-
- - -

- TreeWalker -

-
-
- -
- -

- Controls what can be imported in each package. Useful for - ensuring that application layering rules are not violated, - especially on large projects. -

- -

- The DTD for a import control XML document is at - http://www.puppycrawl.com/dtds/import_control_1_1.dtd. It - contains documentation on each of the elements and attributes. -

- -

- The check validates a XML document when it loads the document. - To validate against the above DTD, include the following - document type declaration in your XML document: -

- -
-<!DOCTYPE import-control PUBLIC
-    "-//Puppy Crawl//DTD Import Control 1.1//EN"
-    "http://www.puppycrawl.com/dtds/import_control_1_1.dtd">
-        
-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
file - name of the file containing the import control configuration. - stringnull
url - URL of the file containing the import control configuration. - stringnull
-
- - -

- To configure the check using a import control file called - "config/import-control.xml", then have the following: -

- - -<module name="ImportControl"> - <property name="file" value="config/import-control.xml"/> -</module> - - -

- In the example below, all classes beginning with an I in the package - java.awt are allowed. In the package java.io only the classes File - and InputStream are allowed. -

- - -<import-control pkg="com.puppycrawl.tools.checkstyle"> - <allow class="java\.awt\.I.*" regex="true"/> - <allow class="java\.io\.(File|InputStream)" local-only="true" - regex="true"/> -</import-control> - - -

- For an example import control file, look at the file called - import-control.xml - which is part of the Checkstyle distribution. -

-
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.imports -

-
- - -

- TreeWalker -

-
-
-

@@ -1109,5 +527,587 @@ import android.*;

+ +
+ +

+ Checks for imports from a set of illegal packages. By default, the + check rejects all sun.* packages since + programs that contain direct calls to the sun.* packages are "not guaranteed + to work on all Java-compatible platforms". To reject other packages, set property illegalPkgs to a list of the illegal packages. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
illegalPkgspackages to rejectlist of stringssun
+
+ + +

+ To configure the check: +

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

+ To configure the check so that it rejects packages java.io.* and java.sql.*: +

+ +<module name="IllegalImport"> + <property name="illegalPkgs" value="java.io, java.sql"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.imports +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Controls what can be imported in each package. Useful for + ensuring that application layering rules are not violated, + especially on large projects. +

+ +

+ The DTD for a import control XML document is at + http://www.puppycrawl.com/dtds/import_control_1_1.dtd. It + contains documentation on each of the elements and attributes. +

+ +

+ The check validates a XML document when it loads the document. + To validate against the above DTD, include the following + document type declaration in your XML document: +

+ +
+<!DOCTYPE import-control PUBLIC
+    "-//Puppy Crawl//DTD Import Control 1.1//EN"
+    "http://www.puppycrawl.com/dtds/import_control_1_1.dtd">
+        
+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
file + name of the file containing the import control configuration. + stringnull
url + URL of the file containing the import control configuration. + stringnull
+
+ + +

+ To configure the check using a import control file called + "config/import-control.xml", then have the following: +

+ + +<module name="ImportControl"> + <property name="file" value="config/import-control.xml"/> +</module> + + +

+ In the example below, all classes beginning with an I in the package + java.awt are allowed. In the package java.io only the classes File + and InputStream are allowed. +

+ + +<import-control pkg="com.puppycrawl.tools.checkstyle"> + <allow class="java\.awt\.I.*" regex="true"/> + <allow class="java\.io\.(File|InputStream)" local-only="true" + regex="true"/> +</import-control> + + +

+ For an example import control file, look at the file called + import-control.xml + which is part of the Checkstyle distribution. +

+
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.imports +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

Checks the ordering/grouping of imports. Features are:

+
    +
  • groups imports: ensures that groups of imports come in a + specific order (e.g., java. comes first, javax. comes second, + then everything else)
  • +
  • adds a separation between groups : ensures that a blank + line sit between each group
  • +
  • sorts imports inside each group: ensures that imports + within each group are in lexicographic order
  • +
  • sorts according to case: ensures that the comparison + between imports is case sensitive, in + ASCII sort order
  • +
  • groups static imports: ensures the relative order between + regular imports and static imports (see + import orders)
  • +
+

+ Examples section contains examples that + work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
optionpolicy on the relative order between regular imports and static importsimport orderunder
groups + list of imports groups (every group identified either by a + common prefix string, or by a regular expression enclosed + in forward slashes (e.g. /regexp/) + list of stringsempty list
orderedwhether imports within group should be sortedBooleantrue
separated + whether imports groups should be separated by, at least, one + blank line + Booleanfalse
caseSensitivewhether string comparison should be case sensitive or not. + Case sensitive sorting is in + ASCII sort order + Booleantrue
sortStaticImportsAlphabeticallywhether static imports grouped by top or bottom option + are sorted alphabetically or notBooleanfalse
tokenstokens to check + subset of tokens + STATIC_IMPORT. + + STATIC_IMPORT. +
+
+ + +

To configure the check so that it matches default Eclipse formatter configuration + (tested on Kepler and Luna releases):

+
    +
  • group of static imports is on the top
  • +
  • groups of non-static imports: "java" and "javax" packages first, + then "org" and then all other imports
  • +
  • imports will be sorted in the groups
  • +
  • groups are separated by, at least, one blank line
  • +
+

Notes:

+
    +
  • "com" package is not mentioned on configuration, because it is + ignored by Eclipse Kepler and Luna (looks like Eclipse defect)
  • +
  • configuration below doesn't work in all 100% cases due to inconsistent behavior + prior to Mars release, but covers most scenarios
  • +
+ + +<module name="ImportOrder"> + <property name="groups" value="/^javax?\./,org"/> + <property name="ordered" value="true"/> + <property name="separated" value="true"/> + <property name="option" value="above"/> + <property name="sortStaticImportsAlphabetically" value="true"/> +</module> + + +

To configure the check so that it matches default Eclipse formatter + configuration (tested on Mars release):

+
    +
  • group of static imports is on the top
  • +
  • groups of non-static imports: "java" and "javax" packages first, + then "org" and "com", then all other imports as one group
  • +
  • imports will be sorted in the groups
  • +
  • groups are separated by, at least, one blank line
  • +
+ + +<module name="ImportOrder"> + <property name="groups" value="/^javax?\./,org,com"/> + <property name="ordered" value="true"/> + <property name="separated" value="true"/> + <property name="option" value="above"/> + <property name="sortStaticImportsAlphabetically" value="true"/> +</module> + + +

To configure the check so that it matches default IntelliJ IDEA formatter + configuration (tested on v14):

+
    +
  • group of static imports is on the bottom
  • +
  • groups of non-static imports: all imports except of "javax" + and "java", then "javax" and "java"
  • +
  • imports will be sorted in the groups
  • +
  • groups are separated by, at least, one blank line
  • +
+ +

+ Note: "separated" option is disabled because IDEA default has blank line + between "java" and static imports, and no blank line between + "javax" and "java" +

+ + +<module name="ImportOrder"> + <property name="groups" value="*,javax,java"/> + <property name="ordered" value="true"/> + <property name="separated" value="false"/> + <property name="option" value="bottom"/> + <property name="sortStaticImportsAlphabetically" value="true"/> +</module> + + +

To configure the check so that it matches default NetBeans formatter configuration + (tested on v8):

+
    +
  • groups of non-static imports are not defined, all imports will be sorted as a one + group
  • +
  • static imports are not separated, they will be sorted along with other imports
  • +
+ + +<module name="ImportOrder"> + <property name="option" value="inflow"/> +</module> + + +

+ To configure the Check allows static imports grouped to the top + being sorted alphabetically: +

+ + +<module name="ImportOrder"> + <property name="sortStaticImportsAlphabetically" value="true"/> + <property name="option" value="top"/> +</module> + + + +import static java.lang.Math.PI; +import static java.lang.Math.abs; // OK, alphabetical case sensitive ASCII order, 'P' < 'a' +import static org.abego.treelayout.Configuration.AlignmentInLevel; // OK, alphabetical order + +import org.abego.*; + +import java.util.Set; // Wrong order for 'java.util.Set' import. + +public class SomeClass { ... } + + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.imports +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks for redundant import statements. An import statement is + considered redundant if: +

+ +
    +
  • + It is a duplicate of another import. This is, when a class is + imported more than once. +
  • +
  • + The class non-statically imported is from the java.lang + package, e.g. importing java.lang.String. +
  • +
  • + The class non-statically imported is from the same package as the current package. +
  • +
+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.imports +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks for unused import statements. Checkstyle uses a simple but + very reliable algorithm to report on unused import statements. An + import statement is considered unused if: +

+ +
    +
  • + It is not referenced in the file. The algorithm does not support + wild-card imports like import + java.io.*;. Most IDE's provide very sophisticated checks + for imports that handle wild-card imports. +
  • + +
  • + It is a duplicate of another import. This is when a class is + imported more than once. +
  • + +
  • + The class imported is from the java.lang + package. For example importing java.lang.String. +
  • + +
  • + The class imported is from the same package. +
  • +
  • + Optionally: it is referenced in Javadoc comments. This check + is off by default, as it is considered bad practice to introduce + a compile time dependency for documentation purposes only. + As an example, the import java.util.Date would be + considered referenced with the Javadoc comment + {@link Date}. The alternative to avoid introducing a + compile time dependency would be to write the Javadoc comment as + {@link java.util.Date}. +
  • +
+

+ The main limitation of this check is handling the case where + an imported type has the same name as a declaration, such as a + member variable. +

+

+ For example, in the following case the import java.awt.Component will not be flagged as + unused: +

+ +import java.awt.Component; +class FooBar { + private Object Component; // a bad practice in my opinion + ... +} + +
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
processJavadocwhether to process Javadocbooleanfalse
+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.imports +

+
+ + +

+ TreeWalker +

+
+
diff --git a/src/xdocs/config_javadoc.xml b/src/xdocs/config_javadoc.xml index 57a13c230..69637a3cc 100644 --- a/src/xdocs/config_javadoc.xml +++ b/src/xdocs/config_javadoc.xml @@ -21,17 +21,10 @@
-
+

- Checks that each Java package has a Javadoc file used for - commenting. By default it only allows a package-info.java file, but can be - configured to allow a package.html - file. -

-

- An error will be reported if both files exist as this is not - allowed by the Javadoc tool. + Checks the order of at-clauses.

@@ -44,202 +37,59 @@ default value - allowLegacy - - If set then allow the use of a - package.html file. + target + allows to specify targets to check at-clauses. + subset of tokens + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF. + + + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF. - boolean - false - fileExtensions - file type extension of files to process - String Set - {} + tagOrder + allows to specify the order by tags. + String + @author, @version, @param, + @return, @throws, @exception, @see, @since, @serial, + @serialField, @serialData, @deprecated

- To configure the check: + Default configuration

-<module name="JavadocPackage"/> +<module name="AtclauseOrder"> + <property name="tagOrder" value="@author, @version, @param, + @return, @throws, @exception, @see, @since, @serial, + @serialField, @serialData, @deprecated"/> + <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, + METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> +</module>
- - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- Checker -

-
-
- -
- -

- Checks Javadoc comments for class and interface definitions. - By default, does not check for author or version tags. The - scope to verify is specified using the Scope - class and defaults to Scope.PRIVATE. To verify - another scope, set property scope to one of the - Scope constants. To define the format for an - author tag or a version tag, set property authorFormat or - versionFormat respectively to a - - regular expression. -

-

- Does not perform checks for author and version tags for inner - classes, as they should be redundant because of outer class. -

-

- Error messages about type parameters for which no param tags are - present can be suppressed by defining property - allowMissingParamTags. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
scopevisibility scope where Javadoc comments are checkedscopeprivate
excludeScopevisibility scope where Javadoc comments are not checkedscopenull
authorFormatpattern for @author tagregular expressionnull (tag not required)
versionFormatpattern for @version tagregular expressionnull (tag not required)
allowMissingParamTagswhether to ignore errors when a class has type parameters - but does not have matching param tags in the javadoc.booleanfalse
allowUnknownTagswhether to ignore errors when a Javadoc tag is not recognised.booleanfalse
tokenstokens to check - subset of tokens - INTERFACE_DEF, - CLASS_DEF, - ENUM_DEF, - ANNOTATION_DEF. - - INTERFACE_DEF, - CLASS_DEF, - ENUM_DEF, - ANNOTATION_DEF. -
-
- - -

- To configure the default check: -

- -<module name="JavadocType"/> - - -

- To configure the check for public scope: -

- -<module name="JavadocType"> - <property name="scope" value="public"/> -</module> - - -

- To configure the check for an @author tag: -

- -<module name="JavadocType"> - <property name="authorFormat" value="\S"/> -</module> - - -

- To configure the check for a CVS revision version tag: -

- -<module name="JavadocType"> - <property name="versionFormat" value="\$Revision.*\$"/> -</module> - - -

- To configure the check for private classes only: -

- -<module name="JavadocType"> - <property name="scope" value="private"/> - <property name="excludeScope" value="package"/> -</module> - -
- - - @@ -562,11 +412,17 @@ public boolean isSomething()
-
+

- Checks that variables have Javadoc comments. Ignores serialVersionUID - fields. + Checks that each Java package has a Javadoc file used for + commenting. By default it only allows a package-info.java file, but can be + configured to allow a package.html + file. +

+

+ An error will be reported if both files exist as this is not + allowed by the Javadoc tool.

@@ -579,85 +435,135 @@ public boolean isSomething() default value - scope - visibility scope where Javadoc comments are checked - scope - private - - - excludeScope - visibility scope where Javadoc comments are not checked - scope - null - - - ignoreNamePattern - regexp to define variable names to ignore - regular expression - null - - - tokens - tokens to check - subset of tokens - ENUM_CONSTANT_DEF. - + allowLegacy - ENUM_CONSTANT_DEF. + If set then allow the use of a + package.html file. + boolean + false + + + fileExtensions + file type extension of files to process + String Set + {}

- To configure the default check: + To configure the check:

-<module name="JavadocVariable"/> - - -

- To configure the check for public - scope: -

- - -<module name="JavadocVariable"> - <property name="scope" value="public"/> -</module> - - -

- To configure the check for members which are in private, but not in protected scope: -

- - -<module name="JavadocVariable"> - <property name="scope" value="private"/> - <property name="excludeScope" value="protected"/> -</module> - - -

- To ignore absence of Javadoc comments for variables with names log or logger: -

- - -<module name="JavadocVariable"> - <property name="ignoreNamePattern" value="log|logger"/> -</module> +<module name="JavadocPackage"/>
+ + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ Checker +

+
+
+ +
+ +

+ Checks that: +

+
    +
  • + There is one blank line between each of two paragraphs and one blank line before the at-clauses block if it is present. +
  • +
  • + Each paragraph but the first has <p> immediately before the first word, with no space after. +
  • +
+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowNewlineParagraphwhether the <p> tag should be placed immediately before the first wordBooleantrue
+
+ + +

+ Default configuration: +

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

+ To allows to place text of a paragraph not immediately after a <p> tag: +

+ +<module name="JavadocParagraph"> + <property name="allowNewlineParagraph" value="true"/> +</module> + +

+ In case of tagImmediatelyBeforeFirstWord set to false + the following example will not have any violations: +

+ +/** + * Some Javadoc. + * + * <p> + * Some Javadoc. + * + * <p> Some Javadoc. + * + * <p> + * <pre> + * Some preformatted Javadoc. + * </pre> + * + */ + +
+ + + @@ -851,6 +757,544 @@ public boolean isSomething()
+
+ +

+ Checks the indentation of the continuation lines in at-clauses. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
offsetHow many spaces to use for new indentation level.Integer4
+
+ + +

+ Default configuration +

+ +<module name="JavadocTagContinuationIndentation"> + <property name="offset" value="4"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks Javadoc comments for class and interface definitions. + By default, does not check for author or version tags. The + scope to verify is specified using the Scope + class and defaults to Scope.PRIVATE. To verify + another scope, set property scope to one of the + Scope constants. To define the format for an + author tag or a version tag, set property authorFormat or + versionFormat respectively to a + + regular expression. +

+

+ Does not perform checks for author and version tags for inner + classes, as they should be redundant because of outer class. +

+

+ Error messages about type parameters for which no param tags are + present can be suppressed by defining property + allowMissingParamTags. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
scopevisibility scope where Javadoc comments are checkedscopeprivate
excludeScopevisibility scope where Javadoc comments are not checkedscopenull
authorFormatpattern for @author tagregular expressionnull (tag not required)
versionFormatpattern for @version tagregular expressionnull (tag not required)
allowMissingParamTagswhether to ignore errors when a class has type parameters + but does not have matching param tags in the javadoc.booleanfalse
allowUnknownTagswhether to ignore errors when a Javadoc tag is not recognised.booleanfalse
tokenstokens to check + subset of tokens + INTERFACE_DEF, + CLASS_DEF, + ENUM_DEF, + ANNOTATION_DEF. + + INTERFACE_DEF, + CLASS_DEF, + ENUM_DEF, + ANNOTATION_DEF. +
+
+ + +

+ To configure the default check: +

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

+ To configure the check for public scope: +

+ +<module name="JavadocType"> + <property name="scope" value="public"/> +</module> + + +

+ To configure the check for an @author tag: +

+ +<module name="JavadocType"> + <property name="authorFormat" value="\S"/> +</module> + + +

+ To configure the check for a CVS revision version tag: +

+ +<module name="JavadocType"> + <property name="versionFormat" value="\$Revision.*\$"/> +</module> + + +

+ To configure the check for private classes only: +

+ +<module name="JavadocType"> + <property name="scope" value="private"/> + <property name="excludeScope" value="package"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that variables have Javadoc comments. Ignores serialVersionUID + fields. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
scopevisibility scope where Javadoc comments are checkedscopeprivate
excludeScopevisibility scope where Javadoc comments are not checkedscopenull
ignoreNamePatternregexp to define variable names to ignoreregular expressionnull
tokenstokens to checksubset of tokens + ENUM_CONSTANT_DEF. + + ENUM_CONSTANT_DEF. +
+
+ + +

+ To configure the default check: +

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

+ To configure the check for public + scope: +

+ + +<module name="JavadocVariable"> + <property name="scope" value="public"/> +</module> + + +

+ To configure the check for members which are in private, but not in protected scope: +

+ + +<module name="JavadocVariable"> + <property name="scope" value="private"/> + <property name="excludeScope" value="protected"/> +</module> + + +

+ To ignore absence of Javadoc comments for variables with names log or logger: +

+ + +<module name="JavadocVariable"> + <property name="ignoreNamePattern" value="log|logger"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that the at-clause tag is followed by description. +

+
+ + +

+ Default configuration that will check @param, @return, + @throws, @deprecated: +

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

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that a JavaDoc block can fit in a single line and doesn't + contain at-clauses. Javadoc comment that contains at least one at-clause + should be formatted in a few lines. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
ignoredTagsallows to specify at-clauses which are ignored by the check.Stringnull
ignoreInlineTagswhether inline tags must be ignored.Booleantrue
+
+ + +

+ Default configuration: +

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

+ To specify a list of ignored at-clauses and make inline at-clauses not ignored: +

+ +<module name="SingleLineJavadoc"> + <property name="ignoredTags" value="@inheritDoc, @see"/> + <property name="ignoreInlineTags" value="false"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that + Javadoc summary sentence does not contain phrases that are not recommended to use. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
forbiddenSummaryFragmentsforbidden summary fragmentsregular expression^$
periodperiod symbol at the end of first javadoc sentenceString literal.
+
+ + +

+ By default Check validate that first sentence is not empty: +

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

+ To ensure that summary do not contain phrase like "This method returns" , use following config: +

+ +<module name="SummaryJavadocCheck"> + <property name="forbiddenSummaryFragments" value="^This method returns.*"/> +</module> + +

+ To specify period symbol at the end of first javadoc sentence: +

+ +<module name="SummaryJavadocCheck"> + <property name="period" value="STRING_LITERAL"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.javadoc +

+
+ + +

+ TreeWalker +

+
+
+

@@ -962,450 +1406,6 @@ public boolean isSomething()

-
- -

- Checks that the at-clause tag is followed by description. -

-
- - -

- Default configuration that will check @param, @return, - @throws, @deprecated: -

- -<module name="NonEmptyAtclauseDescription"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks the indentation of the continuation lines in at-clauses. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
offsetHow many spaces to use for new indentation level.Integer4
-
- - -

- Default configuration -

- -<module name="JavadocTagContinuationIndentation"> - <property name="offset" value="4"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that - Javadoc summary sentence does not contain phrases that are not recommended to use. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
forbiddenSummaryFragmentsforbidden summary fragmentsregular expression^$
periodperiod symbol at the end of first javadoc sentenceString literal.
-
- - -

- By default Check validate that first sentence is not empty: -

- -<module name="SummaryJavadocCheck"/> - -

- To ensure that summary do not contain phrase like "This method returns" , use following config: -

- -<module name="SummaryJavadocCheck"> - <property name="forbiddenSummaryFragments" value="^This method returns.*"/> -</module> - -

- To specify period symbol at the end of first javadoc sentence: -

- -<module name="SummaryJavadocCheck"> - <property name="period" value="STRING_LITERAL"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks the order of at-clauses. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
targetallows to specify targets to check at-clauses.subset of tokens - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF. - - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF. -
tagOrderallows to specify the order by tags.String@author, @version, @param, - @return, @throws, @exception, @see, @since, @serial, - @serialField, @serialData, @deprecated
-
- - -

- Default configuration -

- -<module name="AtclauseOrder"> - <property name="tagOrder" value="@author, @version, @param, - @return, @throws, @exception, @see, @since, @serial, - @serialField, @serialData, @deprecated"/> - <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, - METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that: -

-
    -
  • - There is one blank line between each of two paragraphs and one blank line before the at-clauses block if it is present. -
  • -
  • - Each paragraph but the first has <p> immediately before the first word, with no space after. -
  • -
-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowNewlineParagraphwhether the <p> tag should be placed immediately before the first wordBooleantrue
-
- - -

- Default configuration: -

- -<module name="JavadocParagraph"/> - -

- To allows to place text of a paragraph not immediately after a <p> tag: -

- -<module name="JavadocParagraph"> - <property name="allowNewlineParagraph" value="true"/> -</module> - -

- In case of tagImmediatelyBeforeFirstWord set to false - the following example will not have any violations: -

- -/** - * Some Javadoc. - * - * <p> - * Some Javadoc. - * - * <p> Some Javadoc. - * - * <p> - * <pre> - * Some preformatted Javadoc. - * </pre> - * - */ - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that a JavaDoc block can fit in a single line and doesn't - contain at-clauses. Javadoc comment that contains at least one at-clause - should be formatted in a few lines. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
ignoredTagsallows to specify at-clauses which are ignored by the check.Stringnull
ignoreInlineTagswhether inline tags must be ignored.Booleantrue
-
- - -

- Default configuration: -

- -<module name="SingleLineJavadoc"/> - -

- To specify a list of ignored at-clauses and make inline at-clauses not ignored: -

- -<module name="SingleLineJavadoc"> - <property name="ignoredTags" value="@inheritDoc, @see"/> - <property name="ignoreInlineTags" value="false"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.javadoc -

-
- - -

- TreeWalker -

-
-
- diff --git a/src/xdocs/config_metrics.xml b/src/xdocs/config_metrics.xml index 6f8b90ea7..e8e29fb3b 100644 --- a/src/xdocs/config_metrics.xml +++ b/src/xdocs/config_metrics.xml @@ -503,6 +503,113 @@ class SwitchExample {
+
+ +

+ Determines complexity of methods, classes and files by + counting the Non Commenting Source Statements (NCSS). This + check adheres to the + specification for the + JavaNCSS-Tool + written by Chr. Clemens Lee.
+ Roughly said the NCSS metric is calculated by + counting the source lines which are not comments, (nearly) + equivalent to counting the semicolons and opening curly + braces.
The NCSS for a class is summarized from the NCSS + of all its methods, the NCSS of its nested classes and the + number of member variable declarations.
The NCSS for a + file is summarized from the ncss of all its top level classes, + the number of imports and the package declaration. +

+ +

+ Rationale: Too large methods and classes are hard to read and + costly to maintain. A large NCSS number often means that a + method or class has too many responsibilities and/or + functionalities which should be decomposed into smaller units. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
methodMaximum + the maximum allowed number of non commenting lines in a + method. + integer50
classMaximum + the maximum allowed number of non commenting lines in a + class. + integer1500
fileMaximum + the maximum allowed number of non commenting lines in a + file including all top level and nested classes. + integer2000
+
+ + +

+ To configure the check: +

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

+ To configure the check with 40 allowed non commenting lines + for a method: +

+ +<module name="JavaNCSS"> + <property name="methodMaximum" value="40"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.metrics +

+
+ + +

+ TreeWalker +

+
+
+

@@ -662,112 +769,5 @@ class SwitchExample {

- -
- -

- Determines complexity of methods, classes and files by - counting the Non Commenting Source Statements (NCSS). This - check adheres to the - specification for the - JavaNCSS-Tool - written by Chr. Clemens Lee.
- Roughly said the NCSS metric is calculated by - counting the source lines which are not comments, (nearly) - equivalent to counting the semicolons and opening curly - braces.
The NCSS for a class is summarized from the NCSS - of all its methods, the NCSS of its nested classes and the - number of member variable declarations.
The NCSS for a - file is summarized from the ncss of all its top level classes, - the number of imports and the package declaration. -

- -

- Rationale: Too large methods and classes are hard to read and - costly to maintain. A large NCSS number often means that a - method or class has too many responsibilities and/or - functionalities which should be decomposed into smaller units. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
methodMaximum - the maximum allowed number of non commenting lines in a - method. - integer50
classMaximum - the maximum allowed number of non commenting lines in a - class. - integer1500
fileMaximum - the maximum allowed number of non commenting lines in a - file including all top level and nested classes. - integer2000
-
- - -

- To configure the check: -

- -<module name="JavaNCSS"/> - - -

- To configure the check with 40 allowed non commenting lines - for a method: -

- -<module name="JavaNCSS"> - <property name="methodMaximum" value="40"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.metrics -

-
- - -

- TreeWalker -

-
-
diff --git a/src/xdocs/config_misc.xml b/src/xdocs/config_misc.xml index abe61f2d9..618eddc4e 100755 --- a/src/xdocs/config_misc.xml +++ b/src/xdocs/config_misc.xml @@ -21,17 +21,12 @@
-
+

- Checks whether files end with a line separator. -

- -

- Rationale: Any source files and text files in general should - end with a line separator, especially when using source control management - systems such as CVS. CVS will even print a warning when it - encounters a file that doesn't end with a line separator. + Checks the style of array type definitions. Some like Java style: + public static void main(String[] args) and some like + C style: public static void main(String args[])

@@ -44,60 +39,46 @@ default value - lineSeparator - type of line separator + javaStyle - One of "system" (system default), - "crlf" (Windows-style), "cr" - (Mac-style), "lf" (Unix-style) and "lf_cr_crlf" (lf, cr or crlf). + Controls whether to enforce Java style (true) or C style (false). - "system" + Boolean + true - - fileExtensions - file type extension of the files to check. - String Set - all files - -

- To configure the check: + To configure the check to enforce Java style:

-<module name="NewlineAtEndOfFile"/> +<module name="ArrayTypeStyle"/>

- To configure the check to always use Unix-style line separators: + To configure the check to enforce C style:

-<module name="NewlineAtEndOfFile"> - <property name="lineSeparator" value="lf"/> +<module name="ArrayTypeStyle"> + <property name="javaStyle" value="false"/> </module> - -

- To configure the check to work only on Java, XML and Python files: -

- -<module name="NewlineAtEndOfFile"> - <property name="fileExtensions" value="java, xml, py"/> -</module> -
@@ -111,23 +92,25 @@

- Checker + TreeWalker

-
+

- A check for TODO: comments. Actually - it is a generic regular - expression matcher on Java comments. To check for other - patterns in Java comments, set the format property. + Restrict using + Unicode escapes (e.g. \u221e). + It is possible to allow using escapes for + non-printable(control) characters. + Also, this check can be configured to allow using escapes + if trail comment is present. By the option it is possible to + allow using escapes if literal contains only them.

- + @@ -136,37 +119,97 @@ - - - - + + + + + + + + + + + + + + + + + + + + + +
namedefault value
formatPattern to match comments againstregular expressionTODO:allowEscapesForControlCharactersAllow use escapes for non-printable(control) characters.Booleanfalse
allowByTailCommentAllow use escapes if trail comment is present.Booleanfalse
allowIfAllCharactersEscapedAllow if all characters in literal are escaped.Booleanfalse
allowNonPrintableEscapesAllow non-printable escapes.Booleanfalse
- -

- Using TODO: comments is a great way - to keep track of tasks that need to be done. Having them - reported by Checkstyle makes it very hard to forget about - them. -

-
- -

- To configure the check: +

+ Examples of using Unicode:

-<module name="TodoComment"/> +String unitAbbrev = "μs"; //Best: perfectly clear even without a comment. +String unitAbbrev = "\u03bcs"; //Poor: the reader has no idea what this is. -

- To configure the check for comments that contain TODO and FIXME: + An example of how to configure the check is:

-<module name="TodoComment"> - <property name="format" value="(TODO)|(FIXME)"/> +<module name="AvoidEscapedUnicodeCharacters"/> + +

+ An example of non-printable(control) characters. +

+ +return '\ufeff' + content; // byte order mark + +

+ An example of how to configure the check to allow using escapes + for non-printable(control) characters: +

+ +<module name="AvoidEscapedUnicodeCharacters"> + <property name="allowEscapesForControlCharacters" value="true"/> +</module> + +

+ Example of using escapes with trail comment: +

+ +String unitAbbrev = "\u03bcs"; // Greek letter mu, "s" + +

+ An example of how to configure the check to allow using escapes + if trail comment is present: +

+ +<module name="AvoidEscapedUnicodeCharacters"> + <property name="allowByTailComment" value="true"/> +</module> + +

+ Example of using escapes if literal contains only them: +

+ +String unitAbbrev = "\u03bc\u03bc\u03bc"; + +

+ An example of how to configure the check to allow escapes + if literal contains only them: +

+ +<module name="AvoidEscapedUnicodeCharacters"> + <property name="allowIfAllCharactersEscaped" value="true"/> +</module> + +

+ An example of how to configure the check to allow non-printable escapes: +

+ +<module name="AvoidEscapedUnicodeCharacters"> + <property name="allowNonPrintableEscapes" value="true"/> </module>
@@ -174,11 +217,11 @@ @@ -426,448 +469,6 @@
-
- -

- A FileSetCheck that ensures - the correct translation of code by checking property files for - consistency regarding their keys. Two property files - describing one and the same context are consistent if they - contain the same keys. -

- -

- Consider the following properties file in the same directory: -

- -#messages.properties -hello=Hello -cancel=Cancel - -#messages_de.properties -hell=Hallo -ok=OK - - -

- The Translation check will find the typo in the German hello - key, the missing ok key in the default resource file and the - missing cancel key in the German resource file: -

- -messages_de.properties: Key 'hello' missing. -messages_de.properties: Key 'cancel' missing. -messages.properties: Key 'hell' missing. -messages.properties: Key 'ok' missing. - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
fileExtensions - file type extension to identify translation files. Setting - this property is typically only required if your - translation files are preprocessed and the original files - do not have the extension .properties - String Setproperties
basenameSeparatorAllows setting file names separatorString_
requiredTranslations - Allows to specify language codes of required translations which must exist in project. - The check looks only for messages bundles which names contain the word 'messages'. - Language code is composed of the lowercase, two-letter codes as defined by - ISO 639-1. - Default value is empty String Set which means that only the existence - of default translation is checked. - Note, if you specify language codes (or just one language code) of required translations - the check will also check for existence of default translation files in project. - String Setempty String Set
-
- - -

- To configure the check for files with '_' name separator: -

- -<module name="Translation"/> - - -

- To configure the check for files with user-set name separator: -

- -<module name="Translation"> - <property name="basenameSeparator" value="STRING_LITERAL"/> -</module> - - -

- To configure the check to check existence of Japanese and French translations: -

- -<module name="Translation"> -<property name="requiredTranslations" value="ja, fr"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- Checker -

-
-
- -
- -

- Checks for uncommented main() methods. -

- -

- Rationale: A main() method is often used for debugging - purposes. When debugging is finished, developers often forget - to remove the method, which changes the API and increases the - size of the resulting class or JAR file. With the exception of - the real program entry points, all main() methods should be - removed or commented out of the sources. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
excludedClassesPattern for qualified names of classes which are allowed - to have a main method.regular expression^$
-
- - -

- To configure the check: -

- -<module name="UncommentedMain"/> - - -

- To configure the check to allow the main method for all classes - with "Main" name: -

- -<module name="UncommentedMain"> - <property name="excludedClasses" value="\.Main$"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks that long constants are defined with an upper ell. That - is ' L' and not 'l'. This is in accordance with the Java - Language Specification, - Section 3.10.1. -

- -

- The capital L looks a lot like 1. -

-
- - -

- To configure the check: -

- -<module name="UpperEll"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks the style of array type definitions. Some like Java style: - public static void main(String[] args) and some like - C style: public static void main(String args[]) -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
javaStyle - Controls whether to enforce Java style (true) or C style (false). - Booleantrue
-
- - -

- To configure the check to enforce Java style: -

- -<module name="ArrayTypeStyle"/> - - -

- To configure the check to enforce C style: -

- -<module name="ArrayTypeStyle"> - <property name="javaStyle" value="false"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- TreeWalker -

-
-
- -
- -

- Check that parameters for methods, constructors, and catch blocks are - final. Interface and abstract methods are not checked: the final - keyword does not make sense for interface and abstract method - parameters as there is no code that could modify the parameter. -

- -

- Rationale: Changing the value of parameters during the execution of - the method's algorithm can be confusing and should be avoided. A - great way to let the Java compiler prevent this coding style is to - declare parameters final. -

-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
ignorePrimitiveTypesignore primitive types as parametersBooleanfalse
tokenstokens to check - subset of tokens - METHOD_DEF, - CTOR_DEF, - LITERAL_CATCH, - FOR_EACH_CLAUSE. - - METHOD_DEF, - CTOR_DEF. -
-
- - -

- To configure the check to enforce final parameters for methods and - constructors: -

- -<module name="FinalParameters"/> - - -

- To configure the check to enforce final parameters only for - constructors: -

- -<module name="FinalParameters"> - <property name="tokens" value="CTOR_DEF"/> -</module> - -

- To configure the check to allow ignoring - - primitive datatypes as parameters: -

- -<module name="FinalParameters"> - <property name="ignorePrimitiveTypes" value="true"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- TreeWalker -

-
-
-

@@ -1152,6 +753,152 @@ messages.properties: Key 'ok' missing.

+
+ +

+ Holds the current file contents for global access when configured + as a TreeWalker sub-module. For example,a filter can access + the current file contents through this module. +

+
+ + +

+ This check should not be used by itself, as it does no reporting. + It is to be used in conjuction with other checks like + SuppressionCommentFilter + and + SuppressWithNearbyCommentFilter. +

+
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Check that parameters for methods, constructors, and catch blocks are + final. Interface and abstract methods are not checked: the final + keyword does not make sense for interface and abstract method + parameters as there is no code that could modify the parameter. +

+ +

+ Rationale: Changing the value of parameters during the execution of + the method's algorithm can be confusing and should be avoided. A + great way to let the Java compiler prevent this coding style is to + declare parameters final. +

+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
ignorePrimitiveTypesignore primitive types as parametersBooleanfalse
tokenstokens to check + subset of tokens + METHOD_DEF, + CTOR_DEF, + LITERAL_CATCH, + FOR_EACH_CLAUSE. + + METHOD_DEF, + CTOR_DEF. +
+
+ + +

+ To configure the check to enforce final parameters for methods and + constructors: +

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

+ To configure the check to enforce final parameters only for + constructors: +

+ +<module name="FinalParameters"> + <property name="tokens" value="CTOR_DEF"/> +</module> + +

+ To configure the check to allow ignoring + + primitive datatypes as parameters: +

+ +<module name="FinalParameters"> + <property name="ignorePrimitiveTypes" value="true"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ TreeWalker +

+
+
+

@@ -1290,6 +1037,226 @@ void foo(String aFooString,

+
+ +

+ Checks whether files end with a line separator. +

+ +

+ Rationale: Any source files and text files in general should + end with a line separator, especially when using source control management + systems such as CVS. CVS will even print a warning when it + encounters a file that doesn't end with a line separator. +

+
+ + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
lineSeparatortype of line separator + One of "system" (system default), + "crlf" (Windows-style), "cr" + (Mac-style), "lf" (Unix-style) and "lf_cr_crlf" (lf, cr or crlf). + "system"
fileExtensionsfile type extension of the files to check.String Setall files
+
+ + +

+ To configure the check: +

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

+ To configure the check to always use Unix-style line separators: +

+ +<module name="NewlineAtEndOfFile"> + <property name="lineSeparator" value="lf"/> +</module> + + +

+ To configure the check to work only on Java, XML and Python files: +

+ +<module name="NewlineAtEndOfFile"> + <property name="fileExtensions" value="java, xml, py"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ Checker +

+
+
+ +
+ +

+ Checks that the outer type name and the file name match. For example, + the class Foo must be in a file named + Foo.java. +

+
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ A check for TODO: comments. Actually + it is a generic regular + expression matcher on Java comments. To check for other + patterns in Java comments, set the format property. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatPattern to match comments againstregular expressionTODO:
+
+ + +

+ Using TODO: comments is a great way + to keep track of tasks that need to be done. Having them + reported by Checkstyle makes it very hard to forget about + them. +

+
+ + +

+ To configure the check: +

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

+ To configure the check for comments that contain TODO and FIXME: +

+ +<module name="TodoComment"> + <property name="format" value="(TODO)|(FIXME)"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ TreeWalker +

+
+
+

@@ -1419,13 +1386,170 @@ d = e / f; // Another comment for this line

-
+

- Checks that the outer type name and the file name match. For example, - the class Foo must be in a file named - Foo.java. + A FileSetCheck that ensures + the correct translation of code by checking property files for + consistency regarding their keys. Two property files + describing one and the same context are consistent if they + contain the same keys.

+ +

+ Consider the following properties file in the same directory: +

+ +#messages.properties +hello=Hello +cancel=Cancel + +#messages_de.properties +hell=Hallo +ok=OK + + +

+ The Translation check will find the typo in the German hello + key, the missing ok key in the default resource file and the + missing cancel key in the German resource file: +

+ +messages_de.properties: Key 'hello' missing. +messages_de.properties: Key 'cancel' missing. +messages.properties: Key 'hell' missing. +messages.properties: Key 'ok' missing. + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
fileExtensions + file type extension to identify translation files. Setting + this property is typically only required if your + translation files are preprocessed and the original files + do not have the extension .properties + String Setproperties
basenameSeparatorAllows setting file names separatorString_
requiredTranslations + Allows to specify language codes of required translations which must exist in project. + The check looks only for messages bundles which names contain the word 'messages'. + Language code is composed of the lowercase, two-letter codes as defined by + ISO 639-1. + Default value is empty String Set which means that only the existence + of default translation is checked. + Note, if you specify language codes (or just one language code) of required translations + the check will also check for existence of default translation files in project. + String Setempty String Set
+
+ + +

+ To configure the check for files with '_' name separator: +

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

+ To configure the check for files with user-set name separator: +

+ +<module name="Translation"> + <property name="basenameSeparator" value="STRING_LITERAL"/> +</module> + + +

+ To configure the check to check existence of Japanese and French translations: +

+ +<module name="Translation"> +<property name="requiredTranslations" value="ja, fr"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks +

+
+ + +

+ Checker +

+
+
+ +
+ +

+ Checks for uncommented main() methods. +

+ +

+ Rationale: A main() method is often used for debugging + purposes. When debugging is finished, developers often forget + to remove the method, which changes the API and increases the + size of the resulting class or JAR file. With the exception of + the real program entry points, all main() methods should be + removed or commented out of the sources. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
excludedClassesPattern for qualified names of classes which are allowed + to have a main method.regular expression^$
@@ -1433,18 +1557,24 @@ d = e / f; // Another comment for this line To configure the check:

-<module name="OuterTypeFilename"/> +<module name="UncommentedMain"/> + + +

+ To configure the check to allow the main method for all classes + with "Main" name: +

+ +<module name="UncommentedMain"> + <property name="excludedClasses" value="\.Main$"/> +</module>
@@ -1527,131 +1657,42 @@ d = e / f; // Another comment for this line
-
+

- Restrict using - Unicode escapes (e.g. \u221e). - It is possible to allow using escapes for - non-printable(control) characters. - Also, this check can be configured to allow using escapes - if trail comment is present. By the option it is possible to - allow using escapes if literal contains only them. + Checks that long constants are defined with an upper ell. That + is ' L' and not 'l'. This is in accordance with the Java + Language Specification, + Section 3.10.1.

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowEscapesForControlCharactersAllow use escapes for non-printable(control) characters.Booleanfalse
allowByTailCommentAllow use escapes if trail comment is present.Booleanfalse
allowIfAllCharactersEscapedAllow if all characters in literal are escaped.Booleanfalse
allowNonPrintableEscapesAllow non-printable escapes.Booleanfalse
+

+ The capital L looks a lot like 1. +

-

- Examples of using Unicode: -

- -String unitAbbrev = "μs"; //Best: perfectly clear even without a comment. -String unitAbbrev = "\u03bcs"; //Poor: the reader has no idea what this is. -

- An example of how to configure the check is: + To configure the check:

-<module name="AvoidEscapedUnicodeCharacters"/> - -

- An example of non-printable(control) characters. -

- -return '\ufeff' + content; // byte order mark - -

- An example of how to configure the check to allow using escapes - for non-printable(control) characters: -

- -<module name="AvoidEscapedUnicodeCharacters"> - <property name="allowEscapesForControlCharacters" value="true"/> -</module> - -

- Example of using escapes with trail comment: -

- -String unitAbbrev = "\u03bcs"; // Greek letter mu, "s" - -

- An example of how to configure the check to allow using escapes - if trail comment is present: -

- -<module name="AvoidEscapedUnicodeCharacters"> - <property name="allowByTailComment" value="true"/> -</module> - -

- Example of using escapes if literal contains only them: -

- -String unitAbbrev = "\u03bc\u03bc\u03bc"; - -

- An example of how to configure the check to allow escapes - if literal contains only them: -

- -<module name="AvoidEscapedUnicodeCharacters"> - <property name="allowIfAllCharactersEscaped" value="true"/> -</module> - -

- An example of how to configure the check to allow non-printable escapes: -

- -<module name="AvoidEscapedUnicodeCharacters"> - <property name="allowNonPrintableEscapes" value="true"/> -</module> +<module name="UpperEll"/>
@@ -1669,46 +1710,5 @@ String unitAbbrev = "\u03bc\u03bc\u03bc";

- -
- -

- Holds the current file contents for global access when configured - as a TreeWalker sub-module. For example,a filter can access - the current file contents through this module. -

-
- - -

- This check should not be used by itself, as it does no reporting. - It is to be used in conjuction with other checks like - SuppressionCommentFilter - and - SuppressWithNearbyCommentFilter. -

-
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks -

-
- - -

- TreeWalker -

-
-
diff --git a/src/xdocs/config_regexp.xml b/src/xdocs/config_regexp.xml index d0397481b..5483b48da 100644 --- a/src/xdocs/config_regexp.xml +++ b/src/xdocs/config_regexp.xml @@ -459,6 +459,105 @@
+
+ +

+ A check for detecting that matches across multiple lines. + Works with any file type. +

+ +

+ Rationale: This check can be used to when the regular + expression can be span multiple lines. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
formatillegal patternregular expression^$ (empty)
messagemessage which is used to notify about violations, + if empty then default(hard-coded) message is used.String""(empty)
ignoreCaseControls whether to ignore case when searching.Booleanfalse
minimumThe minimum number of matches required in each file.Integer0
maximumThe maximum number of matches required in each file.Integer0
fileExtensionsfile type extension of files to processString Set{}
+
+ + +

+ To configure the check to find calls to print to the console: +

+ +<module name="RegexpMultiline"> + <property name="format" + value="System\.(out)|(err)\.print(ln)?\("/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.regexp +

+
+ + +

+ Checker +

+
+
+

@@ -591,105 +690,6 @@

-
- -

- A check for detecting that matches across multiple lines. - Works with any file type. -

- -

- Rationale: This check can be used to when the regular - expression can be span multiple lines. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
formatillegal patternregular expression^$ (empty)
messagemessage which is used to notify about violations, - if empty then default(hard-coded) message is used.String""(empty)
ignoreCaseControls whether to ignore case when searching.Booleanfalse
minimumThe minimum number of matches required in each file.Integer0
maximumThe maximum number of matches required in each file.Integer0
fileExtensionsfile type extension of files to processString Set{}
-
- - -

- To configure the check to find calls to print to the console: -

- -<module name="RegexpMultiline"> - <property name="format" - value="System\.(out)|(err)\.print(ln)?\("/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.regexp -

-
- - -

- Checker -

-
-
-

diff --git a/src/xdocs/config_sizes.xml b/src/xdocs/config_sizes.xml index 9936f6ed0..33337bc9d 100644 --- a/src/xdocs/config_sizes.xml +++ b/src/xdocs/config_sizes.xml @@ -21,6 +21,71 @@

+
+ +

+ Checks for long anonymous inner classes. +

+ +

+ Rationale: If an anonymous inner class becomes very long it is hard + to understand and to see the flow of the method where the class is + defined. Therefore long anonymous inner classes should usually be + refactored into a named inner class. See also Bloch, Effective + Java, p. 93. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
maxmaximum allowable number of linesinteger20
+
+ + +

+ To configure the check to accept files with up to 60 lines: +

+ +<module name="AnonInnerLength"> + <property name="max" value="60"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.sizes +

+
+ + +

+ TreeWalker +

+
+
+

@@ -281,6 +346,118 @@

+
+ +

+ Checks the number of methods declared in each type. This + includes the number of each scope (private, + package, protected and + public) as well as an overall total. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
maxTotalmaximum allowable number of methods at all scope levelsinteger100
maxPrivatemaximum allowable number of private methodsinteger100
maxPackagemaximum allowable number of package methodsinteger100
maxProtectedmaximum allowable number of protected methodsinteger100
maxPublicmaximum allowable number of public methodsinteger100
tokenstokens to check + subset of tokens + CLASS_DEF, + ENUM_CONSTANT_DEF, + ENUM_DEF, + INTERFACE_DEF. + + CLASS_DEF, + ENUM_CONSTANT_DEF, + ENUM_DEF, + INTERFACE_DEF. +
+
+ + +

+ To configure the check with defaults: +

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

+ To configure the check to allow at most 30 methods per type: +

+ +<module name="MethodCount"> + <property name="maxTotal" value="30"/> +</module> + + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.sizes +

+
+ + +

+ TreeWalker +

+
+
+

@@ -396,18 +573,16 @@

-
+

- Checks for long anonymous inner classes. + Checks for the number of types declared at the outer + (or root) level in a file.

- Rationale: If an anonymous inner class becomes very long it is hard - to understand and to see the flow of the method where the class is - defined. Therefore long anonymous inner classes should usually be - refactored into a named inner class. See also Bloch, Effective - Java, p. 93. + Rationale: It is considered good practice to only define one outer + type per file.

@@ -421,28 +596,36 @@ max - maximum allowable number of lines + maximum allowable number of outer types integer - 20 + 1

- To configure the check to accept files with up to 60 lines: + To configure the check to accept 1 outer type per file:

-<module name="AnonInnerLength"> - <property name="max" value="60"/> +<module name="OuterTypeNumber"/> + + +

+ To configure the check to accept 2 outer types per file: +

+ +<module name="OuterTypeNumber"> + <property name="max" value="2"/> </module> +
@@ -576,188 +759,5 @@ public void needsLotsOfParameters(int a, int b, int c, int d, int e, int f, int
-
- -

- Checks for the number of types declared at the outer - (or root) level in a file. -

- -

- Rationale: It is considered good practice to only define one outer - type per file. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
maxmaximum allowable number of outer typesinteger1
-
- - -

- To configure the check to accept 1 outer type per file: -

- -<module name="OuterTypeNumber"/> - - -

- To configure the check to accept 2 outer types per file: -

- -<module name="OuterTypeNumber"> - <property name="max" value="2"/> -</module> - - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.sizes -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks the number of methods declared in each type. This - includes the number of each scope (private, - package, protected and - public) as well as an overall total. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
maxTotalmaximum allowable number of methods at all scope levelsinteger100
maxPrivatemaximum allowable number of private methodsinteger100
maxPackagemaximum allowable number of package methodsinteger100
maxProtectedmaximum allowable number of protected methodsinteger100
maxPublicmaximum allowable number of public methodsinteger100
tokenstokens to check - subset of tokens - CLASS_DEF, - ENUM_CONSTANT_DEF, - ENUM_DEF, - INTERFACE_DEF. - - CLASS_DEF, - ENUM_CONSTANT_DEF, - ENUM_DEF, - INTERFACE_DEF. -
-
- - -

- To configure the check with defaults: -

- -<module name="MethodCount"/> - - -

- To configure the check to allow at most 30 methods per type: -

- -<module name="MethodCount"> - <property name="maxTotal" value="30"/> -</module> - - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.sizes -

-
- - -

- TreeWalker -

-
-
- diff --git a/src/xdocs/config_whitespace.xml b/src/xdocs/config_whitespace.xml index 79e7c920a..623a07946 100644 --- a/src/xdocs/config_whitespace.xml +++ b/src/xdocs/config_whitespace.xml @@ -21,82 +21,6 @@
-
- -

- Checks that the whitespace around the Generic tokens (angle brackets) - "<" and ">" are correct to the typical convention. - The convention is not configurable. -

-

- Left angle bracket ("<"): -

-
    -
  • should be preceded with whitespace only in generic methods definitions.
  • -
  • should not be preceded with whitespace when it is precede method name or following type name.
  • -
  • should not be followed with whitespace in all cases.
  • -
-

- Right angle bracket (">"): -

-
    -
  • should not be preceded with whitespace in all cases.
  • -
  • should be followed with whitespace in almost all cases, except diamond operators and when preceding method name.
  • -
- -

- Examples with correct spacing: -

- -public void <K, V extends Number> boolean foo(K, V) {} // Generic methods definitions -class name<T1, T2, ..., Tn> {} // Generic type definition -OrderedPair<String, Box<Integer>> p; // Generic type reference -boolean same = Util.<Integer, String>compare(p1, p2); // Generic preceded method name -Pair<Integer, String> p1 = new Pair<>(1, "apple"); // Diamond operator -List<T> list = ImmutableList.Builder<T>::new; // Method reference -sort(list, Comparable::<String>compareTo); // Method reference - -
- - -

- To configure the check: -

- -<module name="GenericWhitespace"/> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.whitespace -

-
- - -

- TreeWalker -

-
-
-

@@ -247,6 +171,324 @@ for (Iterator foo = very.long.line.iterator();

+
+ +

+ Checks for empty line separators after header, package, all import declarations, + fields, constructors, methods, nested classes, + static initializers and instance initializers. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
allowNoEmptyLineBetweenFieldsAllow no empty line between fieldsbooleanfalse
allowMultipleEmptyLinesAllow multiple empty lines between class membersbooleantrue
tokenstokens to checksubset of tokens + PACKAGE_DEF, + IMPORT, + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + STATIC_INIT, + INSTANCE_INIT, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF. + + PACKAGE_DEF, + IMPORT, + CLASS_DEF, + INTERFACE_DEF, + ENUM_DEF, + STATIC_INIT, + INSTANCE_INIT, + METHOD_DEF, + CTOR_DEF, + VARIABLE_DEF. +
+
+ + +

+ Example of declarations without empty line separator: +

+ +/////////////////////////////////////////////////// +//HEADER +/////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.whitespace; +import java.io.Serializable; +class Foo +{ + public static final int FOO_CONST = 1; + public void foo() {} //should be separated from previous statement. +} + +

+ An example of how to configure the check with default parameters is: +

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

+ Example of declarations with empty line separator that is expected by the Check by default: +

+ +/////////////////////////////////////////////////// +//HEADER +/////////////////////////////////////////////////// + +package com.puppycrawl.tools.checkstyle.whitespace; + +import java.io.Serializable; + +class Foo +{ + public static final int FOO_CONST = 1; + + public void foo() {} //should be separated from previous statement. +} + +

+ An example how to check empty line after VARIABLE_DEF and METHOD_DEF: +

+ +<module name="EmptyLineSeparator"> + <property name="tokens" value="VARIABLE_DEF, METHOD_DEF"/> +</module> + +

+ An example how to allow no empty line between fields: +

+ +<module name="EmptyLineSeparator"> + <property name="allowNoEmptyLineBetweenFields" value="true"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.whitespace +

+
+ + +

+ TreeWalker +

+
+
+ +
+ +

+ Checks that there are no tab characters ('\t') in the source code. +

+ +

+ Rationale: +

+ +
    +
  • + Developers should not need to configure the tab width of their + text editors in order to be able to read source code. +
  • +
  • + From the Apache jakarta coding standards: In a distributed + development environment, when the commit messages get sent + to a mailing list, they are almost impossible to read if you + use tabs. +
  • +
+
+ + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
eachLinewhether to report on each line containing a tab, or just the first instancebooleanfalse
fileExtensionsfile type extension of files to processString Set{}
+
+ + +

+ To configure the check to report on the first instance in each + file: +

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

+ To configure the check to report on each line in each file: +

+ +<module name="FileTabCharacter"> + <property name="eachLine" value="true"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.whitespace +

+
+ + +

+ Checker +

+
+
+ +
+ +

+ Checks that the whitespace around the Generic tokens (angle brackets) + "<" and ">" are correct to the typical convention. + The convention is not configurable. +

+

+ Left angle bracket ("<"): +

+
    +
  • should be preceded with whitespace only in generic methods definitions.
  • +
  • should not be preceded with whitespace when it is precede method name or following type name.
  • +
  • should not be followed with whitespace in all cases.
  • +
+

+ Right angle bracket (">"): +

+
    +
  • should not be preceded with whitespace in all cases.
  • +
  • should be followed with whitespace in almost all cases, except diamond operators and when preceding method name.
  • +
+ +

+ Examples with correct spacing: +

+ +public void <K, V extends Number> boolean foo(K, V) {} // Generic methods definitions +class name<T1, T2, ..., Tn> {} // Generic type definition +OrderedPair<String, Box<Integer>> p; // Generic type reference +boolean same = Util.<Integer, String>compare(p1, p2); // Generic preceded method name +Pair<Integer, String> p1 = new Pair<>(1, "apple"); // Diamond operator +List<T> list = ImmutableList.Builder<T>::new; // Method reference +sort(list, Comparable::<String>compareTo); // Method reference + +
+ + +

+ To configure the check: +

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

+ com.puppycrawl.tools.checkstyle.checks.whitespace +

+
+ + +

+ TreeWalker +

+
+
+

@@ -372,6 +614,111 @@ for (Iterator foo = very.long.line.iterator();

+
+ +

+ Checks that chosen statements are not line-wrapped. By default this + Check restricts wrapping import and package statements, but it's possible to check + any statement. +

+
+ + + + + + + + + + + + + + + +
namedescriptiontypedefault value
tokenstokens to checksubset of tokens + IMPORT, + PACKAGE_DEF, + CLASS_DEF, + METHOD_DEF, + CTOR_DEF, + ENUM_DEF, + INTERFACE_DEF. + PACKAGE_DEF, + IMPORT.
+
+ + +

+ Examples of line-wrapped statements (bad case): +

+ +package com.puppycrawl. + tools.checkstyle.checks; + +import com.puppycrawl.tools. + checkstyle.api.Check; + +

+ To configure the check to force no line-wrapping + in package and import statements (default values): +

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

+ To configure the check to force no line-wrapping only + in import statements: +

+ +<module name="NoLineWrap"> + <property name="tokens" value="IMPORT"/> +</module> + +

+ Examples of not line-wrapped statements (good case): +

+ +import com.puppycrawl.tools.checkstyle.api.Check; + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.whitespace +

+
+ + +

+ TreeWalker +

+
+
+

@@ -915,6 +1262,126 @@ for (Iterator foo = very.long.line.iterator();

+
+ +

+ Checks line wrapping with separators. +

+
+ + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
optionpolicy on how to wrap lines + wrap operator policy + eol
tokenstokens to check + subset of tokens DOT, + COMMA, + SEMI, + ELLIPSIS, + AT, + LPAREN, + RPAREN, + ARRAY_DECLARATOR, + RBRACK. + + DOT, + COMMA. +
+
+ + +

+ Code example for comma and dot at the new line: +

+ +s + .isEmpty(); +foo(i + ,s); + +

+ An example of how to configure the check is: +

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

+ Code example for comma and dot at the previous line: +

+ +s. + isEmpty(); +foo(i, + s); + +

+ An example of how to configure the check for comma at the new line is: +

+ +<module name="SeparatorWrap"> + <property name="tokens" value="COMMA"/> + <property name="option" value="nl"/> +</module> + +
+ + + + + + +

+ com.puppycrawl.tools.checkstyle.checks.whitespace +

+
+ + +

+ TreeWalker +

+
+
+

@@ -985,101 +1452,6 @@ for (Iterator foo = very.long.line.iterator();

-
- -

- Checks that there are no tab characters ('\t') in the source code. -

- -

- Rationale: -

- -
    -
  • - Developers should not need to configure the tab width of their - text editors in order to be able to read source code. -
  • -
  • - From the Apache jakarta coding standards: In a distributed - development environment, when the commit messages get sent - to a mailing list, they are almost impossible to read if you - use tabs. -
  • -
-
- - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
eachLinewhether to report on each line containing a tab, or just the first instancebooleanfalse
fileExtensionsfile type extension of files to processString Set{}
-
- - -

- To configure the check to report on the first instance in each - file: -

- -<module name="FileTabCharacter"/> - -

- To configure the check to report on each line in each file: -

- -<module name="FileTabCharacter"> - <property name="eachLine" value="true"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.whitespace -

-
- - -

- Checker -

-
-
-

@@ -1394,376 +1766,5 @@ public @interface Beta {} // empty annotation type

-
- -

- Checks that chosen statements are not line-wrapped. By default this - Check restricts wrapping import and package statements, but it's possible to check - any statement. -

-
- - - - - - - - - - - - - - - -
namedescriptiontypedefault value
tokenstokens to checksubset of tokens - IMPORT, - PACKAGE_DEF, - CLASS_DEF, - METHOD_DEF, - CTOR_DEF, - ENUM_DEF, - INTERFACE_DEF. - PACKAGE_DEF, - IMPORT.
-
- - -

- Examples of line-wrapped statements (bad case): -

- -package com.puppycrawl. - tools.checkstyle.checks; - -import com.puppycrawl.tools. - checkstyle.api.Check; - -

- To configure the check to force no line-wrapping - in package and import statements (default values): -

- -<module name="NoLineWrap"/> - -

- To configure the check to force no line-wrapping only - in import statements: -

- -<module name="NoLineWrap"> - <property name="tokens" value="IMPORT"/> -</module> - -

- Examples of not line-wrapped statements (good case): -

- -import com.puppycrawl.tools.checkstyle.api.Check; - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.whitespace -

-
- - -

- TreeWalker -

-
-
-
- -

- Checks for empty line separators after header, package, all import declarations, - fields, constructors, methods, nested classes, - static initializers and instance initializers. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
allowNoEmptyLineBetweenFieldsAllow no empty line between fieldsbooleanfalse
allowMultipleEmptyLinesAllow multiple empty lines between class membersbooleantrue
tokenstokens to checksubset of tokens - PACKAGE_DEF, - IMPORT, - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - STATIC_INIT, - INSTANCE_INIT, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF. - - PACKAGE_DEF, - IMPORT, - CLASS_DEF, - INTERFACE_DEF, - ENUM_DEF, - STATIC_INIT, - INSTANCE_INIT, - METHOD_DEF, - CTOR_DEF, - VARIABLE_DEF. -
-
- - -

- Example of declarations without empty line separator: -

- -/////////////////////////////////////////////////// -//HEADER -/////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle.whitespace; -import java.io.Serializable; -class Foo -{ - public static final int FOO_CONST = 1; - public void foo() {} //should be separated from previous statement. -} - -

- An example of how to configure the check with default parameters is: -

- -<module name="EmptyLineSeparator"/> - -

- Example of declarations with empty line separator that is expected by the Check by default: -

- -/////////////////////////////////////////////////// -//HEADER -/////////////////////////////////////////////////// - -package com.puppycrawl.tools.checkstyle.whitespace; - -import java.io.Serializable; - -class Foo -{ - public static final int FOO_CONST = 1; - - public void foo() {} //should be separated from previous statement. -} - -

- An example how to check empty line after VARIABLE_DEF and METHOD_DEF: -

- -<module name="EmptyLineSeparator"> - <property name="tokens" value="VARIABLE_DEF, METHOD_DEF"/> -</module> - -

- An example how to allow no empty line between fields: -

- -<module name="EmptyLineSeparator"> - <property name="allowNoEmptyLineBetweenFields" value="true"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.whitespace -

-
- - -

- TreeWalker -

-
-
- -
- -

- Checks line wrapping with separators. -

-
- - - - - - - - - - - - - - - - - - - - - - - -
namedescriptiontypedefault value
optionpolicy on how to wrap lines - wrap operator policy - eol
tokenstokens to check - subset of tokens DOT, - COMMA, - SEMI, - ELLIPSIS, - AT, - LPAREN, - RPAREN, - ARRAY_DECLARATOR, - RBRACK. - - DOT, - COMMA. -
-
- - -

- Code example for comma and dot at the new line: -

- -s - .isEmpty(); -foo(i - ,s); - -

- An example of how to configure the check is: -

- -<module name="SeparatorWrap"/> - -

- Code example for comma and dot at the previous line: -

- -s. - isEmpty(); -foo(i, - s); - -

- An example of how to configure the check for comma at the new line is: -

- -<module name="SeparatorWrap"> - <property name="tokens" value="COMMA"/> - <property name="option" value="nl"/> -</module> - -
- - - - - - -

- com.puppycrawl.tools.checkstyle.checks.whitespace -

-
- - -

- TreeWalker -

-
-
-