Since Checkstyle 8.27
It is possible to enforce two different styles:
/** Summary text. * More details. */ public void method();
/** * Summary text. * More details. */ public void method();
This check does not validate the Javadoc summary itself nor its presence. The check will not report any violations for missing or malformed javadoc summary. To validate the Javadoc summary use SummaryJavadoc check.
The Documentation Comment Specification permits leading asterisks on the first line. For these Javadoc comments:
/*** * Some text. */ /************ * Some text. */ /** ** * Some text. */
The documentation generated will be just "Some text." without any asterisks. Since these asterisks will not appear in the generated documentation, they should not be considered as the beginning of the Javadoc content. In such cases, the check assumes that the Javadoc content begins on the second line.
name | description | type | default value | since |
---|---|---|---|---|
location | Specify the policy on placement of the Javadoc content. | JavadocContentLocationOption | second_line |
8.27 |
To configure the default check to validate that the Javadoc content starts from the second line:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocContentLocation"/> </module> </module>
This setting produces a violation for each multi-line comment starting on the same line as the initial asterisks:
class Example1 { // violation below 'Javadoc content should start from the next line.' /** This comment causes a violation because it starts from the first line * and spans several lines. */ private int field1; /** * This comment is OK because it starts from the second line. */ private int field12; /** This comment is OK because it is on the single-line. */ private int field3; }
To ensure that Javadoc content starts from the first line:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocContentLocation"> <property name="location" value="first_line"/> </module> </module> </module>
This setting produces a violation for each comment not starting on the same line as the initial asterisks:
class Example2 { /** This comment is OK because it starts on the first line. * There may be additional text. */ private int field1; // violation below, 'Javadoc content should start from the same line.' /** * This comment causes a violation because it starts on the second line. */ private int field2; /** This single-line comment also is OK. */ private int field3; }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.javadoc