Since Checkstyle 3.0
Checks that a variable has a Javadoc comment. Ignores serialVersionUID
fields.
| name | description | type | default value | since |
|---|---|---|---|---|
| excludeScope | Specify the visibility scope where Javadoc comments are not checked. | Scope | null |
3.4 |
| ignoreNamePattern | Specify the regexp to define variable names to ignore. | Pattern | null |
5.8 |
| scope | Specify the visibility scope where Javadoc comments are checked. | Scope | private |
3.0 |
| tokens | tokens to check | subset of tokens ENUM_CONSTANT_DEF . | ENUM_CONSTANT_DEF . | 3.0 |
To configure the default check:
<module name="Checker">
<module name="TreeWalker">
<module name="JavadocVariable"/>
</module>
</module>
By default, this setting will report a violation if there is no javadoc for any scope member.
public class Test {
private int a; // violation, missing javadoc for private member
/**
* Some description here
*/
private int b; // OK
protected int c; // violation, missing javadoc for protected member
public int d; // violation, missing javadoc for public member
/*package*/ int e; // violation, missing javadoc for package member
}
To configure the check for public
scope:
<module name="Checker">
<module name="TreeWalker">
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
</module>
</module>
This setting will report a violation if there
is no javadoc for public member.
public class Test {
private int a; // OK
/**
* Some description here
*/
private int b; // OK
protected int c; // OK
public int d; // violation, missing javadoc for public member
/*package*/ int e; // OK
}
To configure the check for members which are in private, but not in
protected scope:
<module name="Checker">
<module name="TreeWalker">
<module name="JavadocVariable">
<property name="scope" value="private"/>
<property name="excludeScope" value="protected"/>
</module>
</module>
</module>
This setting will report a violation if there is no
javadoc for private member and
ignores protected member.
public class Test {
private int a; // violation, missing javadoc for private member
/**
* Some description here
*/
private int b; // OK
protected int c; // OK
public int d; // OK
/*package*/ int e; // violation, missing javadoc for package member
}
To ignore absence of Javadoc comments for variables with names log or
logger:
<module name="Checker">
<module name="TreeWalker">
<module name="JavadocVariable">
<property name="ignoreNamePattern" value="log|logger"/>
</module>
</module>
</module>
This setting will report a violation if there is no
javadoc for any scope member and ignores members with
name log or logger.
public class Test {
private int a; // violation, missing javadoc for private member
/**
* Some description here
*/
private int b; // OK
protected int c; // violation, missing javadoc for protected member
public int d; // violation, missing javadoc for public member
/*package*/ int e; // violation, missing javadoc for package member
private int log; // OK
private int logger; // 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