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 Example1 { private int a; // violation /** * Some description here */ private int b; protected int c; // violation public int d; // violation /*package*/ int e; // violation }
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 Example2 { private int a; /** * Some description here */ private int b; protected int c; public int d; // violation /*package*/ int e; }
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 Example3 { private int a; // violation /** * Some description here */ private int b; protected int c; public int d; /*package*/ int e; // violation }
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 Example4 { private int a; // violation /** * Some description here */ private int b; protected int c; // violation public int d; // violation /*package*/ int e; // violation }
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