public class MissingJavadocMethodCheck extends AbstractCheck
Checks for missing Javadoc comments for a method or constructor. The scope to verify is
specified using the 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; }
minLineCount
- Control the minimal amount of lines in method to allow no
documentation.
Type is int
.
Default value is -1
.
allowedAnnotations
- Configure the list of annotations that allow missed
documentation.
Type is java.lang.String[]
.
Default value is Override
.
scope
- Specify the visibility scope where Javadoc comments are checked.
Type is com.puppycrawl.tools.checkstyle.api.Scope
.
Default value is public
.
excludeScope
- Specify the visibility scope where Javadoc comments are
not checked.
Type is com.puppycrawl.tools.checkstyle.api.Scope
.
Default value is null
.
allowMissingPropertyJavadoc
- Control whether to allow missing Javadoc on
accessor methods for properties (setters and getters).
Type is boolean
.
Default value is false
.
ignoreMethodNamesRegex
- ignore method whose names are matching specified
regex.
Type is java.util.regex.Pattern
.
Default value is null
.
tokens
- tokens to check
Type is int[]
.
Default value is:
METHOD_DEF,
CTOR_DEF,
ANNOTATION_FIELD_DEF.
To configure the default check:
<module name="MissingJavadocMethod"/>
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="MissingJavadocMethod"> <property name="scope" value="private"/> </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="MissingJavadocMethod"> <property name="scope" value="private"/> <property name="excludeScope" value="protected"/> </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="MissingJavadocMethod"> <property name="ignoreMethodNamesRegex" value="^foo.*$"/> </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="MissingJavadocMethod"> <property name="allowMissingPropertyJavadoc" value="true"/> </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="MissingJavadocMethod"> <property name="allowedAnnotations" value="Override,Deprecated"/> </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 }
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
javadoc.missing
AutomaticBean.OutputStreamOptions
Modifier and Type | Field and Description |
---|---|
static String |
MSG_JAVADOC_MISSING
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
MissingJavadocMethodCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
void |
setAllowedAnnotations(String... userAnnotations)
Setter to configure the list of annotations that allow missed documentation.
|
void |
setAllowMissingPropertyJavadoc(boolean flag)
Setter to control whether to allow missing Javadoc on accessor methods for properties
(setters and getters).
|
void |
setExcludeScope(Scope excludeScope)
Setter to specify the visibility scope where Javadoc comments are not checked.
|
void |
setIgnoreMethodNamesRegex(Pattern pattern)
Setter to ignore method whose names are matching specified regex.
|
void |
setMinLineCount(int value)
Setter to control the minimal amount of lines in method to allow no documentation.
|
void |
setScope(Scope scope)
Setter to specify the visibility scope where Javadoc comments are checked.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_JAVADOC_MISSING
public MissingJavadocMethodCheck()
public void setAllowedAnnotations(String... userAnnotations)
userAnnotations
- user's value.public void setIgnoreMethodNamesRegex(Pattern pattern)
pattern
- a pattern.public void setMinLineCount(int value)
value
- user's value.public void setAllowMissingPropertyJavadoc(boolean flag)
flag
- a Boolean
valuepublic void setScope(Scope scope)
scope
- a scope.public void setExcludeScope(Scope excludeScope)
excludeScope
- a scope.public final int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public final void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processCopyright © 2001–2020. All rights reserved.