JavadocParamOrder

Since Checkstyle 14.1.0

Description

Checks that @param tags in Javadoc comments are in the same order as the parameters in the declaration.

Type parameters must come before regular parameters. For record declarations, record components are treated as regular parameters and must be documented after type parameters. For compact constructors, the expected parameter order is the order of the record components in the record declaration.

The check does not validate missing, extra, or duplicate @param tags. It reports only tags that move backward in the declaration order.

Properties

name description type default value since
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 14.1.0

Examples

To configure the default check:


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

Example:


public class Example1 {

  // violation 5 lines below '@param tag for 'name' should be in declaration order.'
  /**
   * Parameter tags should follow the declaration order.
   *
   * @param role user role
   * @param name user name
   */
  void method(String name, String role) {
  }

  record Person(String id, int age) {

    // violation 5 lines below '@param tag for 'id' should be in declaration order.'
    /**
     * Compact constructor parameter tags follow record component order.
     *
     * @param age age
     * @param id identifier
     */
    Person {
    }
  }

  /**
   * A missing parameter tag does not affect relative order validation.
   *
   * @param name user name
   * @param locale preferred locale
   */
  void missingTag(String name, String email, String locale) {
  }

  /**
   * Duplicate parameter tags are allowed when they do not move backwards.
   *
   * @param name user name
   * @param email email address
   * @param email repeated email address
   */
  void duplicateTag(String name, String email) {
  }
}

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

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

Parent Module

TreeWalker