AnnotationUseStyle

Description

This check controls the style with the usage of annotations.

Properties

name description type default value
elementStyle

Defines the annotation element styles.

element style compact_no_array
closingParens Defines the policy for ending parenthesis. closing parens never
trailingArrayComma Defines the policy for trailing comma in arrays. trailing comma never

Examples

To configure the check:

 <module name="AnnotationUseStyle"/>
        

To configure the check to enforce an expanded style, with a trailing array comma set to never and always including the closing parenthesis.

 <module name="AnnotationUseStyle">
     <property name="ElementStyle"
         value="expanded"/>
      <property name="TrailingArrayComma"
          value="never"/>
     <property name="ClosingParens"
         value="always"/>
  </module>
        

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker

MissingDeprecated

Description

Verifies that both the java.lang.Deprecated annotation is present and the @deprecated Javadoc tag is present when either is present.

Examples

To configure the check:

 <module name="MissingDeprecated"/>
        

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker

MissingOverride

Description

Verifies that the java.lang.Override annotation is present when the {@inheritDoc} javadoc tag is present.

Properties

name description type default value
javaFiveCompatibility 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 java.lang.Object Java 5 Compatibility mode severely limits this check. It is recommended to only use it on Java 5 source boolean false

Examples

To configure the check:

 <module name="MissingOverride"/>
        

To configure the check for the javaFiveCompatibility mode:

   <module name="MissingOverride">
      <property name="javaFiveCompatibility"
          value="true"/>
   </module>
        

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker

PackageAnnotation

Description

This check makes sure that all package annotations are in the package-info.java file.

According to the Java JLS 3rd ed.

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 Java Language specification, sections 7.4.1.1.

Examples

To configure the check:

 <module name="PackageAnnotation"/>
        

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker

SuppressWarnings

Description

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.

Limitations: This check does not consider conditionals inside the SuppressWarnings annotation.
For example: @SupressWarnings((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.

Properties

name description type default value
format The warnings property is a regex pattern. Any warning being suppressed matching this pattern will be flagged. regexp ^$|^\s+$
tokens tokens to check subset of tokens CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF ENUM_CONSTANT_DEF PARAMETER_DEF VARIABLE_DEF METHOD_DEF CTOR_DEF CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF ENUM_CONSTANT_DEF PARAMETER_DEF VARIABLE_DEF METHOD_DEF CTOR_DEF

Examples

To configure the check:

 <module name="SuppressWarnings"/>
        

To configure the check so that the "unchecked" and "unused" warnings cannot be suppressed on anything but variable and parameter declarations.

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

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker