BlockCommentEndPosition

Since Checkstyle 13.3.0

Description

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

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 13.3.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:


/**
 * This multi-line Javadoc is ok because
 * block comment end alone on the line.
 */
class Example1 {

  /** This Javadoc is ok because single-line javadoc is allowed. */
  int n = 10;

  /**
   * This Javadoc causes violation because
   * block comment is not alone on the line.
   *
   * @param a the first number
   * @param b the second number
   * @return the sum of a and b */
  int add(int a, int b) {
    // violation 2 lines above ''BLOCK_COMMENT_END' must be on the new line.'
    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:


/** violation because singleline is not allowed. */
class Example2 {
  // violation 2 lines above ''BLOCK_COMMENT_END' must be on the new line.'

  /**
   * This Javadoc cause violation because block comment end
   * is not alone on the line. */
  int n = 10;
  // violation 2 lines above ''BLOCK_COMMENT_END' must be on the new line.'

  /**
   * This is ok because block comment is alone on the line.
   *
   * @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.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker