516 lines
18 KiB
XML
516 lines
18 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<document xmlns="http://maven.apache.org/XDOC/2.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
|
|
|
|
<properties>
|
|
<title>Annotations</title>
|
|
<author>Checkstyle Development Team</author>
|
|
</properties>
|
|
|
|
<body>
|
|
<section name="AnnotationUseStyle">
|
|
<subsection name="Description">
|
|
<p> This check controls the style with the usage of annotations.
|
|
</p>
|
|
</subsection>
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>elementStyle</td>
|
|
<td>
|
|
<p>
|
|
Defines the annotation element styles.
|
|
</p>
|
|
</td>
|
|
<td>
|
|
<a href="property_types.html#elementStyle">element style</a>
|
|
</td>
|
|
<td>
|
|
<code>compact_no_array</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>closingParens</td>
|
|
<td>
|
|
Defines the policy for ending parenthesis.
|
|
</td>
|
|
<td>
|
|
<a href="property_types.html#closingParens">closing parens</a>
|
|
</td>
|
|
<td>
|
|
<code>never</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>trailingArrayComma</td>
|
|
<td>
|
|
Defines the policy for trailing comma in arrays.
|
|
</td>
|
|
<td>
|
|
<a href="property_types.html#trailingArrayComma">trailing comma</a>
|
|
</td>
|
|
<td>
|
|
<code>never</code>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
<subsection name="Examples">
|
|
<p> To configure the check:</p>
|
|
<source> <module name="AnnotationUseStyle"/>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check to enforce an
|
|
<code>expanded</code> style, with a
|
|
trailing array comma set to <code>never</code>
|
|
and always including the closing
|
|
parenthesis.
|
|
</p>
|
|
<source>
|
|
<module name="AnnotationUseStyle">
|
|
<property name="elementStyle" value="expanded"/>
|
|
<property name="trailingArrayComma" value="never"/>
|
|
<property name="closingParens" value="always"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
</section>
|
|
|
|
|
|
<section name="MissingDeprecated">
|
|
<subsection name="Description">
|
|
<p> Verifies that both the java.lang.Deprecated annotation is
|
|
present and the @deprecated Javadoc tag is present when
|
|
either is present.</p>
|
|
</subsection>
|
|
<subsection name="Examples">
|
|
<p> To configure the check:</p>
|
|
<source> <module name="MissingDeprecated"/>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="MissingOverride">
|
|
<subsection name="Description">
|
|
<p> Verifies that the java.lang.Override annotation is present
|
|
when the {@inheritDoc} javadoc tag is present.</p>
|
|
</subsection>
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>javaFiveCompatibility</td>
|
|
<td>
|
|
When this property is true this check will only check
|
|
classes, interfaces, etc. that do not contain the extends
|
|
or implements keyword or are not anonymous classes. This
|
|
means it only checks methods overridden from
|
|
<code>java.lang.Object</code>
|
|
<b>Java 5 Compatibility mode severely limits this
|
|
check. It is recommended to only use it on Java 5 source </b>
|
|
</td>
|
|
<td>
|
|
<a href="property_types.html#boolean">boolean</a>
|
|
</td>
|
|
<td>
|
|
<code>false</code>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
<subsection name="Examples">
|
|
<p> To configure the check:</p>
|
|
<source> <module name="MissingOverride"/>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check for the <code>javaFiveCompatibility</code>
|
|
mode:
|
|
</p>
|
|
<source>
|
|
<module name="MissingOverride">
|
|
<property name="javaFiveCompatibility"
|
|
value="true"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="PackageAnnotation">
|
|
<subsection name="Description">
|
|
<p> This check makes sure that all package annotations are in the
|
|
package-info.java file.
|
|
</p>
|
|
<p>
|
|
According to the Java JLS 3rd ed.
|
|
</p>
|
|
|
|
<p>
|
|
The JLS does not enforce the placement of package annotations.
|
|
This placement may vary based on implementation. The JLS
|
|
does highly recommend that all package annotations are
|
|
placed in the package-info.java file.
|
|
|
|
See <a
|
|
href="http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html">
|
|
Java Language specification, sections 7.4.1.1</a>.
|
|
</p>
|
|
</subsection>
|
|
<subsection name="Examples">
|
|
<p> To configure the check:</p>
|
|
<source> <module name="PackageAnnotation"/>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="SuppressWarnings">
|
|
<subsection name="Description">
|
|
<p> This check allows you to specify what warnings that
|
|
SuppressWarnings is not allowed to suppress.
|
|
You can also specify a list of TokenTypes that
|
|
the configured warning(s) cannot be suppressed on.</p>
|
|
|
|
<p>
|
|
Limitations: This check does not consider conditionals
|
|
inside the SuppressWarnings annotation. <br/>
|
|
For example: @SuppressWarnings((false) ? (true) ? "unchecked" : "foo" : "unused")
|
|
According to the above example, the "unused" warning is being suppressed
|
|
not the "unchecked" or "foo" warnings. All of these warnings will be
|
|
considered and matched against regardless of what the conditional
|
|
evaluates to.
|
|
</p>
|
|
</subsection>
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>
|
|
The warnings property is a regex pattern. Any warning
|
|
being suppressed matching this pattern will be flagged.
|
|
</td>
|
|
<td>
|
|
<a href="property_types.html#regexp">regexp</a>
|
|
</td>
|
|
<td>
|
|
<code>^$|^\s+$</code>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>tokens to check</td>
|
|
|
|
<td>
|
|
subset of tokens
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">ENUM_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">ANNOTATION_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF">ANNOTATION_FIELD_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">ENUM_CONSTANT_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>
|
|
</td>
|
|
|
|
<td>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">ENUM_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">ANNOTATION_DEF</a>,
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF">ANNOTATION_FIELD_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">ENUM_CONSTANT_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>
|
|
<a
|
|
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
</subsection>
|
|
<subsection name="Examples">
|
|
<p> To configure the check:</p>
|
|
<source> <module name="SuppressWarnings"/>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check so that the "unchecked" and "unused"
|
|
warnings cannot be suppressed on anything
|
|
but variable and parameter declarations.
|
|
</p>
|
|
<source>
|
|
<module name="SuppressWarnings">
|
|
<property name="format"
|
|
value="^unchecked$|^unused$"/>
|
|
<property name="tokens"
|
|
value="
|
|
CLASS_DEF,INTERFACE_DEF,ENUM_DEF,
|
|
ANNOTATION_DEF,ANNOTATION_FIELD_DEF,
|
|
ENUM_CONSTANT_DEF,METHOD_DEF,CTOR_DEF
|
|
"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="SuppressWarningsHolder">
|
|
<subsection name="Description">
|
|
<p>
|
|
Maintains a set of check suppressions from
|
|
<code>@SuppressWarnings</code> annotations. It allows to
|
|
prevent Checkstyle from reporting errors from parts of code
|
|
that were annotated with <code>@SuppressWarnings</code> and
|
|
using name of the check to be excluded. You can also define
|
|
aliases for check names that need to be suppressed.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>aliasList</td>
|
|
<td>Aliases for check names that can be used in code within <code>SuppressWarnings</code></td>
|
|
<td><a href="property_types.html#string">String</a> in a format of comma separated attribute=value entries.
|
|
The attribute is the fully qualified name of the Check and value is its alias.</td>
|
|
<td>null</td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>To prevent <code>FooCheck</code> errors from being reported write:</p>
|
|
<source>
|
|
@SuppressWarnings("foo") interface I { }
|
|
@SuppressWarnings("foo") enum E { }
|
|
@SuppressWarnings("foo") InputSuppressWarningsFilter() { }
|
|
</source>
|
|
<br />
|
|
<p>Some real check examples:</p>
|
|
<p>This will prevent from invocation of the MemberNameCheck:
|
|
<source>
|
|
@SuppressWarnings({"membername"})
|
|
private int J;
|
|
</source>
|
|
</p>
|
|
|
|
<p>You can also use a <code>checkstyle</code> prefix to prevent compiler from processing this annotations.
|
|
For example this will prevent ConstantNameCheck
|
|
<source>
|
|
@SuppressWarnings("checkstyle:constantname")
|
|
private static final int m = 0;
|
|
</source>
|
|
</p>
|
|
|
|
<p>The general rule is that the argument of the <code>@SuppressWarnings</code> will be matched against class name of the checker in lower case
|
|
and without <code>Check</code> suffix if present</p>
|
|
<p>If <code>aliasList</code> property was provided you can use your own names e.g below code will work if there was provided a <code>ParameterNumberCheck=paramnum</code> in the <code>aliasList</code>
|
|
<source>
|
|
@SuppressWarnings("paramnum")
|
|
public void needsLotsOfParameters(@SuppressWarnings("unused") int a,
|
|
int b, int c, int d, int e, int f, int g, int h) {
|
|
...
|
|
}
|
|
</source>
|
|
</p>
|
|
|
|
</subsection>
|
|
|
|
|
|
<subsection name="Package">
|
|
<p> com.puppycrawl.tools.checkstyle.checks </p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
|
|
</subsection>
|
|
|
|
</section>
|
|
|
|
<section name="AnnotationLocation">
|
|
<subsection name="Description">
|
|
<p>
|
|
Check location of annotation on language elements.
|
|
By default, Check enforce to locate annotations immediately
|
|
after documentation block and before target element, annotation should be located on separate line from target element.
|
|
</p>
|
|
<p>
|
|
Example:
|
|
</p>
|
|
<source>
|
|
@Override
|
|
@Nullable
|
|
public String getNameIfPresent() { ... }
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>allowSamelineMultipleAnnotations</td>
|
|
<td>To allow annotation to be located on the same line as target element.</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>allowSamelineSingleParameterlessAnnotation</td>
|
|
<td>To allow single prameterless annotation to be located on the same line as target element.</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><code>true</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>allowSamelineParameterizedAnnotation</td>
|
|
<td>To allow parameterized annotation to be located on the same line as target element.</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
Example to allow single parameterless annotation on the same line
|
|
</p>
|
|
<source>
|
|
@Override public int hashCode() { ... }
|
|
</source>
|
|
<p>
|
|
Use following configuration:
|
|
</p>
|
|
<source>
|
|
<module name="AnnotationLocation">
|
|
<property name="allowSamelineMultipleAnnotations" value="false"/>
|
|
<property name="allowSamelineSingleParameterlessAnnotation" value="true"/>
|
|
<property name="allowSamelineParameterizedAnnotation" value="false"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
Example to allow multiple parameterized annotations on the same line
|
|
</p>
|
|
<source>
|
|
@SuppressWarnings("deprecation") @Mock DataLoader loader;
|
|
</source>
|
|
<p>
|
|
Use following configuration:
|
|
</p>
|
|
<source>
|
|
<module name="AnnotationLocation">
|
|
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
|
<property name="allowSamelineSingleParameterlessAnnotation" value="true"/>
|
|
<property name="allowSamelineParameterizedAnnotation" value="true"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
Example to allow multiple parameterless annotations on the same line
|
|
</p>
|
|
<source>
|
|
@Partial @Mock DataLoader loader;
|
|
</source>
|
|
<p>
|
|
Use following configuration:
|
|
</p>
|
|
<source>
|
|
<module name="AnnotationLocation">
|
|
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
|
<property name="allowSamelineSingleParameterlessAnnotation" value="true"/>
|
|
<property name="allowSamelineParameterizedAnnotation" value="false"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
</section>
|
|
</body>
|
|
</document>
|