BlockCommentEndPosition

Since Checkstyle 14.4.0

Description

Checks that the Javadoc block comment end delimiter position is either alone on its own line or on the same line as the block comment begin /**.

It is possible to enforce two different strategies:

  • alone - The block comment end must be alone on its own line. This allows only multi-line Javadoc comments:
    
    /**
     * Multiple lines of Javadoc text are written here,
     * wrapped normally...
     */
    public void method();
            
  • alone_or_singleline - The block comment end must be either alone on its own line or on the same line as the block comment begin. This allows multi-line Javadoc as well as single-line Javadoc comments:
    
    // Block comment end is alone on its own line
    /**
     * Multiple lines of Javadoc text are written here,
     * wrapped normally...
     */
    public void method();
    
    // Single-line Javadoc
    /** Javadoc summary. */
    public void method1();
            

Properties

name description type default value since
strategy Specify the policy on strategy of the block comment end position. BlockCommentEndPositionOption alone_or_singleline 14.4.0

Examples

To configure the default check to validate whether the block comment end should be on its own line or on a single line:


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

This setting produces a violation for each block comment end that is not on its own line, except for single-line:


/** Singleline Javadoc. */ // ok, 'alone_or_singleline' allows singleline Javadoc
class Example1 {

  /**
   * Invalid block comment end position. */
  int n = 10;
  // violation 2 lines above 'Block comment end must be on new line.'

  /**
   * Valid block comment end position.
   *
   * @param a the first number
   * @param b the second number
   * @return the sum of a and b
   */
  int add(int a, int b) {
    return a + b;
  }
}

To ensure that the block comment end appears on its own line:


<module name="Checker">
  <module name="TreeWalker">
    <module name="BlockCommentEndPosition">
      <property name="strategy" value="alone"/>
    </module>
  </module>
</module>

This setting produces a violation for each block comment end that is not on its own line:


/** Singleline Javadoc. */
class Example2 { // violation above 'Block comment end must be on new line.'

  /**
   * Invalid block comment end position. */
  int n = 10;
  // violation 2 lines above 'Block comment end must be on new line.'

  /**
   * Valid block comment end position.
   *
   * @param a the first number
   * @param b the second number
   * @return the sum of a and b
   */
  int add(int a, int b) {
    return a + b;
  }
}

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

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

Parent Module

TreeWalker