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
violateExecutionOnNonTightHtml Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. boolean false 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:


/** Documented. */
class Example1 {
  /** Javadoc. */
  public class A {}
  /** Javadoc. */
  private class B {}
  /** Javadoc. */
  protected class C {}
  /** Javadoc. */
  class D {}
  /** Javadoc. */
  @SpringBootApplication
  private class App {}
  /** Javadoc. */
  @Configuration
  private class Config {}
  /** Javadoc. */
  private class E {}
}

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 A {}

  private class B {}    // violation, 'Missing a Javadoc comment'

  protected class C {}  // violation, 'Missing a Javadoc comment'

  class D {}            // violation, 'Missing a Javadoc comment'
  /** Javadoc. */
  @SpringBootApplication
  private class App {}
  /** Javadoc. */
  @Configuration
  private class Config {}
  /** Javadoc. */
  private class E {}
}

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 A {}

  private class B {} // violation, 'Missing a Javadoc comment'

  protected class C {}
  /** Javadoc. */
  class D {}
  /** Javadoc. */
  @SpringBootApplication
  private class App {}
  /** Javadoc. */
  @Configuration
  private class Config {}
  /** Javadoc. */
  private class E {}
}

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="scope" value="private"/>
      <property name="skipAnnotations"
        value="SpringBootApplication,Configuration"/>
    </module>
  </module>
</module>

Example4:


/** Documented. */
class Example4 {
  /** Javadoc. */
  public class A {}
  /** Javadoc. */
  private class B {}
  /** Javadoc. */
  protected class C {}
  /** Javadoc. */
  class D {}
  /** Javadoc. */
  @SpringBootApplication
  private class App {}
  /** Javadoc. */
  @Configuration
  private class Config {}

  private class E {} // violation, 'Missing a Javadoc comment'
}

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="scope" value="private"/>
      <property name="skipAnnotations" value="Annotation,MyClass.Annotation"/>
    </module>
  </module>
</module>

Example5:


/** Documented. */
class Example5 {
  /** Javadoc.*/
  @Annotation
  private class Class1 { }

  @MyClass.Annotation
  private class Class2 { }

  private class Class3 { } // violation, 'Missing a Javadoc comment'
}

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.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker