MissingJavadocMethod

Since Checkstyle 8.21

Description

Checks for missing Javadoc comments for a method or constructor. The scope to verify is specified using the Scope class and defaults to Scope.PUBLIC. To verify another scope, set property scope to a different scope.

Javadoc is not required on a method that is tagged with the @Override annotation. However, under Java 5 it is not possible to mark a method required for an interface (this was corrected under Java 6). Hence, Checkstyle supports using the convention of using a single {@inheritDoc} tag instead of all the other tags.

For getters and setters for the property allowMissingPropertyJavadoc, the methods must match exactly the structures below.

public void setNumber(final int number)
{
    mNumber = number;
}

public int getNumber()
{
    return mNumber;
}

public boolean isSomething()
{
    return false;
}
        

Properties

name description type default value since
allowMissingPropertyJavadoc Control whether to allow missing Javadoc on accessor methods for properties (setters and getters). boolean false 8.21
allowedAnnotations Configure annotations that allow missed documentation. String[] Override 8.21
excludeScope Specify the visibility scope where Javadoc comments are not checked. Scope null 8.21
ignoreMethodNamesRegex Ignore method whose names are matching specified regex. Pattern null 8.21
minLineCount Control the minimal amount of lines in method to allow no documentation. int -1 8.21
scope Specify the visibility scope where Javadoc comments are checked. Scope public 8.21
tokens tokens to check subset of tokens METHOD_DEF , CTOR_DEF , ANNOTATION_FIELD_DEF , COMPACT_CTOR_DEF . METHOD_DEF , CTOR_DEF , ANNOTATION_FIELD_DEF , COMPACT_CTOR_DEF . 8.21

Examples

To configure the default check:

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

Example:

public class Example1 {
  public Example1() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {} // violation, 'Missing a Javadoc comment'
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {}
  protected void testMethod4() {}
  void testMethod5() {}
}
        

To configure the check for private scope:

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

Example:

public class Example2 {
  public Example2() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {} // violation, 'Missing a Javadoc comment'
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {} // violation, 'Missing a Javadoc comment'
  protected void testMethod4() {} // violation, 'Missing a Javadoc comment'
  void testMethod5() {} // violation, 'Missing a Javadoc comment'
}
        

To configure the check for methods which are in private, but not in protected scope:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocMethod">
      <property name="scope" value="private"/>
      <property name="excludeScope" value="protected"/>
    </module>
  </module>
</module>
        

Example:

public class Example3 {
  public Example3() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {} // violation, 'Missing a Javadoc comment'
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {} // violation, 'Missing a Javadoc comment'
  protected void testMethod4() {}
  void testMethod5() {} // violation, 'Missing a Javadoc comment'
}
        

To configure the check for ignoring methods named foo(),foo1(),foo2(), etc.:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocMethod">
      <property name="ignoreMethodNamesRegex" value="^testMethod.*$"/>
    </module>
  </module>
</module>
        

Example:

public class Example4 {
  public Example4() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {}
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {}
  protected void testMethod4() {}
  void testMethod5() {}
}
        

To configure the check for ignoring missing javadoc for accessor methods:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocMethod">
      <property name="allowMissingPropertyJavadoc" value="true"/>
    </module>
  </module>
</module>
        

Example:

public class Example5 {
  public Example5() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {} // violation, 'Missing a Javadoc comment'
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {}
  protected void testMethod4() {}
  void testMethod5() {}
}
        

To configure the check with annotations that allow missed documentation:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocMethod">
      <property name="allowedAnnotations" value="Override,Deprecated"/>
    </module>
  </module>
</module>
        

Example:

public class Example6 {
  public Example6() {} // violation, 'Missing a Javadoc comment'
  public void testMethod1() {} // violation, 'Missing a Javadoc comment'
  /**
   * Some description here.
   */
  public void testMethod2() {}

  @Override
  public String toString() {
    return "Some string";
  }

  private void testMethod3() {}
  protected void testMethod4() {}
  void testMethod5() {}
}
        

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