MissingJavadocType

Since Checkstyle 8.20

Description

Checks for missing Javadoc comments for class, enum, interface, and annotation interface definitions. The scope to verify is specified using the Scope class and defaults to Scope.PUBLIC. To verify another scope, set property scope to one of the Scope constants.

Properties

name description type default value since
excludeScope Specify the visibility scope where Javadoc comments are not checked. Scope null 8.20
scope Specify the visibility scope where Javadoc comments are checked. Scope public 8.20
skipAnnotations Specify annotations that allow missed documentation. If annotation is present in target sources in multiple forms of qualified name, all forms should be listed in this property. String[] Generated 8.20
tokens tokens to check subset of tokens INTERFACE_DEF , CLASS_DEF , ENUM_DEF , ANNOTATION_DEF , RECORD_DEF . INTERFACE_DEF , CLASS_DEF , ENUM_DEF , ANNOTATION_DEF , RECORD_DEF . 8.20

Examples

To configure the default check to make sure all public class, enum, interface, and annotation interface, definitions have javadocs:

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

Example1:

class Example1 {
  /** Javadoc.*/
  public class testClass0 {}
  public class testClass1 {}
  private class testClass2 {}
  protected class testClass3 {}
  class testClass4 {}
}
        

To configure the check for private scope:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
      <property name="scope" value="private"/>
    </module>
  </module>
</module>
        

Example2:

class Example2 { // violation, 'Missing a Javadoc comment'
  /** Javadoc.*/
  public class testClass0 {}
  public class testClass1 {} // violation, 'Missing a Javadoc comment'
  private class testClass2 {} // violation, 'Missing a Javadoc comment'
  protected class testClass3 {} // violation, 'Missing a Javadoc comment'
  class testClass4 {} // violation, 'Missing a Javadoc comment'
}
        

To configure the check for private classes only:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
      <property name="scope" value="private"/>
      <property name="excludeScope" value="package"/>
    </module>
  </module>
</module>
        

Example3:

class Example3 {
  /** Javadoc.*/
  public class testClass0 {}
  public class testClass1 {}
  private class testClass2 {} // violation, 'Missing a Javadoc comment'
  protected class testClass3 {}
  class testClass4 {}

}
        

To configure a check that allows missing comments for classes annotated with @SpringBootApplication and @Configuration:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
      <property name="skipAnnotations" value="SpringBootApplication,Configuration"/>
    </module>
  </module>
</module>
        

Example4:

@SpringBootApplication // no violations about missing comment on class
public class Application {}

@Configuration // no violations about missing comment on class
class DatabaseConfiguration {}
        

To configure a check that allows missing comments for classes annotated with @Annotation and @MyClass.Annotation:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
      <property name="skipAnnotations" value="Annotation,MyClass.Annotation"/>
    </module>
  </module>
</module>
        

Example5:

@Annotation // ok
class Class1 {}

@MyClass.Annotation // ok
class Class2 {}

@com.mycompany.MyClass.Annotation // violation, as this form is missed in config
class Class3 {}
        

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

Parent Module

TreeWalker