From 13921e6e90aace1e8d0781aae3fc695fd762a2a6 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
- To not enforce an element style a {@code ElementStyleOption.IGNORE} type is provided.
- The desired style can be set through the {@code elementStyle} property.
+ To not enforce an element style a
- Using the {@code ElementStyleOption.EXPANDED} style is more verbose.
+ Using the
- Using the {@code ElementStyleOption.COMPACT} style is less verbose.
+ Using the
- Using the {@code ElementStyleOption.COMPACT_NO_ARRAY} style is less verbose.
- It is similar to the {@code ElementStyleOption.COMPACT} style but single value arrays are
+ Using the
The ending parenthesis are optional when using annotations with no elements.
- To always require ending parenthesis use the {@code ClosingParensOption.ALWAYS} type.
- To never have ending parenthesis use the {@code ClosingParensOption.NEVER} type.
- To not enforce a closing parenthesis preference a {@code ClosingParensOption.IGNORE} type is
+ To always require ending parenthesis use the
Annotations also allow you to specify arrays of elements in a standard format.
As with normal arrays, a trailing comma is optional.
- To always require a trailing comma use the {@code TrailingArrayCommaOption.ALWAYS} type.
- To never have a trailing comma use the {@code TrailingArrayCommaOption.NEVER} type.
- To not enforce a trailing array comma preference a {@code TrailingArrayCommaOption.IGNORE} type
- is provided. Set this through the {@code trailingArrayComma} property.
+ To always require a trailing comma use the
- By default, the {@code ElementStyleOption} is set to {@code },
- the {@code TrailingArrayCommaOption} is set to {@code },
- and the {@code ClosingParensOption} is set to {@code }.
+ By default, the
According to the JLS, it is legal to include a trailing comma
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperBeforeExecutionExclusionFileFilter.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperBeforeExecutionExclusionFileFilter.txt
index 6071f936a2f..f785893888d 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperBeforeExecutionExclusionFileFilter.txt
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperBeforeExecutionExclusionFileFilter.txt
@@ -5,7 +5,7 @@ FullQualifiedName: com.puppycrawl.tools.checkstyle.meta.javadocmetadatascraper.I
ocMetadataScraperBeforeExecutionExclusionFileFilter
Parent: com.puppycrawl.tools.checkstyle.Checker
Description:
- File filter {@code BeforeExecutionExclusionFileFilter} decides which files should be
+ File filter
checked for violations. Users could have files that are in these subdirectories that shouldn't
be processed with their checkstyle configuration for various reasons, one of which is a valid
Java file that won't pass Checkstyle's parser. When Checkstyle tries to parse a Java file and
- fails, it will throw an {@code Exception} and halt parsing any more files for violations.
- An example of a valid Java file Checkstyle can't parse is JDK 9's {@code module-info.java}.
+ fails, it will throw an
- Checks the placement of right curly braces ({@code '}'}) for code blocks. This check supports
- if-else, try-catch-finally blocks, while-loops, for-loops,
+ Checks the placement of right curly braces (
Checks that
Javadoc summary sentence does not contain phrases that are not recommended to use.
- Summaries that contain only the {@code {@inheritDoc}} tag are skipped.
+ Summaries that contain only the
- Filter {@code SuppressWarningsFilter} uses annotation
- {@code SuppressWarnings} to suppress audit events.
+ Filter
- Rationale: Same as for {@code SuppressionCommentFilter}. In the contrary to it here,
- comments are not used comments but the builtin syntax of {@code @SuppressWarnings}.
+ Rationale: Same as for
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
- {@code SuppressWarningsHolder} as a child module of the {@code TreeWalker}.
+
ElementStyleOption.COMPACT_NO_ARRAY
ElementStyleOption.COMPACT
ElementStyleOption.EXPANDED
ElementStyleOption.IGNORE
type is provided.
+ The desired style can be set through the elementStyle
property.
ElementStyleOption.EXPANDED
style is more verbose.
The expanded version is sometimes referred to as "named parameters" in other languages.
ElementStyleOption.COMPACT
style is less verbose.
This style can only be used when there is an element called 'value' which is either
the sole element or all other elements have default values.
ElementStyleOption.COMPACT_NO_ARRAY
style is less verbose.
+ It is similar to the ElementStyleOption.COMPACT
style but single value arrays are
flagged.
With annotations a single value array does not need to be placed in an array initializer.
ClosingParensOption.ALWAYS
type.
+ To never have ending parenthesis use the ClosingParensOption.NEVER
type.
+ To not enforce a closing parenthesis preference a ClosingParensOption.IGNORE
type is
provided.
- Set this through the {@code closingParens} property.
+ Set this through the closingParens
property.
TrailingArrayCommaOption.ALWAYS
type.
+ To never have a trailing comma use the TrailingArrayCommaOption.NEVER
type.
+ To not enforce a trailing array comma preference a TrailingArrayCommaOption.IGNORE
+ type is provided. Set this through the trailingArrayComma
property.
ElementStyleOption
is set to COMPACT_NO_ARRAY
,
+ the TrailingArrayCommaOption
is set to NEVER
,
+ and the ClosingParensOption
is set to NEVER
.
BeforeExecutionExclusionFileFilter
decides which files should be
excluded from being processed by the utility.
Exception
and halt parsing any more files for violations.
+ An example of a valid Java file Checkstyle can't parse is JDK 9's module-info.java
.
This file filter will exclude these problem files from being parsed, allowing the rest of the
files to run normal and be validated.
'}'
) for code blocks. This check
+ supports if-else, try-catch-finally blocks, while-loops, for-loops,
method definitions, class definitions, constructor definitions,
instance, static initialization blocks, annotation definitions and enum definitions.
For right curly brace of expression blocks of arrays, lambdas and class instances
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperSummaryJavadocCheck.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperSummaryJavadocCheck.txt
index dc910c40b74..4e963ddee4b 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperSummaryJavadocCheck.txt
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/ExpectedJavadocMetadataScraperSummaryJavadocCheck.txt
@@ -8,7 +8,7 @@ Description: {@inheritDoc}
tag are skipped.
Check also violate Javadoc that does not contain first sentence.
SuppressWarningsFilter
uses annotation
+ SuppressWarnings
to suppress audit events.
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.
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.
* By default, the {@code ElementStyleOption} is set to {@code COMPACT_NO_ARRAY}, diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/InputJavadocMetadataScraperRightCurlyCheck.java b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/InputJavadocMetadataScraperRightCurlyCheck.java index f3a350b6b52..10eb77c5da7 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/InputJavadocMetadataScraperRightCurlyCheck.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/meta/javadocmetadatascraper/InputJavadocMetadataScraperRightCurlyCheck.java @@ -21,8 +21,8 @@ /** *
- * Checks the placement of right curly braces ({@code '}'}) for code blocks. This check supports
- * if-else, try-catch-finally blocks, while-loops, for-loops,
+ * Checks the placement of right curly braces ( Code copied from
- *
- * ant
- *
- *
- * @param value The string to be scanned for property references. Must
- * not be {@code null}.
- * @param props Mapping (String to String) of property names to their
- * values. Must not be {@code null}.
- * @param defaultValue default to use if one of the properties in value
- * cannot be resolved from props.
- *
- * @return the original string with the properties replaced.
- * @throws CheckstyleException if the string contains an opening
- * {@code ${} without a closing
- * {@code }}
- */
- private static String replaceProperties(
- String value, PropertyResolver props, String defaultValue)
- throws CheckstyleException {
-
- final List Code copied from
- *
- * ant
- *
- *
- * @param value Text to parse. Must not be {@code null}.
- * @param fragments Collection to add text fragments to.
- * Must not be {@code null}.
- * @param propertyRefs Collection to add property names to.
- * Must not be {@code null}.
- *
- * @throws CheckstyleException if the string contains an opening
- * {@code ${} without a closing
- * {@code }}
- */
- private static void parsePropertyString(String value,
- Collection Code copied from
+ *
+ * ant
+ *
+ *
+ * @param value The string to be scanned for property references. Must
+ * not be {@code null}.
+ * @param defaultValue default to use if one of the properties in value
+ * cannot be resolved from props.
+ *
+ * @return the original string with the properties replaced.
+ * @throws CheckstyleException if the string contains an opening
+ * {@code ${} without a closing
+ * {@code }}
+ */
+ private String replaceProperties(
+ String value, String defaultValue)
+ throws CheckstyleException {
+
+ final List Code copied from
+ *
+ * ant
+ *
+ *
+ * @param value Text to parse. Must not be {@code null}.
+ * @param fragments Collection to add text fragments to.
+ * Must not be {@code null}.
+ * @param propertyRefs Collection to add property names to.
+ * Must not be {@code null}.
+ *
+ * @throws CheckstyleException if the string contains an opening
+ * {@code ${} without a closing
+ * {@code }}
+ */
+ private void parsePropertyString(String value,
+ Collection
* Example (the line with 'No newline at end of file' should not be in the diff):
*
* It can also trick the VCS to report the wrong owner for such lines.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
index 0ca9f9d687d..51aea4a4348 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
@@ -43,10 +43,10 @@
* comments are a bad practice. An end line comment would be one that is on
* the same line as actual code. For example:
*
* Quoting Code Complete for the justification:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
index cd5f58f4f41..af97fab05e0 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
@@ -44,9 +44,9 @@
* Attention: Annotations among modifiers are ignored (looks like false-negative)
* as there might be a problem with annotations for return types:
*
* Such annotations are better to keep close to type.
@@ -56,11 +56,11 @@
*
* Example:
*
* For example, this check finds the obsolete braces in
*
* and debugging / refactoring leftovers such as
*
* A case in a switch statement does not implicitly form a block.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/ArrayTrailingCommaCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/ArrayTrailingCommaCheck.java
index 2a4fabd5e3a..5fe39bcc907 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/ArrayTrailingCommaCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/ArrayTrailingCommaCheck.java
@@ -30,33 +30,33 @@
* Checks that array initialization contains a trailing comma.
*
*
- *
* By default, the check demands a comma at the end if neither left nor right curly braces
* are on the same line as the last element of the array.
*
* Rationale: Putting this comma in makes it easier to change the
* order of the elements or add new elements on the end. Main benefit of a trailing
* comma is that when you add new entry to an array, no surrounding lines are changed.
*
* If closing brace is on the same line as trailing comma, this benefit is gone
* (as the check does not demand a certain location of curly braces the following
* two cases will not produce a violation):
*
* If opening brace is on the same line as trailing comma there's also (more arguable) problem:
*
* Rationale: Some developers find inline conditionals hard to read, so
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java
index c90b2158c24..84c8e1dec0f 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java
@@ -63,9 +63,9 @@
* Programmers sometimes mistakenly use the type of their class {@code Foo}
* as the type of the parameter to {@code equals()}:
*
* This covariant version of {@code equals()} does not override the version in
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/DeclarationOrderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/DeclarationOrderCheck.java
index 8cc9e4a475c..93b99ee6d9d 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/DeclarationOrderCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/DeclarationOrderCheck.java
@@ -67,13 +67,13 @@
* forward references
* A method is recognized as a setter if it is in the following form
*
* where ${anyType} is any primitive type, class or interface name;
@@ -57,9 +57,9 @@
* capitalized form that appears in the method name. By default, it is expected
* that setter returns void, i.e. ${returnType} is 'void'. For example
*
* Any other return types will not let method match a setter pattern. However,
@@ -67,11 +67,11 @@
* definition of a setter is expanded, so that setter return type can also be
* a class in which setter is declared. For example
*
* Such methods are known as chain-setters and a common when Builder-pattern
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
index 1feb56e2b64..2cc9f69c799 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
@@ -60,11 +60,11 @@
* This helps to avoid ambiguous cases, e.g.: {@code java.awt.List} was set as
* illegal class name, then, code like:
*
* will be ok.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/InnerAssignmentCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/InnerAssignmentCheck.java
index 8501783fdd5..9eded8a644a 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/InnerAssignmentCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/InnerAssignmentCheck.java
@@ -44,7 +44,7 @@
*
* Note: Check allows usage of the popular assignments in loops:
*
* Assignment inside a condition is not a problem here, as the assignment is surrounded
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MagicNumberCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MagicNumberCheck.java
index f6fef5d2ca9..820cda0c5e0 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MagicNumberCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MagicNumberCheck.java
@@ -45,14 +45,14 @@
* Constant definition is any variable/field that has 'final' modifier.
* It is fine to have one constant defining multiple numeric literals within one expression:
*
* Rationale: If the control variable is modified inside the loop
@@ -55,21 +55,21 @@
*
* Such loop would be suppressed:
*
* NOTE:The check works with only primitive type variables.
* The check will not work for arrays used as control variable.An example is
*
* The check demands that there should not be any comma after the last element of an array.
*
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoCloneCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoCloneCheck.java
index 5003011785d..464c7c0df08 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoCloneCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoCloneCheck.java
@@ -103,29 +103,29 @@
* limitation of a copy constructor (or static factory). Assume
* Square is a subclass for Shape.
*
* ...assume at this point the code knows nothing of s1 being a Square
* that's the beauty of polymorphism but the code wants to copy
* the Square which is declared as a Shape, its super type...
*
* The working solution (without knowing about all subclasses and doing many
* casts) is to do the following (assuming correct clone implementation).
*
* Just keep in mind if this type of polymorphic cloning is required
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoEnumTrailingCommaCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoEnumTrailingCommaCheck.java
index 2d582bc9dd2..94dce498043 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoEnumTrailingCommaCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/NoEnumTrailingCommaCheck.java
@@ -32,23 +32,23 @@
* them in other locations. To unify the coding style, the use of trailing commas should
* be prohibited.
*
- *
* The check demands that there should not be any comma after last constant in
* enum definition.
*
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanReturnCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanReturnCheck.java
index 37572021c32..efac5d1fb4c 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanReturnCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanReturnCheck.java
@@ -30,19 +30,19 @@
* Checks for over-complicated boolean return or yield statements.
* For example the following code
*
- *
* could be written as
*
* The idea for this Check has been shamelessly stolen from the equivalent
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/StringLiteralEqualityCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/StringLiteralEqualityCheck.java
index dc05e711749..9f9062e77b0 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/StringLiteralEqualityCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/StringLiteralEqualityCheck.java
@@ -37,16 +37,16 @@
*
* Rationale: Novice Java programmers often use code like:
*
* when they mean
*
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java
index 382e4d3596e..6967e588c4e 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java
@@ -36,7 +36,7 @@
* Checks if unnecessary parentheses are used in a statement or expression.
* The check will flag the following with warnings:
*
- *
* The check is not "type aware", that is to say, it can't tell if parentheses
@@ -54,12 +54,13 @@
* operator precedence but unaware about operator associativity.
* It won't catch cases such as:
*
* In the first case, given that a, b, and c are
@@ -75,7 +76,7 @@
*
* The partial support for operator precedence includes cases of the following type:
*
* Example of code that cause violation as it is designed for extension:
*
* Example of code without violation:
*
* 1. patterns STANDARD_JAVA_PACKAGE = "Check", SPECIAL_IMPORTS="ImportOrderCheck" and input file:
*
* Result: imports will be assigned to SPECIAL_IMPORTS, because matching substring length is 16.
@@ -140,9 +140,9 @@
*
* 2. patterns STANDARD_JAVA_PACKAGE = "Check", SPECIAL_IMPORTS="Avoid" and file:
*
* Result: import will be assigned to SPECIAL_IMPORTS. Matching substring length is 5 for both
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java
index d2d91c57c15..67b2ce8ac06 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java
@@ -103,11 +103,11 @@
* 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:
*
* Example:
*
* The documentation generated will be just "Some text." without any asterisks.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java
index fe35ea019a8..eb1d863fded 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java
@@ -101,12 +101,12 @@
* For example, if the following method is implementing a method required by
* an interface, then the Javadoc could be done as:
*
* Rationale for this check: Nested enums, interfaces, and records are treated differently from
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/InterfaceMemberImpliedModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/InterfaceMemberImpliedModifierCheck.java
index 8dfd0a267b3..fcffa7c1129 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/InterfaceMemberImpliedModifierCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/InterfaceMemberImpliedModifierCheck.java
@@ -64,7 +64,7 @@
* enforce that the {@code public} and {@code static} modifiers are explicitly coded and not
* implicitly added by the compiler.
*
* Rationale for this check: Methods, fields and nested types are treated differently
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
index a73f0815771..6af91c22c78 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
@@ -102,7 +102,7 @@
* Enums can also contain abstract methods and methods which can be overridden by the declared
* enumeration fields.
* See the following example: Since these methods can be overridden in these situations, the final methods are not
* marked as redundant even though they can't be extended by other classes/enums. Public modifier for constructors in non-public non-protected classes
* is always obsolete: There is no violation in the following example,
* because removing public modifier from ProtectedInnerClass
* constructor will make this code not compiling:
* Sometimes, users like to space similar items on different lines to the same
@@ -52,10 +52,10 @@
* check, so both braces in the following case will be reported as violations.
*
* may optionally be exempted from the policy using the {@code allowEmptyMethods},
@@ -54,22 +54,22 @@
*
* This check does not flag as violation double brace initialization like:
*
* Parameter allowEmptyCatches allows to suppress violations when token list
* contains SLIST to check if beginning of block is surrounded by whitespace
* and catch block is empty, for example:
*
* With this property turned off, this raises violation because the beginning
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/NewlineAtEndOfFileCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/NewlineAtEndOfFileCheck.xml
index 9ed5c03e937..d2897e0c38e 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/NewlineAtEndOfFileCheck.xml
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/NewlineAtEndOfFileCheck.xml
@@ -17,7 +17,7 @@
<p>
Example (the line with 'No newline at end of file' should not be in the diff):
</p>
- <pre>
+ <div class="wrapper"><pre class="prettyprint"><code class="language-text">
@@ -32,4 +32,5 @@ ForbidWildcardAsReturnTypeCheck.returnTypeClassNamesIgnoreRegex
PublicReferenceToPrivateTypeCheck.name = Public Reference To Private Type
@@ -26,7 +26,7 @@
\ No newline at end of file
+StaticMethodCandidateCheck.desc = Checks whether private methods should be declared as static.
+StaticMethodCandidateCheck.skippedMethods = Method names to skip during the check.
- </pre>
+ </code></pre></div>
<p>
It can also trick the VCS to report the wrong owner for such lines.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/TrailingCommentCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/TrailingCommentCheck.xml
index 7d010a4725a..12f6db3a070 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/TrailingCommentCheck.xml
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/TrailingCommentCheck.xml
@@ -17,10 +17,10 @@
comments are a bad practice. An end line comment would be one that is on
the same line as actual code. For example:
</p>
- <pre>
+ <div class="wrapper"><pre class="prettyprint"><code class="language-java">
a = b + c; // Some insightful comment
d = e / f; // Another comment for this line
- </pre>
+ </code></pre></div>
<p>
Quoting <cite>Code Complete</cite> for the justification:
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/annotation/AnnotationLocationCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/annotation/AnnotationLocationCheck.xml
index fa95fefe3a3..55c08a8e4a3 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/annotation/AnnotationLocationCheck.xml
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/annotation/AnnotationLocationCheck.xml
@@ -21,9 +21,9 @@
Attention: Annotations among modifiers are ignored (looks like false-negative)
as there might be a problem with annotations for return types:
</p>
- <pre>
+ <div class="wrapper"><pre class="prettyprint"><code class="language-java">
public @Nullable Long getStartTimeOrNull() { ... }
- </pre>
+ </code></pre></div>
<p>
Such annotations are better to keep close to type.
@@ -33,11 +33,11 @@
<p>
Example:
</p>
- <pre>
+ <div class="wrapper"><pre class="prettyprint"><code class="language-java">
@Override
@Nullable
public String getNameIfPresent() { ... }
- </pre>
+ </code></pre></div>
Such annotations are better to keep close to type.
@@ -38,11 +40,11 @@
Example:
Such annotations are better to keep close to type.
@@ -38,11 +40,11 @@
Example:
For example, this check finds the obsolete braces in
and debugging / refactoring leftovers such as
A case in a switch statement does not implicitly form a block.
diff --git a/src/site/xdoc/checks/blocks/avoidnestedblocks.xml.template b/src/site/xdoc/checks/blocks/avoidnestedblocks.xml.template
index 35822cd7b4a..7434db4d796 100644
--- a/src/site/xdoc/checks/blocks/avoidnestedblocks.xml.template
+++ b/src/site/xdoc/checks/blocks/avoidnestedblocks.xml.template
@@ -21,7 +21,7 @@
For example, this check finds the obsolete braces in
and debugging / refactoring leftovers such as
A case in a switch statement does not implicitly form a block.
diff --git a/src/site/xdoc/checks/coding/arraytrailingcomma.xml b/src/site/xdoc/checks/coding/arraytrailingcomma.xml
index c57315ea962..013a3a75b19 100644
--- a/src/site/xdoc/checks/coding/arraytrailingcomma.xml
+++ b/src/site/xdoc/checks/coding/arraytrailingcomma.xml
@@ -13,33 +13,33 @@
Checks that array initialization contains a trailing comma.
By default, the check demands a comma at the end if neither left nor right curly braces
are on the same line as the last element of the array.
Rationale: Putting this comma in makes it easier to change the order
of the elements or add new elements on the end. Main benefit of a trailing
comma is that when you add new entry to an array, no surrounding lines are changed.
If closing brace is on the same line as trailing comma, this benefit is gone
(as the check does not demand a certain location of curly braces the following
two cases will not produce a violation):
If opening brace is on the same line as trailing comma there's also (more arguable)
problem:
By default, the check demands a comma at the end if neither left nor right curly braces
are on the same line as the last element of the array.
Rationale: Putting this comma in makes it easier to change the order
of the elements or add new elements on the end. Main benefit of a trailing
comma is that when you add new entry to an array, no surrounding lines are changed.
If closing brace is on the same line as trailing comma, this benefit is gone
(as the check does not demand a certain location of curly braces the following
two cases will not produce a violation):
If opening brace is on the same line as trailing comma there's also (more arguable)
problem:
Rationale: Some developers find inline conditionals hard to read, so
diff --git a/src/site/xdoc/checks/coding/avoidinlineconditionals.xml.template b/src/site/xdoc/checks/coding/avoidinlineconditionals.xml.template
index 9e29df61f01..392f0438d0e 100644
--- a/src/site/xdoc/checks/coding/avoidinlineconditionals.xml.template
+++ b/src/site/xdoc/checks/coding/avoidinlineconditionals.xml.template
@@ -12,10 +12,10 @@
Rationale: Some developers find inline conditionals hard to read, so
diff --git a/src/site/xdoc/checks/coding/covariantequals.xml b/src/site/xdoc/checks/coding/covariantequals.xml
index 5079cda783d..a120371303a 100644
--- a/src/site/xdoc/checks/coding/covariantequals.xml
+++ b/src/site/xdoc/checks/coding/covariantequals.xml
@@ -43,9 +43,9 @@
as the type of the parameter to
This covariant version of
This covariant version of
A method is recognized as a setter if it is in the following form
where ${anyType} is any primitive type, class or interface name;
${name} is name of the variable that is being set and ${Name} its
capitalized form that appears in the method name. By default, it is expected
that setter returns void, i.e. ${returnType} is 'void'. For example
Any other return types will not let method match a setter pattern. However,
by setting setterCanReturnItsClass property to true
definition of a setter is expanded, so that setter return type can also
be a class in which setter is declared. For example
Such methods are known as chain-setters and a common when Builder-pattern
is used. Property setterCanReturnItsClass has effect only if
diff --git a/src/site/xdoc/checks/coding/hiddenfield.xml.template b/src/site/xdoc/checks/coding/hiddenfield.xml.template
index d81a71ce213..062f9b906b2 100644
--- a/src/site/xdoc/checks/coding/hiddenfield.xml.template
+++ b/src/site/xdoc/checks/coding/hiddenfield.xml.template
@@ -21,29 +21,29 @@
A method is recognized as a setter if it is in the following form
where ${anyType} is any primitive type, class or interface name;
${name} is name of the variable that is being set and ${Name} its
capitalized form that appears in the method name. By default, it is expected
that setter returns void, i.e. ${returnType} is 'void'. For example
Any other return types will not let method match a setter pattern. However,
by setting setterCanReturnItsClass property to true
definition of a setter is expanded, so that setter return type can also
be a class in which setter is declared. For example
Such methods are known as chain-setters and a common when Builder-pattern
is used. Property setterCanReturnItsClass has effect only if
diff --git a/src/site/xdoc/checks/coding/illegaltype.xml b/src/site/xdoc/checks/coding/illegaltype.xml
index 73771ef59a8..3b3d45c2b07 100644
--- a/src/site/xdoc/checks/coding/illegaltype.xml
+++ b/src/site/xdoc/checks/coding/illegaltype.xml
@@ -149,13 +149,11 @@
(of variables, methods or parameters). This helps to avoid ambiguous cases, e.g.:
will be ok.
will be ok.
Note: Check allows usage of the popular assignments in loops:
Assignment inside a condition is not a problem here, as the assignment is surrounded by
diff --git a/src/site/xdoc/checks/coding/innerassignment.xml.template b/src/site/xdoc/checks/coding/innerassignment.xml.template
index 814ea6e2967..85d341b0bca 100644
--- a/src/site/xdoc/checks/coding/innerassignment.xml.template
+++ b/src/site/xdoc/checks/coding/innerassignment.xml.template
@@ -24,7 +24,7 @@
Note: Check allows usage of the popular assignments in loops:
Assignment inside a condition is not a problem here, as the assignment is surrounded by
diff --git a/src/site/xdoc/checks/coding/magicnumber.xml b/src/site/xdoc/checks/coding/magicnumber.xml
index 2982dcdf56f..e398b84103a 100644
--- a/src/site/xdoc/checks/coding/magicnumber.xml
+++ b/src/site/xdoc/checks/coding/magicnumber.xml
@@ -21,14 +21,14 @@
Constant definition is any variable/field that has 'final' modifier.
It is fine to have one constant defining multiple numeric literals within one expression:
-T option prints AST tree of the checked file. -b option shows AST nodes that match given Xpath query. This command can be
used to validate accuracy of Xpath query against given file.
The following example demonstrates validation of methods order, so that public methods
should come before the private ones: -T option prints AST tree of the checked file. -b option shows AST nodes that match given Xpath query. This command can be
used to validate accuracy of Xpath query against given file.
The following example demonstrates validation of methods order, so that public methods
should come before the private ones:
Rationale: If the control variable is modified inside the loop
body, the program flow becomes more difficult to follow. See
@@ -27,20 +27,20 @@ for (int i = 0; i < 1; i++) {
Such loop would be suppressed:
NOTE:The check works with only primitive type variables.
The check will not work for arrays used as control variable.An example is
Rationale: If the control variable is modified inside the loop
body, the program flow becomes more difficult to follow. See
@@ -27,20 +27,20 @@ for (int i = 0; i < 1; i++) {
Such loop would be suppressed:
NOTE:The check works with only primitive type variables.
The check will not work for arrays used as control variable.An example is
The check demands that there should not be any comma after the last element of an array.
diff --git a/src/site/xdoc/checks/coding/noarraytrailingcomma.xml.template b/src/site/xdoc/checks/coding/noarraytrailingcomma.xml.template
index 701674021be..1a8221082f6 100644
--- a/src/site/xdoc/checks/coding/noarraytrailingcomma.xml.template
+++ b/src/site/xdoc/checks/coding/noarraytrailingcomma.xml.template
@@ -15,21 +15,21 @@
them in other locations. To unify the coding style, the use of trailing commas should
be prohibited.
-
The check demands that there should not be any comma after the last element of an array.
diff --git a/src/site/xdoc/checks/coding/noclone.xml b/src/site/xdoc/checks/coding/noclone.xml
index 824f7172a89..cd8647f7d80 100644
--- a/src/site/xdoc/checks/coding/noclone.xml
+++ b/src/site/xdoc/checks/coding/noclone.xml
@@ -81,27 +81,27 @@
clone method. The example below highlights the limitation of a copy constructor
(or static factory). Assume Square is a subclass for Shape.
...assume at this point the code knows nothing of s1 being a Square that's the beauty
of polymorphism but the code wants to copy the Square which is declared as a Shape,
its super type...
The working solution (without knowing about all subclasses and doing many casts) is to do
the following (assuming correct clone implementation).
Just keep in mind if this type of polymorphic cloning is required then a properly
implemented clone method may be the best choice.
diff --git a/src/site/xdoc/checks/coding/noclone.xml.template b/src/site/xdoc/checks/coding/noclone.xml.template
index b173b68ed60..e2ffbd74c10 100644
--- a/src/site/xdoc/checks/coding/noclone.xml.template
+++ b/src/site/xdoc/checks/coding/noclone.xml.template
@@ -81,27 +81,27 @@
clone method. The example below highlights the limitation of a copy constructor
(or static factory). Assume Square is a subclass for Shape.
...assume at this point the code knows nothing of s1 being a Square that's the beauty
of polymorphism but the code wants to copy the Square which is declared as a Shape,
its super type...
The working solution (without knowing about all subclasses and doing many casts) is to do
the following (assuming correct clone implementation).
Just keep in mind if this type of polymorphic cloning is required then a properly
implemented clone method may be the best choice.
diff --git a/src/site/xdoc/checks/coding/noenumtrailingcomma.xml b/src/site/xdoc/checks/coding/noenumtrailingcomma.xml
index 1d52ff1e04a..9c05dbc9f5c 100644
--- a/src/site/xdoc/checks/coding/noenumtrailingcomma.xml
+++ b/src/site/xdoc/checks/coding/noenumtrailingcomma.xml
@@ -15,22 +15,22 @@
them in other locations. To unify the coding style, the use of trailing commas should
be prohibited.
-
The check demands that there should not be any comma after last constant in
enum definition.
The check demands that there should not be any comma after last constant in
enum definition.
could be written as
The idea for this Check has been shamelessly stolen from the
diff --git a/src/site/xdoc/checks/coding/simplifybooleanreturn.xml.template b/src/site/xdoc/checks/coding/simplifybooleanreturn.xml.template
index d68aea3d7d5..af7e4cee09b 100644
--- a/src/site/xdoc/checks/coding/simplifybooleanreturn.xml.template
+++ b/src/site/xdoc/checks/coding/simplifybooleanreturn.xml.template
@@ -13,19 +13,19 @@
Checks for over-complicated boolean return or yield statements. For example
the following code
-
could be written as
The idea for this Check has been shamelessly stolen from the
diff --git a/src/site/xdoc/checks/coding/stringliteralequality.xml b/src/site/xdoc/checks/coding/stringliteralequality.xml
index c57a061e39a..60559ee0930 100644
--- a/src/site/xdoc/checks/coding/stringliteralequality.xml
+++ b/src/site/xdoc/checks/coding/stringliteralequality.xml
@@ -23,14 +23,14 @@
Rationale: Novice Java programmers often use code like:
when they mean
Rationale: Novice Java programmers often use code like:
when they mean
In the first case, given that a, b, and c are all
The partial support for operator precedence includes cases of the following type:
In the first case, given that a, b, and c are all
The partial support for operator precedence includes cases of the following type:
Example of code that cause violation as it is designed for extension:
Example of code without violation:
Example of code that cause violation as it is designed for extension:
Example of code without violation:
Result: imports will be assigned to SPECIAL_IMPORTS, because matching
substring length is 16. Matching substring for STANDARD_JAVA_PACKAGE is 5.
@@ -107,9 +107,9 @@ import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
2. patterns STANDARD_JAVA_PACKAGE = "Check", SPECIAL_IMPORTS="Avoid" and file:
Result: import will be assigned to SPECIAL_IMPORTS. Matching substring length is 5 for
both patterns. However, "Avoid" position is lower than "Check" position.
diff --git a/src/site/xdoc/checks/imports/customimportorder.xml.template b/src/site/xdoc/checks/imports/customimportorder.xml.template
index 01d6a47e9b7..9bee4a9c026 100644
--- a/src/site/xdoc/checks/imports/customimportorder.xml.template
+++ b/src/site/xdoc/checks/imports/customimportorder.xml.template
@@ -28,7 +28,7 @@
SAME_PACKAGE(n) group. This group sets the ordering of the same package imports.
Imports are considered on SAME_PACKAGE group if n first domains in package
name and import name are identical:
-
Result: imports will be assigned to SPECIAL_IMPORTS, because matching
substring length is 16. Matching substring for STANDARD_JAVA_PACKAGE is 5.
@@ -107,9 +107,9 @@ import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
2. patterns STANDARD_JAVA_PACKAGE = "Check", SPECIAL_IMPORTS="Avoid" and file:
Result: import will be assigned to SPECIAL_IMPORTS. Matching substring length is 5 for
both patterns. However, "Avoid" position is lower than "Check" position.
diff --git a/src/site/xdoc/checks/imports/importcontrol.xml b/src/site/xdoc/checks/imports/importcontrol.xml
index abdf870b75b..cf83ea51b1b 100644
--- a/src/site/xdoc/checks/imports/importcontrol.xml
+++ b/src/site/xdoc/checks/imports/importcontrol.xml
@@ -81,13 +81,11 @@
document type declaration in your XML document:
To configure the check to only check the "src/main" directory
@@ -136,12 +134,12 @@
then have the following:
In the example below access to package
@@ -154,7 +152,7 @@
and
In the next example regular expressions are used to enforce a layering rule: In all
@@ -184,7 +182,7 @@
with the same rules.
In the next examples usage of
In the example below, any import is disallowed inside
@@ -243,7 +241,7 @@
However, any import is allowed in the classes outside of
When
In the example below, only file names that end with "Panel", "View", or "Dialog"
in the package
For a real-life import control file look at the file called
@@ -317,14 +315,14 @@
In the next example imports
In the following example, all imports are allowed except the classes
In the following example, all imports of the
@@ -430,19 +428,19 @@ import java.util.stream.IntStream;
For example, to allow importing both It is also possible to use a regex with a wildcard:
To configure the check to only check the "src/main" directory
@@ -117,12 +115,12 @@
then have the following:
In the example below access to package
@@ -135,7 +133,7 @@
and
In the next example regular expressions are used to enforce a layering rule: In all
@@ -165,7 +163,7 @@
with the same rules.
In the next examples usage of
In the example below, any import is disallowed inside
@@ -224,7 +222,7 @@
However, any import is allowed in the classes outside of
When
In the example below, only file names that end with "Panel", "View", or "Dialog"
in the package
For a real-life import control file look at the file called
@@ -298,14 +296,14 @@
In the next example imports
In the following example, all imports are allowed except the classes
In the following example, all imports of the
@@ -411,19 +409,19 @@ import java.util.stream.IntStream;
For example, to allow importing both It is also possible to use a regex with a wildcard:
For e.g. this is what is considered to be container names for the given example:
According to this logic, HttpHeaders.Names should come after HttpHeaders.
Example:
To configure the check to enforce static import group separation
For e.g. this is what is considered to be container names for the given example:
According to this logic, HttpHeaders.Names should come after HttpHeaders.
Example:
To configure the check to enforce static import group separation
The documentation generated will be just "Some text." without any asterisks.
Since these asterisks will not appear in the generated documentation,
diff --git a/src/site/xdoc/checks/javadoc/javadoccontentlocation.xml.template b/src/site/xdoc/checks/javadoc/javadoccontentlocation.xml.template
index 9959c3a9d33..a5e88a55421 100644
--- a/src/site/xdoc/checks/javadoc/javadoccontentlocation.xml.template
+++ b/src/site/xdoc/checks/javadoc/javadoccontentlocation.xml.template
@@ -20,22 +20,22 @@
The documentation generated will be just "Some text." without any asterisks.
Since these asterisks will not appear in the generated documentation,
diff --git a/src/site/xdoc/checks/javadoc/javadocmethod.xml b/src/site/xdoc/checks/javadoc/javadocmethod.xml
index 66f29701078..ff1eb1c37b7 100644
--- a/src/site/xdoc/checks/javadoc/javadocmethod.xml
+++ b/src/site/xdoc/checks/javadoc/javadocmethod.xml
@@ -74,12 +74,12 @@
Javadoc could be done as:
Example: Example:
Example (the line with 'No newline at end of file' should not be in the diff):
It can also trick the VCS to report the wrong owner for such lines.
An engineer who has added nothing but a newline character becomes
diff --git a/src/site/xdoc/checks/misc/newlineatendoffile.xml.template b/src/site/xdoc/checks/misc/newlineatendoffile.xml.template
index c3e093fc99a..de63d7a531b 100644
--- a/src/site/xdoc/checks/misc/newlineatendoffile.xml.template
+++ b/src/site/xdoc/checks/misc/newlineatendoffile.xml.template
@@ -21,7 +21,7 @@
Example (the line with 'No newline at end of file' should not be in the diff):
It can also trick the VCS to report the wrong owner for such lines.
An engineer who has added nothing but a newline character becomes
diff --git a/src/site/xdoc/checks/misc/trailingcomment.xml b/src/site/xdoc/checks/misc/trailingcomment.xml
index 2c342f373d8..bab2de698d6 100644
--- a/src/site/xdoc/checks/misc/trailingcomment.xml
+++ b/src/site/xdoc/checks/misc/trailingcomment.xml
@@ -24,10 +24,10 @@
one that is on the same line as actual code. For example:
Quoting Code Complete for the justification:
diff --git a/src/site/xdoc/checks/misc/trailingcomment.xml.template b/src/site/xdoc/checks/misc/trailingcomment.xml.template
index e9aad311c64..da31e63ea8e 100644
--- a/src/site/xdoc/checks/misc/trailingcomment.xml.template
+++ b/src/site/xdoc/checks/misc/trailingcomment.xml.template
@@ -24,10 +24,10 @@
one that is on the same line as actual code. For example:
Quoting Code Complete for the justification:
diff --git a/src/site/xdoc/checks/misc/translation.xml b/src/site/xdoc/checks/misc/translation.xml
index a337afec356..61e786f385d 100644
--- a/src/site/xdoc/checks/misc/translation.xml
+++ b/src/site/xdoc/checks/misc/translation.xml
@@ -101,11 +101,11 @@
</module>
Example1 (target folder structure): Contents of messages.properties file: Example2 (target folder structure): Contents of ButtonLabels.properties file: Example3 no messages_home_fr.* files (target folder structure): Contents of messages_home.properties file: Example1 (target folder structure): Contents of messages.properties file: Example2 (target folder structure): Contents of ButtonLabels.properties file: Example3 no messages_home_fr.* files (target folder structure): Contents of messages_home.properties file:
Rationale for this check:
Nested enums, interfaces, and records are treated differently from nested classes as they
diff --git a/src/site/xdoc/checks/modifier/classmemberimpliedmodifier.xml.template b/src/site/xdoc/checks/modifier/classmemberimpliedmodifier.xml.template
index f366dc00df7..9c92730c7a6 100644
--- a/src/site/xdoc/checks/modifier/classmemberimpliedmodifier.xml.template
+++ b/src/site/xdoc/checks/modifier/classmemberimpliedmodifier.xml.template
@@ -24,13 +24,13 @@
the ability to enforce that the
Rationale for this check:
Nested enums, interfaces, and records are treated differently from nested classes as they
diff --git a/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml b/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml
index 4aa073755d2..c0b57435970 100644
--- a/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml
+++ b/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml
@@ -43,7 +43,7 @@
the ability to enforce that the
Rationale for this check:
Methods, fields and nested types are treated differently depending on whether
diff --git a/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml.template b/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml.template
index 73f16ff47d9..e8ce41941dd 100644
--- a/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml.template
+++ b/src/site/xdoc/checks/modifier/interfacememberimpliedmodifier.xml.template
@@ -43,7 +43,7 @@
the ability to enforce that the
Rationale for this check:
Methods, fields and nested types are treated differently depending on whether
diff --git a/src/site/xdoc/checks/modifier/redundantmodifier.xml b/src/site/xdoc/checks/modifier/redundantmodifier.xml
index 16aff091a52..3916fb4018d 100644
--- a/src/site/xdoc/checks/modifier/redundantmodifier.xml
+++ b/src/site/xdoc/checks/modifier/redundantmodifier.xml
@@ -87,7 +87,7 @@
See the following example:
Since these methods can be overridden in these situations, the final methods are not
@@ -119,7 +119,7 @@ public enum EnumClass {
is always obsolete:
There is no violation in the following example,
because removing public modifier from ProtectedInnerClass
constructor will make this code not compiling:
Since these methods can be overridden in these situations, the final methods are not
@@ -119,7 +119,7 @@ public enum EnumClass {
is always obsolete:
There is no violation in the following example,
because removing public modifier from ProtectedInnerClass
constructor will make this code not compiling:
Result: Result:
Examples of not line-wrapped statements (good case):
Examples of not line-wrapped statements (good case):
The following cases are not checked:
The following cases are not checked:
Sometimes, users like to space similar items on different lines to the same
@@ -33,10 +33,10 @@ ignored */ i) {
check, so both braces in the following case will be reported as violations.
Sometimes, users like to space similar items on different lines to the same
@@ -33,10 +33,10 @@ ignored */ i) {
check, so both braces in the following case will be reported as violations.
may optionally be exempted from the policy using the This check does not flag as violation double brace initialization like: Parameter allowEmptyCatches allows to suppress violations when token
list contains SLIST to check if beginning of block is surrounded by
whitespace and catch block is empty, for example:
With this property turned off, this raises violation because the beginning of the
catch block (left curly bracket) is not separated from the end of the catch
diff --git a/src/site/xdoc/checks/whitespace/whitespacearound.xml.template b/src/site/xdoc/checks/whitespace/whitespacearound.xml.template
index 981cabe08a0..d4457c4bcf3 100644
--- a/src/site/xdoc/checks/whitespace/whitespacearound.xml.template
+++ b/src/site/xdoc/checks/whitespace/whitespacearound.xml.template
@@ -14,7 +14,8 @@
method, class, enum, interface, loop bodies (blocks), lambdas of the form
-
may optionally be exempted from the policy using the This check does not flag as violation double brace initialization like: Parameter allowEmptyCatches allows to suppress violations when token
list contains SLIST to check if beginning of block is surrounded by
whitespace and catch block is empty, for example:
With this property turned off, this raises violation because the beginning of the
catch block (left curly bracket) is not separated from the end of the catch
diff --git a/src/site/xdoc/filters/suppressionfilter.xml b/src/site/xdoc/filters/suppressionfilter.xml
index 099ebb72f01..7c3533e54f2 100644
--- a/src/site/xdoc/filters/suppressionfilter.xml
+++ b/src/site/xdoc/filters/suppressionfilter.xml
@@ -129,12 +129,12 @@
with suppressions
file
The following suppressions XML document directs
a
Suppress check by module id
when config have two instances on the same check:
Suppress all checks for hidden files and folders:
Suppress all checks for Maven-generated code:
Suppress all checks for archives, classes and other binary files:
Suppress all checks for image files:
Suppress all checks for non-java files:
Suppress all checks in generated sources:
Suppress FileLength check on integration tests in certain folder:
Suppress naming violations on variable named 'log' in all files:
The following suppressions XML document directs
a
Suppress check by module id
when config have two instances on the same check:
Suppress all checks for hidden files and folders:
Suppress all checks for Maven-generated code:
Suppress all checks for archives, classes and other binary files:
Suppress all checks for image files:
Suppress all checks for non-java files:
Suppress all checks in generated sources:
Suppress FileLength check on integration tests in certain folder:
Suppress naming violations on variable named 'log' in all files:
A suppressions XML
document contains a set
@@ -204,7 +204,7 @@
more accurate results.
Other token types always have constant values.
Suppress checks for package definitions:
Suppress checks for parent element of the first variable definition:
Suppress checks for elements which are either class definitions,
either method definitions.
Suppress checks for certain methods:
Suppress checks for variable testVariable inside testMethod method
inside TestClass class.
In the following sample, violations for
The following example demonstrates how to suppress
Suppress
The following sample demonstrates how to suppress all violations for method itself and
all descendants. Some elements can be suppressed in different ways.
For example, to suppress violation on variable You need to look at AST of such code by our CLI tool:
The easiest way is to suppress by variable name. As you can see The following example demonstrates how variable can be queried by its name: Another way is to suppress by variable value. Again, if you look at the printed AST tree
above, you will notice that one of the grandchildren of The following example demonstrates how variable can be queried by its value, same
approach applies to Next example is about suppressing method with certain annotation by its name and
element value. First of all we need to look at AST tree printed by our CLI tool:
AST node
The problem with query above that it will suppress violations for all methods with
annotation
A suppressions XML
document contains a set
@@ -185,7 +185,7 @@
more accurate results.
Other token types always have constant values.
Suppress checks for package definitions:
Suppress checks for parent element of the first variable definition:
Suppress checks for elements which are either class definitions,
either method definitions.
Suppress checks for certain methods:
Suppress checks for variable testVariable inside testMethod method
inside TestClass class.
In the following sample, violations for
The following example demonstrates how to suppress
Suppress
The following sample demonstrates how to suppress all violations for method itself and
all descendants. Some elements can be suppressed in different ways.
For example, to suppress violation on variable You need to look at AST of such code by our CLI tool:
The easiest way is to suppress by variable name. As you can see The following example demonstrates how variable can be queried by its name: Another way is to suppress by variable value. Again, if you look at the printed AST tree
above, you will notice that one of the grandchildren of The following example demonstrates how variable can be queried by its value, same
approach applies to Next example is about suppressing method with certain annotation by its name and
element value. First of all we need to look at AST tree printed by our CLI tool:
AST node
The problem with query above that it will suppress violations for all methods with
annotation
To start the development - visit our
From 39276088e7b9ddada13e63cf9fd0fa44b18c00e7 Mon Sep 17 00:00:00 2001
From: Mohit Attry
Attention: Elements that cannot have JavaDoc comments like local variables are not in the
- scope of this check even though a token type like
@@ -29,7 +28,7 @@
as there might be a problem with annotations for return types:
@@ -41,8 +40,8 @@
Example:
Since Checkstyle 6.0
- Attention: Elements that cannot have JavaDoc comments like local variables are not in the
- scope of this check even though a token type like
- Attention: Annotations among modifiers are ignored (looks like false-negative)
- as there might be a problem with annotations for return types:
-
- Such annotations are better to keep close to type.
- Due to limitations, Checkstyle can not examine the target of an annotation.
-
- Example:
- Since Checkstyle 10.26.0
- Pattern variable assignment is considered bad programming practice. The pattern variable
- is meant to be a direct reference to the object being matched. Reassigning it can break
- this connection and mislead readers.
+ Pattern variable assignment is considered bad programming practice. The pattern variable
+ is meant to be a direct reference to the object being matched. Reassigning it can break this
+ connection and mislead readers.
Since Checkstyle 10.26.0
- Pattern variable assignment is considered bad programming practice. The pattern variable
- is meant to be a direct reference to the object being matched. Reassigning it can break
- this connection and mislead readers.
- '}'
) for code blocks. This check
+ * supports if-else, try-catch-finally blocks, while-loops, for-loops,
* method definitions, class definitions, constructor definitions,
* instance, static initialization blocks, annotation definitions and enum definitions.
* For right curly brace of expression blocks of arrays, lambdas and class instances
From eee400069f4549ac015fc130f3de5ea39c034845 Mon Sep 17 00:00:00 2001
From: Amit Kumar Deohoria
+
+
+
+
+
+ MatchXpath
+ (
+ config)
From e700629a23b12ceb46199abb977cf42ff7503e60 Mon Sep 17 00:00:00 2001
From: Amit Kumar Deohoria tags
---
config/intellij-idea-inspections.xml | 3 +
.../checks/NewlineAtEndOfFileCheck.java | 4 +-
.../checks/TrailingCommentCheck.java | 4 +-
.../annotation/AnnotationLocationCheck.java | 8 +-
.../annotation/MissingDeprecatedCheck.java | 4 +-
.../checks/blocks/AvoidNestedBlocksCheck.java | 8 +-
.../coding/ArrayTrailingCommaCheck.java | 20 ++---
.../coding/AvoidInlineConditionalsCheck.java | 4 +-
.../checks/coding/CovariantEqualsCheck.java | 4 +-
.../checks/coding/DeclarationOrderCheck.java | 4 +-
.../checks/coding/HiddenFieldCheck.java | 12 +--
.../checks/coding/IllegalTypeCheck.java | 4 +-
.../checks/coding/InnerAssignmentCheck.java | 4 +-
.../checks/coding/MagicNumberCheck.java | 4 +-
.../coding/ModifiedControlVariableCheck.java | 12 +--
.../coding/NoArrayTrailingCommaCheck.java | 8 +-
.../checks/coding/NoCloneCheck.java | 12 +--
.../coding/NoEnumTrailingCommaCheck.java | 8 +-
.../coding/SimplifyBooleanReturnCheck.java | 8 +-
.../coding/StringLiteralEqualityCheck.java | 8 +-
.../coding/UnnecessaryParenthesesCheck.java | 13 +--
.../design/DesignForExtensionCheck.java | 8 +-
.../HideUtilityClassConstructorCheck.java | 4 +-
.../imports/CustomImportOrderCheck.java | 12 +--
.../checks/imports/ImportControlCheck.java | 4 +-
.../checks/indentation/IndentationCheck.java | 4 +-
.../javadoc/JavadocBlockTagLocationCheck.java | 4 +-
.../javadoc/JavadocContentLocationCheck.java | 12 +--
.../checks/javadoc/JavadocMethodCheck.java | 4 +-
.../javadoc/MissingJavadocMethodCheck.java | 4 +-
.../ClassMemberImpliedModifierCheck.java | 4 +-
.../InterfaceMemberImpliedModifierCheck.java | 4 +-
.../modifier/RedundantModifierCheck.java | 12 +--
.../checks/sizes/LineLengthCheck.java | 4 +-
.../checks/sizes/MethodCountCheck.java | 4 +-
.../EmptyForInitializerPadCheck.java | 4 +-
.../whitespace/EmptyForIteratorPadCheck.java | 4 +-
.../whitespace/SingleSpaceSeparatorCheck.java | 8 +-
.../whitespace/WhitespaceAroundCheck.java | 12 +--
.../meta/checks/NewlineAtEndOfFileCheck.xml | 4 +-
.../meta/checks/TrailingCommentCheck.xml | 4 +-
.../annotation/AnnotationLocationCheck.xml | 8 +-
.../annotation/MissingDeprecatedCheck.xml | 4 +-
.../checks/blocks/AvoidNestedBlocksCheck.xml | 8 +-
.../checks/coding/ArrayTrailingCommaCheck.xml | 20 ++---
.../coding/AvoidInlineConditionalsCheck.xml | 4 +-
.../checks/coding/CovariantEqualsCheck.xml | 4 +-
.../checks/coding/DeclarationOrderCheck.xml | 4 +-
.../meta/checks/coding/HiddenFieldCheck.xml | 12 +--
.../meta/checks/coding/IllegalTypeCheck.xml | 4 +-
.../checks/coding/InnerAssignmentCheck.xml | 4 +-
.../meta/checks/coding/MagicNumberCheck.xml | 4 +-
.../coding/ModifiedControlVariableCheck.xml | 12 +--
.../coding/NoArrayTrailingCommaCheck.xml | 8 +-
.../meta/checks/coding/NoCloneCheck.xml | 12 +--
.../coding/NoEnumTrailingCommaCheck.xml | 8 +-
.../coding/SimplifyBooleanReturnCheck.xml | 8 +-
.../coding/StringLiteralEqualityCheck.xml | 8 +-
.../coding/UnnecessaryParenthesesCheck.xml | 13 +--
.../checks/design/DesignForExtensionCheck.xml | 8 +-
.../HideUtilityClassConstructorCheck.xml | 4 +-
.../checks/imports/CustomImportOrderCheck.xml | 12 +--
.../checks/imports/ImportControlCheck.xml | 4 +-
.../checks/indentation/IndentationCheck.xml | 4 +-
.../javadoc/JavadocBlockTagLocationCheck.xml | 4 +-
.../javadoc/JavadocContentLocationCheck.xml | 12 +--
.../checks/javadoc/JavadocMethodCheck.xml | 4 +-
.../javadoc/MissingJavadocMethodCheck.xml | 4 +-
.../ClassMemberImpliedModifierCheck.xml | 4 +-
.../InterfaceMemberImpliedModifierCheck.xml | 4 +-
.../modifier/RedundantModifierCheck.xml | 12 +--
.../meta/checks/sizes/LineLengthCheck.xml | 4 +-
.../meta/checks/sizes/MethodCountCheck.xml | 4 +-
.../EmptyForInitializerPadCheck.xml | 4 +-
.../whitespace/EmptyForIteratorPadCheck.xml | 4 +-
.../whitespace/SingleSpaceSeparatorCheck.xml | 8 +-
.../whitespace/WhitespaceAroundCheck.xml | 12 +--
.../checks/annotation/annotationlocation.xml | 8 +-
.../annotationlocation.xml.template | 8 +-
.../checks/annotation/missingdeprecated.xml | 4 +-
.../annotation/missingdeprecated.xml.template | 4 +-
.../xdoc/checks/blocks/avoidnestedblocks.xml | 8 +-
.../blocks/avoidnestedblocks.xml.template | 8 +-
.../xdoc/checks/coding/arraytrailingcomma.xml | 20 ++---
.../coding/arraytrailingcomma.xml.template | 20 ++---
.../checks/coding/avoidinlineconditionals.xml | 4 +-
.../avoidinlineconditionals.xml.template | 4 +-
.../xdoc/checks/coding/covariantequals.xml | 4 +-
.../coding/covariantequals.xml.template | 4 +-
.../xdoc/checks/coding/declarationorder.xml | 4 +-
.../coding/declarationorder.xml.template | 4 +-
src/site/xdoc/checks/coding/hiddenfield.xml | 12 +--
.../checks/coding/hiddenfield.xml.template | 12 +--
src/site/xdoc/checks/coding/illegaltype.xml | 6 +-
.../checks/coding/illegaltype.xml.template | 6 +-
.../xdoc/checks/coding/innerassignment.xml | 4 +-
.../coding/innerassignment.xml.template | 4 +-
src/site/xdoc/checks/coding/magicnumber.xml | 4 +-
.../checks/coding/magicnumber.xml.template | 4 +-
src/site/xdoc/checks/coding/matchxpath.xml | 8 +-
.../checks/coding/matchxpath.xml.template | 8 +-
.../checks/coding/modifiedcontrolvariable.xml | 12 +--
.../modifiedcontrolvariable.xml.template | 12 +--
.../checks/coding/noarraytrailingcomma.xml | 8 +-
.../coding/noarraytrailingcomma.xml.template | 8 +-
src/site/xdoc/checks/coding/noclone.xml | 12 +--
.../xdoc/checks/coding/noclone.xml.template | 12 +--
.../checks/coding/noenumtrailingcomma.xml | 8 +-
.../coding/noenumtrailingcomma.xml.template | 8 +-
.../checks/coding/simplifybooleanreturn.xml | 8 +-
.../coding/simplifybooleanreturn.xml.template | 8 +-
.../checks/coding/stringliteralequality.xml | 8 +-
.../coding/stringliteralequality.xml.template | 8 +-
.../checks/coding/unnecessaryparentheses.xml | 12 +--
.../unnecessaryparentheses.xml.template | 12 +--
.../xdoc/checks/design/designforextension.xml | 8 +-
.../design/designforextension.xml.template | 8 +-
.../design/hideutilityclassconstructor.xml | 4 +-
.../hideutilityclassconstructor.xml.template | 4 +-
.../xdoc/checks/imports/customimportorder.xml | 12 +--
.../imports/customimportorder.xml.template | 12 +--
.../xdoc/checks/imports/importcontrol.xml | 66 +++++++--------
.../checks/imports/importcontrol.xml.template | 66 +++++++--------
src/site/xdoc/checks/imports/importorder.xml | 8 +-
.../checks/imports/importorder.xml.template | 8 +-
.../javadoc/javadocblocktaglocation.xml | 4 +-
.../javadocblocktaglocation.xml.template | 4 +-
.../checks/javadoc/javadoccontentlocation.xml | 12 +--
.../javadoccontentlocation.xml.template | 12 +--
.../xdoc/checks/javadoc/javadocmethod.xml | 4 +-
.../checks/javadoc/javadocmethod.xml.template | 4 +-
.../checks/javadoc/missingjavadocmethod.xml | 4 +-
.../javadoc/missingjavadocmethod.xml.template | 4 +-
src/site/xdoc/checks/misc/indentation.xml | 4 +-
.../xdoc/checks/misc/indentation.xml.template | 4 +-
.../xdoc/checks/misc/newlineatendoffile.xml | 4 +-
.../misc/newlineatendoffile.xml.template | 4 +-
src/site/xdoc/checks/misc/trailingcomment.xml | 4 +-
.../checks/misc/trailingcomment.xml.template | 4 +-
src/site/xdoc/checks/misc/translation.xml | 12 +--
.../xdoc/checks/misc/translation.xml.template | 12 +--
.../modifier/classmemberimpliedmodifier.xml | 4 +-
.../classmemberimpliedmodifier.xml.template | 4 +-
.../interfacememberimpliedmodifier.xml | 4 +-
...nterfacememberimpliedmodifier.xml.template | 4 +-
.../checks/modifier/redundantmodifier.xml | 12 +--
.../modifier/redundantmodifier.xml.template | 12 +--
.../xdoc/checks/regexp/regexpmultiline.xml | 4 +-
.../regexp/regexpmultiline.xml.template | 4 +-
src/site/xdoc/checks/sizes/linelength.xml | 4 +-
.../xdoc/checks/sizes/linelength.xml.template | 4 +-
src/site/xdoc/checks/sizes/methodcount.xml | 4 +-
.../checks/sizes/methodcount.xml.template | 4 +-
.../whitespace/emptyforinitializerpad.xml | 4 +-
.../emptyforinitializerpad.xml.template | 4 +-
.../checks/whitespace/emptyforiteratorpad.xml | 4 +-
.../emptyforiteratorpad.xml.template | 4 +-
.../xdoc/checks/whitespace/nolinewrap.xml | 4 +-
.../checks/whitespace/nolinewrap.xml.template | 4 +-
src/site/xdoc/checks/whitespace/parenpad.xml | 4 +-
.../checks/whitespace/parenpad.xml.template | 4 +-
.../whitespace/singlespaceseparator.xml | 8 +-
.../singlespaceseparator.xml.template | 8 +-
.../checks/whitespace/whitespacearound.xml | 17 ++--
.../whitespace/whitespacearound.xml.template | 17 ++--
src/site/xdoc/filters/suppressionfilter.xml | 44 +++++-----
.../filters/suppressionfilter.xml.template | 44 +++++-----
.../xdoc/filters/suppressionxpathfilter.xml | 84 +++++++++----------
.../suppressionxpathfilter.xml.template | 84 +++++++++----------
169 files changed, 765 insertions(+), 770 deletions(-)
diff --git a/config/intellij-idea-inspections.xml b/config/intellij-idea-inspections.xml
index 15e0c1dc4dd..8b8f9344a9c 100644
--- a/config/intellij-idea-inspections.xml
+++ b/config/intellij-idea-inspections.xml
@@ -2648,6 +2648,9 @@
enabled_by_default="true"/>
+ *
+ *
* @@ -32,4 +32,5 @@ ForbidWildcardAsReturnTypeCheck.returnTypeClassNamesIgnoreRegex
* PublicReferenceToPrivateTypeCheck.name = Public Reference To Private Type
*
@@ -51,7 +51,7 @@
* \ No newline at end of file
* +StaticMethodCandidateCheck.desc = Checks whether private methods should be declared as static.
* +StaticMethodCandidateCheck.skippedMethods = Method names to skip during the check.
- *
+ *
+ *
* a = b + c; // Some insightful comment
* d = e / f; // Another comment for this line
- *
+ *
+ *
* public @Nullable Long getStartTimeOrNull() { ... }
- *
+ *
+ *
* @Override
* @Nullable
* public String getNameIfPresent() { ... }
- *
*
+ *
+ *
* <!-- required till https://bugs.openjdk.org/browse/JDK-8160601 -->
* <module name="SuppressionSingleFilter">
* <property name="checks" value="MissingDeprecatedCheck"/>
* <property name="files" value="package-info\.java"/>
* </module>
- *
*
+ *
+ *
* public void guessTheOutput()
* {
* int whichIsWhich = 0;
@@ -46,17 +46,17 @@
* }
* System.out.println("value = " + whichIsWhich);
* }
- *
+ *
+ *
* // if (conditionThatIsNotUsedAnyLonger)
* {
* System.out.println("unconditional");
* }
- *
+ *
+ *
* int[] a = new int[]
* {
* 1,
* 2,
* 3,
* };
- *
+ *
+ *
* return new int[] { 0 };
* return new int[] { 0
* };
* return new int[] {
* 0 };
- *
+ *
+ *
* {
* 100000000000000000000,
* 200000000000000000000, // OK
@@ -67,33 +67,33 @@
* 200000000000000000000,
* 300000000000000000000, // Just this line added, no other changes
* }
- *
+ *
+ *
* {100000000000000000000,
* 200000000000000000000,} // Trailing comma not needed, line needs to be modified anyway
*
* {100000000000000000000,
* 200000000000000000000, // Modified line
* 300000000000000000000,} // Added line
- *
+ *
+ *
* {100000000000000000000, // Line cannot be just duplicated to slightly modify entry
* }
*
* {100000000000000000000,
* 100000000000000000001, // More work needed to duplicate
* }
- *
*
+ *
+ *
* String a = getParameter("a");
* String b = (a==null || a.length()<1) ? null : a.substring(1);
- *
+ *
+ *
* public boolean equals(Foo obj) {...}
- *
+ *
+ *
* public class A {
* private double x = 1.0;
* private double y = 2.0;
* public double slope = x / y; // will be skipped from validation due to forward reference
* }
- *
*
+ *
+ *
* ${returnType} set${Name}(${anyType} ${name}) { ... }
- *
+ *
+ *
* void setTime(long time) { ... }
- *
+ *
+ *
* class PageBuilder {
* PageBuilder setName(String name) { ... }
* }
- *
+ *
+ *
* import java.util.List;
* ...
* List list; //No violation here
- *
+ *
+ *
* String line;
* while ((line = bufferedReader.readLine()) != null) { // OK
* // process the line
@@ -58,7 +58,7 @@
* // process the line
* }
* while ((line = bufferedReader.readLine()) != null); // OK
- *
+ *
+ *
* static final int SECONDS_PER_DAY = 24 * 60 * 60;
* static final double SPECIAL_RATIO = 4.0 / 3.0;
* static final double SPECIAL_SUM = 1 + Math.E;
* static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
* static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
* static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);
- *
*
+ *
+ *
* for (int i = 0; i < 1; i++) {
* i++; // violation
* }
- *
+ *
+ *
* for (int i = 0; i < 10;) {
* i++;
* }
- *
+ *
+ *
* for (int a[]={0};a[0] < 10;a[0]++) {
* a[0]++; // it will skip this violation
* }
- *
*
+ *
+ *
* int[] foo = new int[] {
* 1,
* 2
* };
- *
+ *
+ *
* String[] foo = new String[] {
* "FOO",
* "BAR", // violation
* }
- *
+ *
+ *
* Shape s1 = new Square();
* System.out.println(s1 instanceof Square); //true
- *
+ *
+ *
* Shape s2 = new Shape(s1); //using the copy constructor
* System.out.println(s2 instanceof Square); //false
- *
+ *
+ *
* Shape s2 = s1.clone();
* System.out.println(s2 instanceof Square); //true
- *
+ *
+ *
* enum Foo1 {
* FOO,
* BAR;
* }
- *
+ *
+ *
* enum Foo1 {
* FOO,
* BAR, // violation
* }
- *
+ *
+ *
* if (valid())
* return false;
* else
* return true;
- *
+ *
+ *
* return !valid();
- *
+ *
+ *
* if (x == "something")
- *
+ *
+ *
* if ("something".equals(x))
- *
+ *
+ *
* return (x); // parens around identifier
* return (x + 1); // parens around return value
* int x = (y / 2 + 1); // parens around assignment rhs
@@ -46,7 +46,7 @@
* || z < 9;
* boolean b = (~a) > -27 // parens around ~a
* && (a-- < 30); // parens around expression
- *
+ *
+ * if (p == (q <= r)) {}
+ *
* int x = (a + b) + c; // 1st Case
* boolean p = true; // 2nd Case
* int q = 4;
* int r = 3;
- * if (p == (q <= r)) {}
+ *
+ *
* boolean a = true, b = true;
* boolean c = false, d = false;
* if ((a && b) || c) { // violation, unnecessary paren
@@ -94,7 +95,7 @@
* }
* if ((++f) > g && a) { // violation, unnecessary paren
* }
- *
*
+ *
+ *
* public abstract class Plant {
* private String roots;
* private String trunk;
@@ -142,12 +142,12 @@
* validate();
* }
* }
- *
+ *
+ *
* public abstract class Plant {
* private String roots;
* private String trunk;
@@ -162,7 +162,7 @@
*
* public abstract void grow();
* }
- *
*
+ *
+ *
* public class StringUtils // not final to allow subclassing
* {
* protected StringUtils() {
@@ -56,7 +56,7 @@
* // ...
* }
* }
- *
*
+ *
+ *
* package java.util.concurrent.locks;
*
* import java.io.File;
@@ -63,7 +63,7 @@
* import java.util.concurrent.locks.LockSupport; //#6
* import java.util.regex.Pattern; //#7
* import java.util.regex.Matcher; //#8
- *
+ *
+ *
* import com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck;
* import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
- *
+ *
+ *
* import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck;
- *
+ *
+ *
* <!DOCTYPE import-control PUBLIC
* "-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
* "https://checkstyle.org/dtds/import_control_1_4.dtd">
- *
*
+ *
+ *
* if ((condition1 && condition2)
* || (condition3 && condition4) // line wrap with bigger indentation
* ||!(condition5 && condition6)) { // line wrap with bigger indentation
@@ -68,7 +68,7 @@
* return c.doSome(); // basic offset
* });
* }
- *
*
+ *
+ *
* /**
* * @serial literal in {@code @serial} Javadoc tag.
* */
- *
*
*
*
@@ -73,7 +73,7 @@
* Documentation Comment Specification permits leading asterisks on the first line.
* For these Javadoc comments:
*
- *
+ *
+ *
* /** Summary text.
* * More details.
* */
* public void method();
- *
+ *
+ *
* /**
* * Summary text.
* * More details.
* */
* public void method();
- *
+ *
+ *
* /***
* * Some text.
* */
@@ -83,7 +83,7 @@
* /** **
* * Some text.
* */
- *
+ *
+ *
* /** {@inheritDoc} */
* public int checkReturnTag(final int aTagIndex,
* JavadocTag[] aTags,
* int aLineNo)
- *
*
+ *
+ *
* public void setNumber(final int number)
* {
* mNumber = number;
@@ -68,7 +68,7 @@
* {
* return false;
* }
- *
*
+ *
+ *
* public final class Person {
* enum Age { // violation
* CHILD, ADULT
* }
* }
- *
+ *
+ *
* public interface AddressFactory {
* // check enforces code contains "public static final"
* public static final String UNKNOWN = "Unknown";
@@ -88,7 +88,7 @@
* return createAddress(OTHER, OTHER);
* }
* }
- *
+ *
+ *
* public enum EnumClass {
* FIELD_1,
* FIELD_2 {
@@ -113,7 +113,7 @@
* public void method1() {}
* public final void method2() {} // no violation expected
* }
- *
+ *
+ *
* public class PublicClass {
* public PublicClass() {} // OK
* }
@@ -137,13 +137,13 @@
* class PackagePrivateClass {
* public PackagePrivateClass() {} // violation expected
* }
- *
+ *
+ *
* package a;
* public class ClassExample {
* protected class ProtectedInnerClass {
@@ -156,7 +156,7 @@
* public class ClassExtending extends ClassExample {
* ProtectedInnerClass pc = new ProtectedInnerClass();
* }
- *
*
+ *
+ *
* import java.util.regex.Pattern; // The length of this comment will be taken into consideration
- *
+ *
+ *
* public class ExampleClass {
* public enum Colors {
* RED, GREEN, YELLOW;
@@ -73,7 +73,7 @@
* // but counted towards InnerExampleClass
* }
* }
- *
*
+ *
+ *
* for (
* ; i < j; i++, j--)
- *
*
+ *
+ *
* for (Iterator foo = very.long.line.iterator();
* foo.hasNext();
* )
- *
*
+ *
+ *
* int i; // Multiple whitespaces before comment tokens will be ignored.
* private void foo(int /* whitespaces before and after block-comments will be
* ignored */ i) {
- *
+ *
+ *
* public long toNanos(long d) { return d; } // 2 violations
* public long toMicros(long d) { return d / (C1 / C0); }
- *
*
+ *
+ *
* public MyClass() {} // empty constructor
* public void func() {} // empty method
* public interface Foo {} // empty interface
@@ -42,7 +42,7 @@
* do {} while (i = 1); // empty do-while loop
* Runnable noop = () -> {}; // empty lambda
* public @interface Beta {} // empty annotation type
- *
+ *
+ *
* new Properties() {{
* setProperty("key", "value");
* }};
- *
+ *
+ *
* try {
* k = 5 / i;
* } catch (ArithmeticException ex) {}
- *
+ public @Nullable Long getStartTimeOrNull() { ... }
+
@Override
@Nullable
public String getNameIfPresent() { ... }
-
+
+ public @Nullable Long getStartTimeOrNull() { ... }
+
@Override
@Nullable
public String getNameIfPresent() { ... }
-
+
<!-- required till https://bugs.openjdk.org/browse/JDK-8160601 -->
<module name="SuppressionSingleFilter">
<property name="checks" value="MissingDeprecatedCheck"/>
<property name="files" value="package-info\.java"/>
</module>
-
+
<!-- required till https://bugs.openjdk.org/browse/JDK-8160601 -->
<module name="SuppressionSingleFilter">
<property name="checks" value="MissingDeprecatedCheck"/>
<property name="files" value="package-info\.java"/>
</module>
-
+
public void guessTheOutput()
{
int whichIsWhich = 0;
@@ -30,15 +30,15 @@ public void guessTheOutput()
}
System.out.println("value = " + whichIsWhich);
}
-
+
// if (conditionThatIsNotUsedAnyLonger)
{
System.out.println("unconditional");
}
-
+
public void guessTheOutput()
{
int whichIsWhich = 0;
@@ -30,15 +30,15 @@ public void guessTheOutput()
}
System.out.println("value = " + whichIsWhich);
}
-
+
// if (conditionThatIsNotUsedAnyLonger)
{
System.out.println("unconditional");
}
-
+
int[] a = new int[]
{
1,
2,
3,
};
-
+
return new int[] { 0 };
return new int[] { 0
};
return new int[] {
0 };
-
+
{
100000000000000000000,
200000000000000000000, // OK
@@ -50,34 +50,34 @@ return new int[] {
200000000000000000000,
300000000000000000000, // Just this line added, no other changes
}
-
+
{100000000000000000000,
200000000000000000000,} // Trailing comma not needed, line needs to be modified anyway
{100000000000000000000,
200000000000000000000, // Modified line
300000000000000000000,} // Added line
-
+
{100000000000000000000, // Line cannot be just duplicated to slightly modify entry
}
{100000000000000000000,
100000000000000000001, // More work needed to duplicate
}
-
+
int[] a = new int[]
{
1,
2,
3,
};
-
+
return new int[] { 0 };
return new int[] { 0
};
return new int[] {
0 };
-
+
{
100000000000000000000,
200000000000000000000, // OK
@@ -50,34 +50,34 @@ return new int[] {
200000000000000000000,
300000000000000000000, // Just this line added, no other changes
}
-
+
{100000000000000000000,
200000000000000000000,} // Trailing comma not needed, line needs to be modified anyway
{100000000000000000000,
200000000000000000000, // Modified line
300000000000000000000,} // Added line
-
+
{100000000000000000000, // Line cannot be just duplicated to slightly modify entry
}
{100000000000000000000,
100000000000000000001, // More work needed to duplicate
}
-
+
String a = getParameter("a");
String b = (a==null || a.length()<1) ? null : a.substring(1);
-
+
String a = getParameter("a");
String b = (a==null || a.length()<1) ? null : a.substring(1);
-
+
equals()
:
public boolean equals(Foo obj) {...}
-
+
equals()
does not override the version in the
diff --git a/src/site/xdoc/checks/coding/covariantequals.xml.template b/src/site/xdoc/checks/coding/covariantequals.xml.template
index 3f381e25ee9..852dfd8e715 100644
--- a/src/site/xdoc/checks/coding/covariantequals.xml.template
+++ b/src/site/xdoc/checks/coding/covariantequals.xml.template
@@ -43,9 +43,9 @@
as the type of the parameter to equals()
:
public boolean equals(Foo obj) {...}
-
+
equals()
does not override the version in the
diff --git a/src/site/xdoc/checks/coding/declarationorder.xml b/src/site/xdoc/checks/coding/declarationorder.xml
index 3299eb283ea..a226b7d9c73 100644
--- a/src/site/xdoc/checks/coding/declarationorder.xml
+++ b/src/site/xdoc/checks/coding/declarationorder.xml
@@ -51,13 +51,13 @@
from validation due to the fact that we have Checkstyle's limitations to clearly
detect user intention of fields location and grouping. For example:
public class A {
private double x = 1.0;
private double y = 2.0;
public double slope = x / y; // will be skipped from validation due to forward reference
}
-
+
public class A {
private double x = 1.0;
private double y = 2.0;
public double slope = x / y; // will be skipped from validation due to forward reference
}
-
+
${returnType} set${Name}(${anyType} ${name}) { ... }
-
+
void setTime(long time) { ... }
-
+
class PageBuilder {
PageBuilder setName(String name) { ... }
}
-
+
${returnType} set${Name}(${anyType} ${name}) { ... }
-
+
void setTime(long time) { ... }
-
+
class PageBuilder {
PageBuilder setName(String name) { ... }
}
-
+
java.awt.List
was set as illegal class name, then, code like:
+
-
import java.util.List;
...
List list; //No violation here
-
java.awt.List
was set as illegal class name, then, code like:
-
+
-
import java.util.List;
...
List list; //No violation here
-
String line;
while ((line = bufferedReader.readLine()) != null) { // OK
// process the line
@@ -38,7 +38,7 @@ do {
// process the line
}
while ((line = bufferedReader.readLine()) != null); // OK
-
+
String line;
while ((line = bufferedReader.readLine()) != null) { // OK
// process the line
@@ -38,7 +38,7 @@ do {
// process the line
}
while ((line = bufferedReader.readLine()) != null); // OK
-
+
static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final double SPECIAL_RATIO = 4.0 / 3.0;
static final double SPECIAL_SUM = 1 + Math.E;
static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);
-
+
static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final double SPECIAL_RATIO = 4.0 / 3.0;
static final double SPECIAL_SUM = 1 + Math.E;
static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);
-
+
$ java -jar checkstyle-X.XX-all.jar -T Main.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -95,15 +95,15 @@ CLASS_DEF -> CLASS_DEF [1:0]
| | `--SEMI -> ; [3:31]
| `--RCURLY -> } [4:4]
`--RCURLY -> } [5:0]
-
+
$ java -jar checkstyle-X.XX-all.jar Main.java -b "//METHOD_DEF[./IDENT[@text='sayHello']]"
CLASS_DEF -> CLASS_DEF [1:0]
`--OBJBLOCK -> OBJBLOCK [1:18]
|--METHOD_DEF -> METHOD_DEF [2:4]
-
+
$ java -jar checkstyle-X.XX-all.jar -T Main.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -83,15 +83,15 @@ CLASS_DEF -> CLASS_DEF [1:0]
| | `--SEMI -> ; [3:31]
| `--RCURLY -> } [4:4]
`--RCURLY -> } [5:0]
-
+
$ java -jar checkstyle-X.XX-all.jar Main.java -b "//METHOD_DEF[./IDENT[@text='sayHello']]"
CLASS_DEF -> CLASS_DEF [1:0]
`--OBJBLOCK -> OBJBLOCK [1:18]
|--METHOD_DEF -> METHOD_DEF [2:4]
-
+
for (int i = 0; i < 1; i++) {
i++; // violation
}
-
+
for (int i = 0; i < 10;) {
i++;
}
-
+
for (int a[]={0};a[0] < 10;a[0]++) {
a[0]++; // it will skip this violation
}
-
+
for (int i = 0; i < 1; i++) {
i++; // violation
}
-
+
for (int i = 0; i < 10;) {
i++;
}
-
+
for (int a[]={0};a[0] < 10;a[0]++) {
a[0]++; // it will skip this violation
}
-
+
int[] foo = new int[] {
1,
2
};
-
+
String[] foo = new String[] {
"FOO",
"BAR", // violation
}
-
+
int[] foo = new int[] {
1,
2
};
-
+
String[] foo = new String[] {
"FOO",
"BAR", // violation
}
-
+
Shape s1 = new Square();
System.out.println(s1 instanceof Square); //true
-
+
Shape s2 = new Shape(s1); //using the copy constructor
System.out.println(s2 instanceof Square); //false
-
+
Shape s2 = s1.clone();
System.out.println(s2 instanceof Square); //true
-
+
Shape s1 = new Square();
System.out.println(s1 instanceof Square); //true
-
+
Shape s2 = new Shape(s1); //using the copy constructor
System.out.println(s2 instanceof Square); //false
-
+
Shape s2 = s1.clone();
System.out.println(s2 instanceof Square); //true
-
+
enum Foo1 {
FOO,
BAR;
}
-
+
enum Foo1 {
FOO,
BAR, // violation
}
-
+
enum Foo1 {
FOO,
BAR;
}
-
+
enum Foo1 {
FOO,
BAR, // violation
}
-
+
if (valid())
return false;
else
return true;
-
+
return !valid();
-
+
if (valid())
return false;
else
return true;
-
+
return !valid();
-
+
if (x == "something")
-
+
if ("something".equals(x))
-
+
if (x == "something")
-
+
if ("something".equals(x))
-
+
return (x); // parens around identifier
return (x + 1); // parens around return value
int x = (y / 2 + 1); // parens around assignment rhs
@@ -23,7 +23,7 @@ boolean a = (x > 7 && y > 5) // parens around expression
|| z < 9;
boolean b = (~a) > -27 // parens around ~a
&& (a-- < 30); // parens around expression
-
+
int x = (a + b) + c; // 1st Case
boolean p = true; // 2nd Case
int q = 4;
int r = 3;
if (p == (q <= r)) {}
-
+
int
variables, the parentheses around a + b
@@ -53,7 +53,7 @@ if (p == (q <= r)) {}
boolean a = true, b = true;
boolean c = false, d = false;
if ((a && b) || c) { // violation, unnecessary paren
@@ -72,7 +72,7 @@ if (!(f >= g) // ok
}
if ((++f) > g && a) { // violation, unnecessary paren
}
-
+
return (x); // parens around identifier
return (x + 1); // parens around return value
int x = (y / 2 + 1); // parens around assignment rhs
@@ -23,7 +23,7 @@ boolean a = (x > 7 && y > 5) // parens around expression
|| z < 9;
boolean b = (~a) > -27 // parens around ~a
&& (a-- < 30); // parens around expression
-
+
int x = (a + b) + c; // 1st Case
boolean p = true; // 2nd Case
int q = 4;
int r = 3;
if (p == (q <= r)) {}
-
+
int
variables, the parentheses around a + b
@@ -53,7 +53,7 @@ if (p == (q <= r)) {}
boolean a = true, b = true;
boolean c = false, d = false;
if ((a && b) || c) { // violation, unnecessary paren
@@ -72,7 +72,7 @@ if (!(f >= g) // ok
}
if ((++f) > g && a) { // violation, unnecessary paren
}
-
+
public abstract class Plant {
private String roots;
private String trunk;
@@ -106,11 +106,11 @@ public class Tree extends Plant {
validate();
}
}
-
+
public abstract class Plant {
private String roots;
private String trunk;
@@ -125,7 +125,7 @@ public abstract class Plant {
public abstract void grow();
}
-
+
public abstract class Plant {
private String roots;
private String trunk;
@@ -106,11 +106,11 @@ public class Tree extends Plant {
validate();
}
}
-
+
public abstract class Plant {
private String roots;
private String trunk;
@@ -125,7 +125,7 @@ public abstract class Plant {
public abstract void grow();
}
-
+
public class StringUtils // not final to allow subclassing
{
protected StringUtils() {
@@ -39,7 +39,7 @@ public class StringUtils // not final to allow subclassing
// ...
}
}
-
+
public class StringUtils // not final to allow subclassing
{
protected StringUtils() {
@@ -39,7 +39,7 @@ public class StringUtils // not final to allow subclassing
// ...
}
}
-
+
package java.util.concurrent.locks;
import java.io.File;
@@ -40,7 +40,7 @@ import java.util.concurrent.AbstractExecutorService; //#5
import java.util.concurrent.locks.LockSupport; //#6
import java.util.regex.Pattern; //#7
import java.util.regex.Matcher; //#8
-
+
import com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck;
import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
-
+
import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck;
-
+
package java.util.concurrent.locks;
import java.io.File;
@@ -40,7 +40,7 @@ import java.util.concurrent.AbstractExecutorService; //#5
import java.util.concurrent.locks.LockSupport; //#6
import java.util.regex.Pattern; //#7
import java.util.regex.Matcher; //#8
-
+
import com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck;
import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
-
+
import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck;
-
+
+
-
<!DOCTYPE import-control PUBLIC
"-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
"https://checkstyle.org/dtds/import_control_1_4.dtd">
-
<module name="ImportControl">
<property name="file" value="config/import-control.xml"/>
</module>
-
+
<module name="ImportControl">
<property name="file" value="config/import-control.xml"/>
<property name="path" value="^.*[\\/]src[\\/]main[\\/].*$"/>
</module>
-
+
ClassPath
classes).
<import-control pkg="com.puppycrawl.tools.checkstyle">
<disallow pkg="sun"/>
<allow pkg="com.puppycrawl.tools.checkstyle.api"/>
@@ -173,7 +171,7 @@
<disallow pkg="javax.swing" exact-match="true"/>
</subpackage>
</import-control>
-
+
<import-control pkg="(de.olddomain|de.newdomain)\..*" regex="true">
<subpackage pkg="[^.]+\.dao" regex="true">
<disallow pkg=".*\.ui" regex="true"/>
@@ -194,7 +192,7 @@
<disallow pkg=".*\.(dao|service)" regex="true"/>
</subpackage>
</import-control>
-
+
strategyOnMismatch
property is shown.
@@ -228,13 +226,13 @@
import-control
tag. Here all imports are allowed except
java.awt.Image
and java.io.File
classes.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks"
strategyOnMismatch="allowed">
<disallow class="java.awt.Image"/>
<disallow class="java.io.File"/>
</import-control>
-
+
com.puppycrawl.tools.checkstyle.checks.imports
package.
e>
<import-control pkg="com.puppycrawl.tools.checkstyle.checks"
strategyOnMismatch="allowed">
<subpackage name="imports" strategyOnMismatch="disallowed">
@@ -251,7 +249,7 @@
<allow class="java.io.File"/>
</subpackage>
</import-control>
-
+
strategyOnMismatch
has allowed
or disallowed
@@ -263,7 +261,7 @@
com.puppycrawl.tools.checkstyle.checks.imports
import will be allowed by
default.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow class="java\.awt\.Image" regex="true"/>
<allow class="java\..*\.File" local-only="true" regex="true"/>
@@ -276,7 +274,7 @@
<allow class="javax.util.Date"/>
</subpackage>
</import-control>
-
+
gui
are disallowed to have imports from
@@ -285,7 +283,7 @@
disallowed to have imports that match javax.swing.J*
.
All other imports in the package are allowed.
<import-control pkg="com.mycompany.billing">
<subpackage name="gui" strategyOnMismatch="allowed">
<file name=".*(Panel|View|Dialog)" regex="true">
@@ -297,7 +295,7 @@
</file>
</subpackage>
</import-control>
-
+
java.util.Map
inside subpackage
com.puppycrawl.tools.checkstyle.filters
.
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow pkg="java.util"/>
<subpackage name="filters" >
<disallow class="java.util.Map"/>
</subpackage>
</import-control>
-
+
java.util.stream.Stream
and
java.util.stream.Collectors
are disallowed inside
@@ -332,7 +330,7 @@
but because of <allow pkg="java.util.stream"/>
every import
from java.util.stream
is allowed except described ones.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow pkg="java.util.stream"/>
<subpackage name="imports">
@@ -340,20 +338,20 @@
<disallow class="java.util.stream.Collectors"/>
</subpackage>
</import-control>
-
+
package com.puppycrawl.tools.checkstyle.checks.imports;
import java.util.stream.Stream; // violation here
import java.util.stream.Collectors; // violation here
import java.util.stream.IntStream;
-
+
java.util.Date
, java.util.List
and package sun
.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow pkg=".*" regex="true"/>
<subpackage name="imports">
@@ -362,18 +360,18 @@ import java.util.stream.IntStream;
<disallow pkg="sun"/>
</subpackage>
</import-control>
-
+
java.util
package are allowed
except the java.util.Date
class.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<disallow class="java.util.Date"/>
<allow pkg="java.util"/>
</import-control>
-
+
Notes on regular expressions
java.util.Map
and
java.util.Map.Entry
use the following configuration:
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow class="java.util.Map"/>
<allow class="java.util.Map.Entry"/>
</import-control>
-
+
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow class="java.util.Map"/>
<allow class="java.util.Map.*" regex="true" />
</import-control>
-
+
+
-
<!DOCTYPE import-control PUBLIC
"-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
"https://checkstyle.org/dtds/import_control_1_4.dtd">
-
<module name="ImportControl">
<property name="file" value="config/import-control.xml"/>
</module>
-
+
<module name="ImportControl">
<property name="file" value="config/import-control.xml"/>
<property name="path" value="^.*[\\/]src[\\/]main[\\/].*$"/>
</module>
-
+
ClassPath
classes).
<import-control pkg="com.puppycrawl.tools.checkstyle">
<disallow pkg="sun"/>
<allow pkg="com.puppycrawl.tools.checkstyle.api"/>
@@ -154,7 +152,7 @@
<disallow pkg="javax.swing" exact-match="true"/>
</subpackage>
</import-control>
-
+
<import-control pkg="(de.olddomain|de.newdomain)\..*" regex="true">
<subpackage pkg="[^.]+\.dao" regex="true">
<disallow pkg=".*\.ui" regex="true"/>
@@ -175,7 +173,7 @@
<disallow pkg=".*\.(dao|service)" regex="true"/>
</subpackage>
</import-control>
-
+
strategyOnMismatch
property is shown.
@@ -209,13 +207,13 @@
import-control
tag. Here all imports are allowed except
java.awt.Image
and java.io.File
classes.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks"
strategyOnMismatch="allowed">
<disallow class="java.awt.Image"/>
<disallow class="java.io.File"/>
</import-control>
-
+
com.puppycrawl.tools.checkstyle.checks.imports
package.
e>
<import-control pkg="com.puppycrawl.tools.checkstyle.checks"
strategyOnMismatch="allowed">
<subpackage name="imports" strategyOnMismatch="disallowed">
@@ -232,7 +230,7 @@
<allow class="java.io.File"/>
</subpackage>
</import-control>
-
+
strategyOnMismatch
has allowed
or disallowed
@@ -244,7 +242,7 @@
com.puppycrawl.tools.checkstyle.checks.imports
import will be allowed by
default.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow class="java\.awt\.Image" regex="true"/>
<allow class="java\..*\.File" local-only="true" regex="true"/>
@@ -257,7 +255,7 @@
<allow class="javax.util.Date"/>
</subpackage>
</import-control>
-
+
gui
are disallowed to have imports from
@@ -266,7 +264,7 @@
disallowed to have imports that match javax.swing.J*
.
All other imports in the package are allowed.
<import-control pkg="com.mycompany.billing">
<subpackage name="gui" strategyOnMismatch="allowed">
<file name=".*(Panel|View|Dialog)" regex="true">
@@ -278,7 +276,7 @@
</file>
</subpackage>
</import-control>
-
+
java.util.Map
inside subpackage
com.puppycrawl.tools.checkstyle.filters
.
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow pkg="java.util"/>
<subpackage name="filters" >
<disallow class="java.util.Map"/>
</subpackage>
</import-control>
-
+
java.util.stream.Stream
and
java.util.stream.Collectors
are disallowed inside
@@ -313,7 +311,7 @@
but because of <allow pkg="java.util.stream"/>
every import
from java.util.stream
is allowed except described ones.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow pkg="java.util.stream"/>
<subpackage name="imports">
@@ -321,20 +319,20 @@
<disallow class="java.util.stream.Collectors"/>
</subpackage>
</import-control>
-
+
package com.puppycrawl.tools.checkstyle.checks.imports;
import java.util.stream.Stream; // violation here
import java.util.stream.Collectors; // violation here
import java.util.stream.IntStream;
-
+
java.util.Date
, java.util.List
and package sun
.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<allow pkg=".*" regex="true"/>
<subpackage name="imports">
@@ -343,18 +341,18 @@ import java.util.stream.IntStream;
<disallow pkg="sun"/>
</subpackage>
</import-control>
-
+
java.util
package are allowed
except the java.util.Date
class.
<import-control pkg="com.puppycrawl.tools.checkstyle.checks">
<disallow class="java.util.Date"/>
<allow pkg="java.util"/>
</import-control>
-
+
Notes on regular expressions
java.util.Map
and
java.util.Map.Entry
use the following configuration:
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow class="java.util.Map"/>
<allow class="java.util.Map.Entry"/>
</import-control>
-
+
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow class="java.util.Map"/>
<allow class="java.util.Map.*" regex="true" />
</import-control>
-
+
import static HttpConstants.COLON => HttpConstants
import static HttpHeaders.addHeader => HttpHeaders
import static HttpHeaders.setHeader => HttpHeaders
import static HttpHeaders.Names.DATE => HttpHeaders.Names
-
+
@@ -454,14 +454,14 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.DATE;
import static io.netty.handler.codec.http.HttpConstants.COLON;
import static io.netty.handler.codec.http.HttpHeaders.addHeader;
import static io.netty.handler.codec.http.HttpHeaders.setHeader;
import static io.netty.handler.codec.http.HttpHeaders.Names.DATE; // violation, wrong order, should sort alphabetically
public class Example9 { }
-
+
diff --git a/src/site/xdoc/checks/imports/importorder.xml.template b/src/site/xdoc/checks/imports/importorder.xml.template
index 00fa2948f02..96794ce332b 100644
--- a/src/site/xdoc/checks/imports/importorder.xml.template
+++ b/src/site/xdoc/checks/imports/importorder.xml.template
@@ -242,12 +242,12 @@
import static HttpConstants.COLON => HttpConstants
import static HttpHeaders.addHeader => HttpHeaders
import static HttpHeaders.setHeader => HttpHeaders
import static HttpHeaders.Names.DATE => HttpHeaders.Names
-
+
@@ -278,14 +278,14 @@ import static HttpHeaders.Names.DATE => HttpHeaders.Names
import static io.netty.handler.codec.http.HttpConstants.COLON;
import static io.netty.handler.codec.http.HttpHeaders.addHeader;
import static io.netty.handler.codec.http.HttpHeaders.setHeader;
import static io.netty.handler.codec.http.HttpHeaders.Names.DATE; // violation, wrong order, should sort alphabetically
public class Example9 { }
-
+
diff --git a/src/site/xdoc/checks/javadoc/javadocblocktaglocation.xml b/src/site/xdoc/checks/javadoc/javadocblocktaglocation.xml
index 48bbf558035..c19b299828c 100644
--- a/src/site/xdoc/checks/javadoc/javadocblocktaglocation.xml
+++ b/src/site/xdoc/checks/javadoc/javadocblocktaglocation.xml
@@ -35,11 +35,11 @@
with HTML entity @ or place it inside {@code }
,
for example:
-
/**
* @serial literal in {@code @serial} Javadoc tag.
*/
-
+
{@code }
,
for example:
-
/**
* @serial literal in {@code @serial} Javadoc tag.
*/
-
+
/** Summary text.
* More details.
*/
public void method();
-
+
/**
* Summary text.
* More details.
*/
public void method();
-
+
/***
* Some text.
*/
@@ -62,7 +62,7 @@ public void method();
/** **
* Some text.
*/
-
+
@@ -52,7 +52,7 @@ public void method();
Documentation Comment Specification permits leading asterisks on the first line.
For these Javadoc comments:
-
/** Summary text.
* More details.
*/
public void method();
-
+
/**
* Summary text.
* More details.
*/
public void method();
-
+
/***
* Some text.
*/
@@ -62,7 +62,7 @@ public void method();
/** **
* Some text.
*/
-
+
/** {@inheritDoc} */
public int checkReturnTag(final int aTagIndex,
JavadocTag[] aTags,
int aLineNo)
-
+
/** {@inheritDoc} */
public int checkReturnTag(final int aTagIndex,
JavadocTag[] aTags,
int aLineNo)
-
+
allowMissingPropertyJavadoc
,
the methods must match exactly the structures below.
-
public void setNumber(final int number)
{
mNumber = number;
@@ -46,7 +46,7 @@ public boolean isSomething()
{
return false;
}
-
+
allowMissingPropertyJavadoc
,
the methods must match exactly the structures below.
-
public void setNumber(final int number)
{
mNumber = number;
@@ -46,7 +46,7 @@ public boolean isSomething()
{
return false;
}
-
+
if ((condition1 && condition2)
|| (condition3 && condition4) // line wrap with bigger indentation
||!(condition5 && condition6)) { // line wrap with bigger indentation
@@ -44,7 +44,7 @@ if ((condition1 && condition2)
return c.doSome(); // basic offset
});
}
-
+
if ((condition1 && condition2)
|| (condition3 && condition4) // line wrap with bigger indentation
||!(condition5 && condition6)) { // line wrap with bigger indentation
@@ -44,7 +44,7 @@ if ((condition1 && condition2)
return c.doSome(); // basic offset
});
}
-
+
@@ -32,4 +32,5 @@ ForbidWildcardAsReturnTypeCheck.returnTypeClassNamesIgnoreRegex
PublicReferenceToPrivateTypeCheck.name = Public Reference To Private Type
@@ -30,7 +30,7 @@ StaticMethodCandidateCheck.name = Static Method Candidate
\ No newline at end of file
+StaticMethodCandidateCheck.desc = Checks whether private methods should be declared as static.
+StaticMethodCandidateCheck.skippedMethods = Method names to skip during the check.
-
+
@@ -32,4 +32,5 @@ ForbidWildcardAsReturnTypeCheck.returnTypeClassNamesIgnoreRegex
PublicReferenceToPrivateTypeCheck.name = Public Reference To Private Type
@@ -30,7 +30,7 @@ StaticMethodCandidateCheck.name = Static Method Candidate
\ No newline at end of file
+StaticMethodCandidateCheck.desc = Checks whether private methods should be declared as static.
+StaticMethodCandidateCheck.skippedMethods = Method names to skip during the check.
-
+
a = b + c; // Some insightful comment
d = e / f; // Another comment for this line
-
+
a = b + c; // Some insightful comment
d = e / f; // Another comment for this line
-
+
messages.properties
messages_fr.properties
messages_es.properties
-
+
hello=Hello
@@ -140,10 +140,10 @@ messages_es.properties // violation 'Key 'cancel', 'name' and 'hello' missing.'
</module>
ButtonLabels.properties
ButtonLabels_fr.properties
-
+
hello=Hello
@@ -173,10 +173,10 @@ ButtonLabels_fr.properties // violation 'Key 'cancel' is missing.'
</module>
messages_home.properties
messages_home.translations
-
+
hello=Hello
diff --git a/src/site/xdoc/checks/misc/translation.xml.template b/src/site/xdoc/checks/misc/translation.xml.template
index d73a0f0490d..f3a14f159a2 100644
--- a/src/site/xdoc/checks/misc/translation.xml.template
+++ b/src/site/xdoc/checks/misc/translation.xml.template
@@ -72,11 +72,11 @@
modifier is explicitly coded and not
implicitly added by the compiler.
-
messages.properties
messages_fr.properties
messages_es.properties
-
+
ButtonLabels.properties
ButtonLabels_fr.properties
-
+
messages_home.properties
messages_home.translations
-
+
public final class Person {
enum Age { // violation
CHILD, ADULT
}
}
-
+
static
modifier is explicitly coded and not
implicitly added by the compiler.
public final class Person {
enum Age { // violation
CHILD, ADULT
}
}
-
+
public
and static
modifiers
are explicitly coded and not implicitly added by the compiler.
public interface AddressFactory {
// check enforces code contains "public static final"
public static final String UNKNOWN = "Unknown";
@@ -67,7 +67,7 @@ public interface AddressFactory {
return createAddress(OTHER, OTHER);
}
}
-
+
public
and static
modifiers
are explicitly coded and not implicitly added by the compiler.
public interface AddressFactory {
// check enforces code contains "public static final"
public static final String UNKNOWN = "Unknown";
@@ -67,7 +67,7 @@ public interface AddressFactory {
return createAddress(OTHER, OTHER);
}
}
-
+
public enum EnumClass {
FIELD_1,
FIELD_2 {
@@ -98,7 +98,7 @@ public enum EnumClass {
public void method1() {}
public final void method2() {} // no violation expected
}
-
+
public class PublicClass {
public PublicClass() {} // OK
}
@@ -127,14 +127,14 @@ public class PublicClass {
class PackagePrivateClass {
public PackagePrivateClass() {} // violation expected
}
-
+
package a;
public class ClassExample {
protected class ProtectedInnerClass {
@@ -147,7 +147,7 @@ import a.ClassExample;
public class ClassExtending extends ClassExample {
ProtectedInnerClass pc = new ProtectedInnerClass();
}
-
+
public enum EnumClass {
FIELD_1,
FIELD_2 {
@@ -98,7 +98,7 @@ public enum EnumClass {
public void method1() {}
public final void method2() {} // no violation expected
}
-
+
public class PublicClass {
public PublicClass() {} // OK
}
@@ -127,14 +127,14 @@ public class PublicClass {
class PackagePrivateClass {
public PackagePrivateClass() {} // violation expected
}
-
+
package a;
public class ClassExample {
protected class ProtectedInnerClass {
@@ -147,7 +147,7 @@ import a.ClassExample;
public class ClassExtending extends ClassExample {
ProtectedInnerClass pc = new ProtectedInnerClass();
}
-
+
/var/tmp/Test.java // violation, a file must not be empty.
-
+
/var/tmp/Test.java // violation, a file must not be empty.
-
+
import java.util.regex.Pattern; // The length of this comment will be taken into consideration
-
+
import java.util.regex.Pattern; // The length of this comment will be taken into consideration
-
+
public class ExampleClass {
public enum Colors {
RED, GREEN, YELLOW;
@@ -50,7 +50,7 @@ public class ExampleClass {
// but counted towards InnerExampleClass
}
}
-
+
public class ExampleClass {
public enum Colors {
RED, GREEN, YELLOW;
@@ -50,7 +50,7 @@ public class ExampleClass {
// but counted towards InnerExampleClass
}
}
-
+
for (
; i < j; i++, j--)
-
+
for (
; i < j; i++, j--)
-
+
for (Iterator foo = very.long.line.iterator();
foo.hasNext();
)
-
+
for (Iterator foo = very.long.line.iterator();
foo.hasNext();
)
-
+
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import static java.math.BigInteger.ZERO;
-
+
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import static java.math.BigInteger.ZERO;
-
+
for ( ; i < j; i++, j--) // no check after left parenthesis
for (Iterator it = xs.iterator(); it.hasNext(); ) // no check before right parenthesis
try (Closeable resource = acquire(); ) // no check before right parenthesis
-
+
for ( ; i < j; i++, j--) // no check after left parenthesis
for (Iterator it = xs.iterator(); it.hasNext(); ) // no check before right parenthesis
try (Closeable resource = acquire(); ) // no check before right parenthesis
-
+
validateComments
to false will ignore cases like:
-
int i; // Multiple whitespaces before comment tokens will be ignored.
private void foo(int /* whitespaces before and after block-comments will be
ignored */ i) {
-
+
public long toNanos(long d) { return d; } // 2 violations
public long toMicros(long d) { return d / (C1 / C0); }
-
+
validateComments
to false will ignore cases like:
-
int i; // Multiple whitespaces before comment tokens will be ignored.
private void foo(int /* whitespaces before and after block-comments will be
ignored */ i) {
-
+
public long toNanos(long d) { return d; } // 2 violations
public long toMicros(long d) { return d / (C1 / C0); }
-
+
+public MyClass() {} // empty constructor
public void func() {} // empty method
public interface Foo {} // empty interface
public class Foo {} // empty class
@@ -25,7 +26,7 @@ for (int i = 1; i > 1; i++) {} // empty for loop
do {} while (i = 1); // empty do-while loop
Runnable noop = () -> {}; // empty lambda
public @interface Beta {} // empty annotation type
-
+
@@ -36,23 +37,19 @@ public @interface Beta {} // empty annotation type
properties.
+
-
new Properties() {{
setProperty("key", "value");
}};
-
+
-
try {
k = 5 / i;
} catch (ArithmeticException ex) {}
-
+public MyClass() {} // empty constructor
public void func() {} // empty method
public interface Foo {} // empty interface
public class Foo {} // empty class
@@ -25,7 +26,7 @@ for (int i = 1; i > 1; i++) {} // empty for loop
do {} while (i = 1); // empty do-while loop
Runnable noop = () -> {}; // empty lambda
public @interface Beta {} // empty annotation type
-
+
@@ -36,23 +37,19 @@ public @interface Beta {} // empty annotation type
properties.
+
-
new Properties() {{
setProperty("key", "value");
}};
-
+
-
try {
k = 5 / i;
} catch (ArithmeticException ex) {}
-
config/suppressions.xml
:
<module name="SuppressionFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="optional" value="false"/>
</module>
-
+
SuppressionFilter
to
@@ -146,7 +146,7 @@
and 'Missing a Javadoc comment'
violations
for all lines and files:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
@@ -162,64 +162,64 @@
lines="221"/>
<suppress message="Missing a Javadoc comment"/>
</suppressions>
-
+
<suppress id="stringEqual" files="SomeTestCode.java"/>
-
+
<suppress files="[/\\]\..+" checks=".*"/>
-
+
<suppress files="[/\\]target[/\\]" checks=".*"/>
-
+
<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/>
-
+
<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/>
-
+
<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$"
checks=".*"/>
-
+
<suppress checks=".*" files="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/>
-
+
<suppress checks="FileLength"
files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
-
+
<suppress message="Name 'log' must match pattern"/>
-
+
diff --git a/src/site/xdoc/filters/suppressionfilter.xml.template b/src/site/xdoc/filters/suppressionfilter.xml.template
index d1601d40d83..ce252e048ec 100644
--- a/src/site/xdoc/filters/suppressionfilter.xml.template
+++ b/src/site/xdoc/filters/suppressionfilter.xml.template
@@ -110,12 +110,12 @@
with suppressions
file
config/suppressions.xml
:
-
<module name="SuppressionFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="optional" value="false"/>
</module>
-
+
SuppressionFilter
to
@@ -127,7 +127,7 @@
and 'Missing a Javadoc comment'
violations
for all lines and files:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
@@ -143,64 +143,64 @@
lines="221"/>
<suppress message="Missing a Javadoc comment"/>
</suppressions>
-
+
<suppress id="stringEqual" files="SomeTestCode.java"/>
-
+
<suppress files="[/\\]\..+" checks=".*"/>
-
+
<suppress files="[/\\]target[/\\]" checks=".*"/>
-
+
<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/>
-
+
<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/>
-
+
<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$"
checks=".*"/>
-
+
<suppress checks=".*" files="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/>
-
+
<suppress checks="FileLength"
files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
-
+
<suppress message="Name 'log' must match pattern"/>
-
+
diff --git a/src/site/xdoc/filters/suppressionxpathfilter.xml b/src/site/xdoc/filters/suppressionxpathfilter.xml
index 3f4144a6289..a6f154916f7 100644
--- a/src/site/xdoc/filters/suppressionxpathfilter.xml
+++ b/src/site/xdoc/filters/suppressionxpathfilter.xml
@@ -129,12 +129,12 @@
with suppressions
file
config/suppressions.xml
:
-
<module name="SuppressionXpathFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="optional" value="false"/>
</module>
-
+
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
@@ -216,60 +216,60 @@
files="FileOne.java,FileTwo.java"
query="//METHOD_DEF[./IDENT[@text='sayHelloWorld']]"/>
</suppressions>
-
+
<suppress-xpath checks=".*" query="/PACKAGE_DEF"/>
-
+
<suppress-xpath checks=".*" query="(//VARIABLE_DEF)[1]/.."/>
-
+
<suppress-xpath checks=".*" query="//CLASS_DEF | //METHOD_DEF"/>
-
+
<suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='getSomeVar'
or @text='setSomeVar']]"/>
-
+
<suppress-xpath checks=".*" query="//CLASS_DEF[@text='TestClass']
//METHOD_DEF[./IDENT[@text='testMethod']]
//VARIABLE_DEF[./IDENT[@text='testVariable']]"/>
-
+
LeftCurly
check will be suppressed
for classes with name Main or for methods with name calculate.
<suppress-xpath checks="LeftCurly" query="//CLASS_DEF[./IDENT[@text='Main']]//*
| //METHOD_DEF[./IDENT[@text='calculate']]/*"/>
-
+
RequireThis
violations for
variable age inside changeAge method.
<suppress-xpath checks="RequireThis"
query="//CLASS_DEF[./IDENT[@text='InputTest']]
//METHOD_DEF[./IDENT[@text='changeAge']]//ASSIGN/IDENT[@text='age']"/>
-
-
public class InputTest {
private int age = 23;
@@ -277,7 +277,7 @@ public class InputTest {
age = 24; // violation will be suppressed
}
}
-
+
IllegalThrows
violations only for methods with name
throwsMethod and only for RuntimeException
exceptions.
@@ -286,12 +286,12 @@ public class InputTest {
METHOD_DEF
and name throwsMethod. Please read more about xpath axes at
W3Schools Xpath Axes.
<suppress-xpath checks="IllegalThrows" query="//LITERAL_THROWS
/IDENT[@text='RuntimeException' and
./ancestor::METHOD_DEF[./IDENT[@text='throwsMethod']]]"/>
-
-
public class InputTest {
public void throwsMethod() throws RuntimeException { // violation will be suppressed
}
@@ -299,7 +299,7 @@ public class InputTest {
public void sampleMethod() throws RuntimeException { // will throw violation here
}
}
-
+
descendant-or-self
axis iterates through current node and
@@ -307,21 +307,21 @@ public class InputTest {
Please read more about xpath syntax at
W3Schools Xpath Syntax.
<suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='legacyMethod']]
/descendant-or-self::node()"/>
-
+
wordCount
in following code:
public class InputTest {
private int wordCount = 11;
}
-
+
$ java -jar checkstyle-X.XX-all.jar -t InputTest.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -341,28 +341,28 @@ CLASS_DEF -> CLASS_DEF [1:0]
| | `--NUM_INT -> 11 [2:28]
| `--SEMI -> ; [2:30]
`--RCURLY -> } [3:0]
-
+
VARIABLE_DEF
node refers to variable declaration statement and has child node with token type
IDENT
which is used for storing class, method, variable names.
<suppress-xpath checks="." query="//VARIABLE_DEF[
./IDENT[@text='wordCount']]"/>
-
+
VARIABLE_DEF
node is
responsible for storing variable value - NUM_INT
with value 11.String, char, float, double, int, long
data types:
<suppress-xpath checks="." query="//VARIABLE_DEF[.//NUM_INT[@text=11]]"/>
-
+
public class InputTest {
@Generated("first") // should not be suppressed
public void test1() {
@@ -372,9 +372,9 @@ public class InputTest {
public void test2() {
}
}
-
+
$ java -jar checkstyle-X.XX-all.jar -t InputTest.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -420,16 +420,16 @@ CLASS_DEF -> CLASS_DEF [1:0]
| `--SLIST -> { [7:24]
| `--RCURLY -> } [8:4]
`--RCURLY -> } [9:0]
-
+
ANNOTATION -> ANNOTATION [6:4]
has direct child
IDENT -> Generated [6:5]
,
therefore can be queried by IDENT
value:
<suppress-xpath checks="." query="//METHOD_DEF[
.//ANNOTATION/IDENT[@text='Generated']]//*"/>
-
+
@Generated
. In order to suppress methods with
@@ -438,10 +438,10 @@ CLASS_DEF -> CLASS_DEF [1:0]
STRING_LITERAL
. Use the following query to suppress methods with
@Generated("second")
annotation:
<suppress-xpath checks="." query="//METHOD_DEF[.//ANNOTATION[
./IDENT[@text='Generated'] and ./EXPR/STRING_LITERAL[@text='second']]]//*"/>
-
+
diff --git a/src/site/xdoc/filters/suppressionxpathfilter.xml.template b/src/site/xdoc/filters/suppressionxpathfilter.xml.template
index 76c9bb5ef5e..2dd3bace2b5 100644
--- a/src/site/xdoc/filters/suppressionxpathfilter.xml.template
+++ b/src/site/xdoc/filters/suppressionxpathfilter.xml.template
@@ -110,12 +110,12 @@
with suppressions
file
config/suppressions.xml
:
-
<module name="SuppressionXpathFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="optional" value="false"/>
</module>
-
+
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
@@ -197,60 +197,60 @@
files="FileOne.java,FileTwo.java"
query="//METHOD_DEF[./IDENT[@text='sayHelloWorld']]"/>
</suppressions>
-
+
<suppress-xpath checks=".*" query="/PACKAGE_DEF"/>
-
+
<suppress-xpath checks=".*" query="(//VARIABLE_DEF)[1]/.."/>
-
+
<suppress-xpath checks=".*" query="//CLASS_DEF | //METHOD_DEF"/>
-
+
<suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='getSomeVar'
or @text='setSomeVar']]"/>
-
+
<suppress-xpath checks=".*" query="//CLASS_DEF[@text='TestClass']
//METHOD_DEF[./IDENT[@text='testMethod']]
//VARIABLE_DEF[./IDENT[@text='testVariable']]"/>
-
+
LeftCurly
check will be suppressed
for classes with name Main or for methods with name calculate.
<suppress-xpath checks="LeftCurly" query="//CLASS_DEF[./IDENT[@text='Main']]//*
| //METHOD_DEF[./IDENT[@text='calculate']]/*"/>
-
+
RequireThis
violations for
variable age inside changeAge method.
<suppress-xpath checks="RequireThis"
query="//CLASS_DEF[./IDENT[@text='InputTest']]
//METHOD_DEF[./IDENT[@text='changeAge']]//ASSIGN/IDENT[@text='age']"/>
-
-
public class InputTest {
private int age = 23;
@@ -258,7 +258,7 @@ public class InputTest {
age = 24; // violation will be suppressed
}
}
-
+
IllegalThrows
violations only for methods with name
throwsMethod and only for RuntimeException
exceptions.
@@ -267,12 +267,12 @@ public class InputTest {
METHOD_DEF
and name throwsMethod. Please read more about xpath axes at
W3Schools Xpath Axes.
<suppress-xpath checks="IllegalThrows" query="//LITERAL_THROWS
/IDENT[@text='RuntimeException' and
./ancestor::METHOD_DEF[./IDENT[@text='throwsMethod']]]"/>
-
-
public class InputTest {
public void throwsMethod() throws RuntimeException { // violation will be suppressed
}
@@ -280,7 +280,7 @@ public class InputTest {
public void sampleMethod() throws RuntimeException { // will throw violation here
}
}
-
+
descendant-or-self
axis iterates through current node and
@@ -288,21 +288,21 @@ public class InputTest {
Please read more about xpath syntax at
W3Schools Xpath Syntax.
<suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='legacyMethod']]
/descendant-or-self::node()"/>
-
+
wordCount
in following code:
public class InputTest {
private int wordCount = 11;
}
-
+
$ java -jar checkstyle-X.XX-all.jar -t InputTest.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -322,28 +322,28 @@ CLASS_DEF -> CLASS_DEF [1:0]
| | `--NUM_INT -> 11 [2:28]
| `--SEMI -> ; [2:30]
`--RCURLY -> } [3:0]
-
+
VARIABLE_DEF
node refers to variable declaration statement and has child node with token type
IDENT
which is used for storing class, method, variable names.
<suppress-xpath checks="." query="//VARIABLE_DEF[
./IDENT[@text='wordCount']]"/>
-
+
VARIABLE_DEF
node is
responsible for storing variable value - NUM_INT
with value 11.String, char, float, double, int, long
data types:
<suppress-xpath checks="." query="//VARIABLE_DEF[.//NUM_INT[@text=11]]"/>
-
+
public class InputTest {
@Generated("first") // should not be suppressed
public void test1() {
@@ -353,9 +353,9 @@ public class InputTest {
public void test2() {
}
}
-
+
$ java -jar checkstyle-X.XX-all.jar -t InputTest.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
@@ -401,16 +401,16 @@ CLASS_DEF -> CLASS_DEF [1:0]
| `--SLIST -> { [7:24]
| `--RCURLY -> } [8:4]
`--RCURLY -> } [9:0]
-
+
ANNOTATION -> ANNOTATION [6:4]
has direct child
IDENT -> Generated [6:5]
,
therefore can be queried by IDENT
value:
<suppress-xpath checks="." query="//METHOD_DEF[
.//ANNOTATION/IDENT[@text='Generated']]//*"/>
-
+
@Generated
. In order to suppress methods with
@@ -419,10 +419,10 @@ CLASS_DEF -> CLASS_DEF [1:0]
STRING_LITERAL
. Use the following query to suppress methods with
@Generated("second")
annotation:
<suppress-xpath checks="." query="//METHOD_DEF[.//ANNOTATION[
./IDENT[@text='Generated'] and ./EXPR/STRING_LITERAL[@text='second']]]//*"/>
-
+
From 36e8fb6584d6c33e73c1d249cafb0b07bb79e5da Mon Sep 17 00:00:00 2001
From: Roman Ivanov
", "", "",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "");
+
+ @Override
+ public void execute(Sink sink, MacroRequest request) throws MacroExecutionException {
+ final Path modulePath = Paths.get((String) request.getParameter("modulePath"));
+ final String moduleName = CommonUtil.getFileNameWithoutExtension(modulePath.toString());
+
+ final Set
getSpecifiedPropertyVersion(String propertyName,
* @param moduleJavadoc the javadoc of module.
* @return the Optional of javadoc node part of the property.
*/
- private static Optional
VARIABLE_DEF
would match
- them.
+ scope of this check even though a token type like VARIABLE_DEF
would match them.
- public @Nullable Long getStartTimeOrNull() { ... }
+public @Nullable Long getStartTimeOrNull() { ... }
-@Override
-@Nullable
+@Override
+@Nullable
public String getNameIfPresent() { ... }
VARIABLE_DEF
would match
- them.
-
- public @Nullable Long getStartTimeOrNull() { ... }
-
-@Override
-@Nullable
-public String getNameIfPresent() { ... }
-