Since Checkstyle 8.21
Scope
class and
defaults to Scope.PUBLIC
. To verify another
scope, set property scope to a different
scope.
Javadoc is not required on a method that is tagged with the
@Override
annotation. However, under
Java 5 it is not possible to mark a method required for an
interface (this was corrected under Java 6). Hence,
Checkstyle supports using the convention of using a single
{@inheritDoc}
tag instead of all the
other tags.
For getters and setters for the property allowMissingPropertyJavadoc
,
the methods must match exactly the structures below.
public void setNumber(final int number) { mNumber = number; } public int getNumber() { return mNumber; } public boolean isSomething() { return false; }
name | description | type | default value | since |
---|---|---|---|---|
allowMissingPropertyJavadoc | Control whether to allow missing Javadoc on accessor methods for properties (setters and getters). | boolean | false |
8.21 |
allowedAnnotations | Configure annotations that allow missed documentation. | String[] | Override |
8.21 |
excludeScope | Specify the visibility scope where Javadoc comments are not checked. | Scope | null |
8.21 |
ignoreMethodNamesRegex | Ignore method whose names are matching specified regex. | Pattern | null |
8.21 |
minLineCount | Control the minimal amount of lines in method to allow no documentation. | int | -1 |
8.21 |
scope | Specify the visibility scope where Javadoc comments are checked. | Scope | public |
8.21 |
tokens | tokens to check | subset of tokens METHOD_DEF , CTOR_DEF , ANNOTATION_FIELD_DEF , COMPACT_CTOR_DEF . | METHOD_DEF , CTOR_DEF , ANNOTATION_FIELD_DEF , COMPACT_CTOR_DEF . | 8.21 |
To configure the default check:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"/> </module> </module>
Example:
public class Test { public Test() {} // violation, missing javadoc for constructor public void test() {} // violation, missing javadoc for method /** * Some description here. */ public void test2() {} // OK @Override public String toString() { // OK return "Some string"; } private void test1() {} // OK protected void test2() {} // OK void test3() {} // OK }
To configure the check for private
scope:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"> <property name="scope" value="private"/> </module> </module> </module>
Example:
public class Test { private void test1() {} // violation, the private method is missing javadoc }
To configure the check for methods which are in private
,
but not in protected
scope:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"> <property name="scope" value="private"/> <property name="excludeScope" value="protected"/> </module> </module> </module>
Example:
public class Test { private void test1() {} // violation, the private method is missing javadoc /** * Some description here */ private void test1() {} // OK protected void test2() {} // OK }
To configure the check for ignoring methods named foo(),foo1(),foo2()
, etc.:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"> <property name="ignoreMethodNamesRegex" value="^foo.*$"/> </module> </module> </module>
Example:
public class Test { public void test1() {} // violation, method is missing javadoc public void foo() {} // OK public void foobar() {} // OK }
To configure the check for ignoring missing javadoc for accessor methods:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"> <property name="allowMissingPropertyJavadoc" value="true"/> </module> </module> </module>
Example:
public class Test { private String text; public void test() {} // violation, method is missing javadoc public String getText() { return text; } // OK public void setText(String text) { this.text = text; } // OK }
To configure the check with annotations that allow missed documentation:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingJavadocMethod"> <property name="allowedAnnotations" value="Override,Deprecated"/> </module> </module> </module>
Example:
public class Test { public void test() {} // violation, method is missing javadoc @Override public void test1() {} // OK @Deprecated public void test2() {} // OK @SuppressWarnings public void test3() {} // violation, method is missing javadoc /** * Some description here. */ @SuppressWarnings public void test4() {} // OK }
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