Class JavadocMethodCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck
-
- com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public class JavadocMethodCheck extends AbstractTypeAwareCheck
Checks the Javadoc of a method or constructor.- Author:
- Oliver Burn, Rick Giles, o_sukhodoslky
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck
AbstractTypeAwareCheck.AbstractClassInfo, AbstractTypeAwareCheck.Token
-
-
Field Summary
Fields Modifier and Type Field Description static String
MSG_CLASS_INFO
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_DUPLICATE_TAG
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_EXPECTED_TAG
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_INVALID_INHERIT_DOC
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_JAVADOC_MISSING
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_RETURN_EXPECTED
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_UNUSED_TAG
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_UNUSED_TAG_GENERAL
A key is pointing to the warning message text in "messages.properties" file.
-
Constructor Summary
Constructors Constructor Description JavadocMethodCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getAcceptableTokens()
The configurable token set.int[]
getDefaultTokens()
Returns the default token a check is interested in.boolean
isCommentNodesRequired()
Whether comment nodes are required or not.protected boolean
isMissingJavadocAllowed(DetailAST ast)
The JavadocMethodCheck is about to report a missing Javadoc.protected void
logLoadError(AbstractTypeAwareCheck.Token ident)
Logs error if unable to load class information.protected void
processAST(DetailAST ast)
Called to process an AST when visiting it.void
setAllowedAnnotations(String... userAnnotations)
Sets list of annotations.void
setAllowMissingJavadoc(boolean flag)
Controls whether to ignore errors when there is no javadoc.void
setAllowMissingParamTags(boolean flag)
Controls whether to allow a method which has parameters to omit matching param tags in the javadoc.void
setAllowMissingPropertyJavadoc(boolean flag)
Controls whether to ignore errors when there is no javadoc for a property accessor (setter/getter methods).void
setAllowMissingReturnTag(boolean flag)
Controls whether to allow a method which returns non-void type to omit the return tag in the javadoc.void
setAllowMissingThrowsTags(boolean flag)
Controls whether to allow a method which declares that it throws exceptions to omit matching throws tags in the javadoc.void
setAllowThrowsTagsForSubclasses(boolean flag)
Controls whether to allow documented exception that are subclass of one of declared exceptions.void
setAllowUndeclaredRTE(boolean flag)
Controls whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException.void
setExcludeScope(Scope excludeScope)
Set the excludeScope.void
setIgnoreMethodNamesRegex(Pattern pattern)
Set regex for matching method names to ignore.void
setMinLineCount(int value)
Sets minimal amount of lines in method.void
setScope(Scope scope)
Set the scope.void
setValidateThrows(boolean value)
Allow validating throws tag.-
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck
beginTree, createClassInfo, findClassAlias, getCurrentClassName, getRequiredTokens, isSubclass, isUnchecked, leaveToken, logLoadErrorImpl, resolveClass, setLogLoadErrors, setSuppressLoadErrors, tryLoadClass, visitToken
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
-
-
-
-
Field Detail
-
MSG_JAVADOC_MISSING
public static final String MSG_JAVADOC_MISSING
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_CLASS_INFO
public static final String MSG_CLASS_INFO
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_UNUSED_TAG_GENERAL
public static final String MSG_UNUSED_TAG_GENERAL
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_INVALID_INHERIT_DOC
public static final String MSG_INVALID_INHERIT_DOC
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_UNUSED_TAG
public static final String MSG_UNUSED_TAG
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_EXPECTED_TAG
public static final String MSG_EXPECTED_TAG
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_RETURN_EXPECTED
public static final String MSG_RETURN_EXPECTED
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_DUPLICATE_TAG
public static final String MSG_DUPLICATE_TAG
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavadocMethodCheck
public JavadocMethodCheck()
-
-
Method Detail
-
setIgnoreMethodNamesRegex
public void setIgnoreMethodNamesRegex(Pattern pattern)
Set regex for matching method names to ignore.- Parameters:
pattern
- a pattern.
-
setMinLineCount
public void setMinLineCount(int value)
Sets minimal amount of lines in method.- Parameters:
value
- user's value.
-
setValidateThrows
public void setValidateThrows(boolean value)
Allow validating throws tag.- Parameters:
value
- user's value.
-
setAllowedAnnotations
public void setAllowedAnnotations(String... userAnnotations)
Sets list of annotations.- Parameters:
userAnnotations
- user's value.
-
setExcludeScope
public void setExcludeScope(Scope excludeScope)
Set the excludeScope.- Parameters:
excludeScope
- a scope.
-
setAllowUndeclaredRTE
public void setAllowUndeclaredRTE(boolean flag)
Controls whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException.- Parameters:
flag
- aBoolean
value
-
setAllowThrowsTagsForSubclasses
public void setAllowThrowsTagsForSubclasses(boolean flag)
Controls whether to allow documented exception that are subclass of one of declared exceptions.- Parameters:
flag
- aBoolean
value
-
setAllowMissingParamTags
public void setAllowMissingParamTags(boolean flag)
Controls whether to allow a method which has parameters to omit matching param tags in the javadoc. Defaults to false.- Parameters:
flag
- aBoolean
value
-
setAllowMissingThrowsTags
public void setAllowMissingThrowsTags(boolean flag)
Controls whether to allow a method which declares that it throws exceptions to omit matching throws tags in the javadoc. Defaults to false.- Parameters:
flag
- aBoolean
value
-
setAllowMissingReturnTag
public void setAllowMissingReturnTag(boolean flag)
Controls whether to allow a method which returns non-void type to omit the return tag in the javadoc. Defaults to false.- Parameters:
flag
- aBoolean
value
-
setAllowMissingJavadoc
public void setAllowMissingJavadoc(boolean flag)
Controls whether to ignore errors when there is no javadoc. Defaults to false.- Parameters:
flag
- aBoolean
value
-
setAllowMissingPropertyJavadoc
public void setAllowMissingPropertyJavadoc(boolean flag)
Controls whether to ignore errors when there is no javadoc for a property accessor (setter/getter methods). Defaults to false.- Parameters:
flag
- aBoolean
value
-
getDefaultTokens
public int[] getDefaultTokens()
Description copied from class:AbstractCheck
Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
getDefaultTokens
in classAbstractCheck
- Returns:
- the default tokens
- See Also:
TokenTypes
-
getAcceptableTokens
public int[] getAcceptableTokens()
Description copied from class:AbstractCheck
The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Specified by:
getAcceptableTokens
in classAbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
TokenTypes
-
isCommentNodesRequired
public boolean isCommentNodesRequired()
Description copied from class:AbstractCheck
Whether comment nodes are required or not.- Overrides:
isCommentNodesRequired
in classAbstractCheck
- Returns:
- false as a default value.
-
processAST
protected final void processAST(DetailAST ast)
Description copied from class:AbstractTypeAwareCheck
Called to process an AST when visiting it.- Specified by:
processAST
in classAbstractTypeAwareCheck
- Parameters:
ast
- the AST to process. Guaranteed to not be PACKAGE_DEF or IMPORT tokens.
-
logLoadError
protected final void logLoadError(AbstractTypeAwareCheck.Token ident)
Description copied from class:AbstractTypeAwareCheck
Logs error if unable to load class information. Abstract, should be overridden in subclasses.- Specified by:
logLoadError
in classAbstractTypeAwareCheck
- Parameters:
ident
- class name for which we can no load class.
-
isMissingJavadocAllowed
protected boolean isMissingJavadocAllowed(DetailAST ast)
The JavadocMethodCheck is about to report a missing Javadoc. This hook can be used by derived classes to allow a missing javadoc in some situations. The default implementation checksallowMissingJavadoc
andallowMissingPropertyJavadoc
properties, do not forget to callsuper.isMissingJavadocAllowed(ast)
in case you want to keep this logic.- Parameters:
ast
- the tree node for the method or constructor.- Returns:
- True if this method or constructor doesn't need Javadoc.
-
-