PackageAnnotation

Since Checkstyle 5.0

Description

Checks that all package annotations are in the package-info.java file.

For Java SE8 and above, placement of package annotations in the package-info.java file is enforced by the compiler and this check is not necessary.

For Java SE7 and below, the Java Language Specification highly recommends but doesn't require that annotations are placed in the package-info.java file, and this check can help to enforce that placement.

See Java Language Specification, §7.4.1 for more info.

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="PackageAnnotation"/>
  </module>
</module>
        

Example of validating MyClass.java:

@Deprecated
package com.example.annotations.packageannotation; //violation
        

Example of fixing violation in MyClass.java:

package com.example.annotations.packageannotation; //ok
        

Example of validating package-info.java:

@Deprecated
package com.example.annotations.packageannotation; //ok
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.annotation

Parent Module

TreeWalker