public class JavadocMethodCheck extends AbstractCheck
Checks the Javadoc of a method or constructor.
The scope to verify is specified using the Scope class and defaults
to Scope.PRIVATE. To verify another scope, set property scope to
a different scope.
Violates parameters and type parameters for which no param tags are present
can be suppressed by defining property allowMissingParamTags.
Violates methods which return non-void but for which no return tag is present
can be suppressed by defining property allowMissingReturnTag.
Violates exceptions which are declared to be thrown, but for which no throws
tag is present by activation of property validateThrows.
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.
Note that only inheritable items will allow the {@inheritDoc}
tag to be used in place of comments. Static methods at all visibilities,
private non-static methods and constructors are not inheritable.
For example, if the following method is implementing a method required by an interface, then the Javadoc could be done as:
/** {@inheritDoc} */
public int checkReturnTag(final int aTagIndex,
JavadocTag[] aTags,
int aLineNo)
allowedAnnotations - Specify the list of annotations
that allow missed documentation.
Default value is Override.
validateThrows - Control whether to validate throws tags.
Default value is false.
scope - Specify the visibility scope where Javadoc comments are checked.
Default value is private.
excludeScope - Specify the visibility scope where Javadoc comments
are not checked.
Default value is null.
allowMissingParamTags - Control whether to ignore violations
when a method has parameters but does not have matching param tags in the javadoc.
Default value is false.
allowMissingReturnTag - Control whether to ignore violations
when a method returns non-void type and does not have a return tag in the javadoc.
Default value is false.
tokens - tokens to check Default value is:
METHOD_DEF,
CTOR_DEF,
ANNOTATION_FIELD_DEF.
To configure the default check:
<module name="JavadocMethod"/>
To configure the check for public scope, ignoring any missing param tags is:
<module name="JavadocMethod"> <property name="scope" value="public"/> <property name="allowMissingParamTags" value="true"/> </module>
To configure the check for methods which are in private,
but not in protected scope:
<module name="JavadocMethod"> <property name="scope" value="private"/> <property name="excludeScope" value="protected"/> </module>
To configure the check to validate throws tags, you can use following config.
ATTENTION: Checkstyle does not have information about hierarchy of exception types so usage
of base class is considered as separate exception type. As workaround you need to
specify both types in javadoc (parent and exact type).
<module name="JavadocMethod"> <property name="validateThrows" value="true"/> </module>
/**
* Actual exception thrown is child class of class that is declared in throws.
* It is limitation of checkstyle (as checkstyle does not know type hierarchy).
* Javadoc is valid not declaring FileNotFoundException
* BUT checkstyle can not distinguish relationship between exceptions.
* @param file some file
* @throws IOException if some problem
*/
public void doSomething8(File file) throws IOException {
if (file == null) {
throw new FileNotFoundException(); // violation
}
}
/**
* Exact throw type referencing in javadoc even first is parent of second type.
* It is a limitation of checkstyle (as checkstyle does not know type hierarchy).
* This javadoc is valid for checkstyle and for javadoc tool.
* @param file some file
* @throws IOException if some problem
* @throws FileNotFoundException if file is not found
*/
public void doSomething9(File file) throws IOException {
if (file == null) {
throw new FileNotFoundException();
}
}
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_CLASS_INFO
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_DUPLICATE_TAG
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_EXPECTED_TAG
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_INVALID_INHERIT_DOC
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_RETURN_EXPECTED
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_UNUSED_TAG
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_UNUSED_TAG_GENERAL
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
JavadocMethodCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
static java.util.List<DetailAST> |
findTokensInAstByType(DetailAST root,
int astType)
Finds node of specified type among root children, siblings, siblings children
on any deep level.
|
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 |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
setAllowedAnnotations(java.lang.String... userAnnotations)
Setter to specify the list of annotations that allow missed documentation.
|
void |
setAllowMissingParamTags(boolean flag)
Setter to control whether to ignore violations when a method has parameters
but does not have matching
param tags in the javadoc. |
void |
setAllowMissingReturnTag(boolean flag)
Setter to control whether to ignore violations when a method returns non-void type
and does not have a
return tag in the javadoc. |
void |
setExcludeScope(Scope excludeScope)
Setter to specify the visibility scope where Javadoc comments are not checked.
|
void |
setScope(Scope scope)
Setter to specify the visibility scope where Javadoc comments are checked.
|
void |
setValidateThrows(boolean value)
Setter to control whether to validate
throws tags. |
void |
visitToken(DetailAST ast)
Called to process a token.
|
clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_CLASS_INFO
public static final java.lang.String MSG_UNUSED_TAG_GENERAL
public static final java.lang.String MSG_INVALID_INHERIT_DOC
public static final java.lang.String MSG_UNUSED_TAG
public static final java.lang.String MSG_EXPECTED_TAG
public static final java.lang.String MSG_RETURN_EXPECTED
public static final java.lang.String MSG_DUPLICATE_TAG
public JavadocMethodCheck()
public void setValidateThrows(boolean value)
throws tags.value - user's value.public void setAllowedAnnotations(java.lang.String... userAnnotations)
userAnnotations - user's value.public void setScope(Scope scope)
scope - a scope.public void setExcludeScope(Scope excludeScope)
excludeScope - a scope.public void setAllowMissingParamTags(boolean flag)
param tags in the javadoc.flag - a Boolean valuepublic void setAllowMissingReturnTag(boolean flag)
return tag in the javadoc.flag - a Boolean valuepublic final int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic void beginTree(DetailAST rootAST)
AbstractCheckbeginTree in class AbstractCheckrootAST - the root of the treepublic final void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processpublic final void leaveToken(DetailAST ast)
AbstractCheckleaveToken in class AbstractCheckast - the token leavingpublic static java.util.List<DetailAST> findTokensInAstByType(DetailAST root, int astType)
root - DetailASTastType - value of TokenTypeList of DetailAST nodes which matches the predicate.Copyright © 2001-2020. All Rights Reserved.