Since Checkstyle 3.2
The following checks are performed:
@return
tags,
because the Javadoc tools automatically appends a period to the end of the tag
content.
Javadoc automatically places the first sentence in the
method summary table and index. Without proper punctuation
the Javadoc may be malformed. All items eligible for the
{@inheritDoc}
tag are exempt from this
requirement.
@param
and @return
.
These checks were patterned after the checks made by the DocCheck doclet available from Sun. Note: Original Sun's DocCheck tool does not exist anymore.
name | description | type | default value | since |
---|---|---|---|---|
checkEmptyJavadoc | Control whether to check if the Javadoc is missing a describing text. | boolean | false |
3.4 |
checkFirstSentence | Control whether to check the first sentence for proper end of sentence. | boolean | true |
3.2 |
checkHtml | Control whether to check for incomplete HTML tags. | boolean | true |
3.2 |
endOfSentenceFormat | Specify the format for matching the end of a sentence. | Pattern | "([.?!][ \t\n\r\f<])|([.?!]$)" |
5.0 |
excludeScope | Specify the visibility scope where Javadoc comments are not checked. | Scope | null |
3.4 |
scope | Specify the visibility scope where Javadoc comments are checked. | Scope | private |
3.2 |
tokens | tokens to check | subset of tokens ANNOTATION_DEF , ANNOTATION_FIELD_DEF , CLASS_DEF , CTOR_DEF , ENUM_CONSTANT_DEF , ENUM_DEF , INTERFACE_DEF , METHOD_DEF , PACKAGE_DEF , VARIABLE_DEF , RECORD_DEF , COMPACT_CTOR_DEF . | ANNOTATION_DEF , ANNOTATION_FIELD_DEF , CLASS_DEF , CTOR_DEF , ENUM_CONSTANT_DEF , ENUM_DEF , INTERFACE_DEF , METHOD_DEF , PACKAGE_DEF , VARIABLE_DEF , RECORD_DEF , COMPACT_CTOR_DEF . | 3.2 |
To configure the default check:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"/> </module> </module>
Example1:
/** * Some description here */ public class Example1 { Example1() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here */ public void testMethod4() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here * Second line of description */ private void testMethod5() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here * <p */ private void testMethod6() { // violation 4 lines above 'should end with a period' // violation 3 lines above 'Incomplete HTML tag found' } }
To configure the check for public
scope:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"> <property name="scope" value="public"/> </module> </module> </module>
Example2:
/** * Some description here */ public class Example2 { Example2() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { } /** * Some description here */ public void testMethod4() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here * Second line of description */ private void testMethod5() { } /** * Some description here * <p */ private void testMethod6() { } }
To configure the check for javadoc which is in private
, but not in
package
scope:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"> <property name="scope" value="private"/> <property name="excludeScope" value="package"/> </module> </module> </module>
Example3:
/** * Some description here */ public class Example3 { Example3() { } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here */ public void testMethod4() { } /** * Some description here * Second line of description */ private void testMethod5() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here * <p */ private void testMethod6() { // violation 4 lines above 'should end with a period' // violation 3 lines above 'Incomplete HTML tag' } }
To configure the check to turn off first sentence checking:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"> <property name="checkFirstSentence" value="false"/> </module> </module> </module>
Example4:
/** * Some description here */ public class Example4 { Example4() { } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { } /** * Some description here */ public void testMethod4() { } /** * Some description here * Second line of description */ private void testMethod5() { } /** * Some description here * <p */ private void testMethod6() { // violation 3 lines above 'Incomplete HTML tag' } }
To configure the check to turn off validation of incomplete html tags:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"> <property name="checkHtml" value="false"/> </module> </module> </module>
Example5:
/** * Some description here */ public class Example5 { Example5() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here */ public void testMethod4() { // violation 4 lines above 'First sentence should end with a period' } /** * Some description here * Second line of description */ private void testMethod5() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here * <p */ private void testMethod6() { // violation 4 lines above 'should end with a period' } }
To configure the check for only class definitions:
<module name="Checker"> <module name="TreeWalker"> <module name="JavadocStyle"> <property name="tokens" value="CLASS_DEF"/> </module> </module> </module>
Example6:
/** * Some description here */ public class Example6 { Example6() { // violation 5 lines above 'First sentence should end with a period' } /** * Some description here. */ private void testMethod1() {} // ok below, @return tag automatically inserts a period after the text /** * {@return {@code true} if this object * has been initialized, {@code false} otherwise} */ private boolean testMethod2() { return true; } /** * Some description here */ private void testMethod3() { } /** * Some description here */ public void testMethod4() { } /** * Some description here * Second line of description */ private void testMethod5() { } /** * Some description here * <p */ private void testMethod6() { } }
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