Class MissingJavadocMethodCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck
-
- All Implemented Interfaces:
Configurable,Contextualizable
public class MissingJavadocMethodCheck extends AbstractCheck
Checks for missing Javadoc comments for a method or constructor. The scope to verify is specified using the
Scopeclass and defaults toScope.PUBLIC. To verify another scope, set property scope to a different scope.Javadoc is not required on a method that is tagged with the
@Overrideannotation. 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; }-
Property
allowMissingPropertyJavadoc- Control whether to allow missing Javadoc on accessor methods for properties (setters and getters). Type isboolean. Default value isfalse. -
Property
allowedAnnotations- Configure annotations that allow missed documentation. Type isjava.lang.String[]. Default value isOverride. -
Property
excludeScope- Specify the visibility scope where Javadoc comments are not checked. Type iscom.puppycrawl.tools.checkstyle.api.Scope. Default value isnull. -
Property
ignoreMethodNamesRegex- Ignore method whose names are matching specified regex. Type isjava.util.regex.Pattern. Default value isnull. -
Property
minLineCount- Control the minimal amount of lines in method to allow no documentation. Type isint. Default value is-1. -
Property
scope- Specify the visibility scope where Javadoc comments are checked. Type iscom.puppycrawl.tools.checkstyle.api.Scope. Default value ispublic. -
Property
tokens- tokens to check Type isjava.lang.String[]. Validation type istokenSet. Default value is: METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF.
Parent is
com.puppycrawl.tools.checkstyle.TreeWalkerViolation Message Keys:
-
javadoc.missing
- Since:
- 8.21
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>allowedAnnotationsConfigure annotations that allow missed documentation.private booleanallowMissingPropertyJavadocControl whether to allow missing Javadoc on accessor methods for properties (setters and getters).private static intDEFAULT_MIN_LINE_COUNTDefault value of minimal amount of lines in method to allow no documentation.private ScopeexcludeScopeSpecify the visibility scope where Javadoc comments are not checked.private static java.util.regex.PatternGETTER_PATTERNPattern matching names of getter methods.private java.util.regex.PatternignoreMethodNamesRegexIgnore method whose names are matching specified regex.private intminLineCountControl the minimal amount of lines in method to allow no documentation.static java.lang.StringMSG_JAVADOC_MISSINGA key is pointing to the warning message text in "messages.properties" file.private ScopescopeSpecify the visibility scope where Javadoc comments are checked.private static intSETTER_BODY_SIZEMaximum nodes allowed in a body of setter.private static intSETTER_GETTER_MAX_CHILDRENMaximum children allowed in setter/getter.private static java.util.regex.PatternSETTER_PATTERNPattern matching names of setter methods.
-
Constructor Summary
Constructors Constructor Description MissingJavadocMethodCheck()
-
Method Summary
All Methods Static 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.private static intgetMethodsNumberOfLine(DetailAST methodDef)Some javadoc.int[]getRequiredTokens()The tokens that this check must be registered for.private booleanisContentsAllowMissingJavadoc(DetailAST ast)Checks if the Javadoc can be missing if the method or constructor is below the minimum line count or has a special annotation.static booleanisGetterMethod(DetailAST ast)Returns whether an AST represents a getter method.private booleanisMissingJavadocAllowed(DetailAST ast)Checks if a missing Javadoc is allowed by the check's configuration.static booleanisSetterMethod(DetailAST ast)Returns whether an AST represents a setter method.private booleanmatchesSkipRegex(DetailAST methodDef)Checks if the given method name matches the regex.voidsetAllowedAnnotations(java.lang.String... userAnnotations)Setter to configure annotations that allow missed documentation.voidsetAllowMissingPropertyJavadoc(boolean flag)Setter to control whether to allow missing Javadoc on accessor methods for properties (setters and getters).voidsetExcludeScope(Scope excludeScope)Setter to specify the visibility scope where Javadoc comments are not checked.voidsetIgnoreMethodNamesRegex(java.util.regex.Pattern pattern)Setter to ignore method whose names are matching specified regex.voidsetMinLineCount(int value)Setter to control the minimal amount of lines in method to allow no documentation.voidsetScope(Scope scope)Setter to specify the visibility scope where Javadoc comments are checked.private booleanshouldCheck(DetailAST ast, Scope nodeScope)Whether we should check this node.voidvisitToken(DetailAST ast)Called to process a token.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
MSG_JAVADOC_MISSING
public static final java.lang.String MSG_JAVADOC_MISSING
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
SETTER_GETTER_MAX_CHILDREN
private static final int SETTER_GETTER_MAX_CHILDREN
Maximum children allowed in setter/getter.- See Also:
- Constant Field Values
-
GETTER_PATTERN
private static final java.util.regex.Pattern GETTER_PATTERN
Pattern matching names of getter methods.
-
SETTER_PATTERN
private static final java.util.regex.Pattern SETTER_PATTERN
Pattern matching names of setter methods.
-
SETTER_BODY_SIZE
private static final int SETTER_BODY_SIZE
Maximum nodes allowed in a body of setter.- See Also:
- Constant Field Values
-
DEFAULT_MIN_LINE_COUNT
private static final int DEFAULT_MIN_LINE_COUNT
Default value of minimal amount of lines in method to allow no documentation.- See Also:
- Constant Field Values
-
excludeScope
private Scope excludeScope
Specify the visibility scope where Javadoc comments are not checked.
-
minLineCount
private int minLineCount
Control the minimal amount of lines in method to allow no documentation.
-
allowMissingPropertyJavadoc
private boolean allowMissingPropertyJavadoc
Control whether to allow missing Javadoc on accessor methods for properties (setters and getters).
-
ignoreMethodNamesRegex
private java.util.regex.Pattern ignoreMethodNamesRegex
Ignore method whose names are matching specified regex.
-
allowedAnnotations
private java.util.Set<java.lang.String> allowedAnnotations
Configure annotations that allow missed documentation.
-
-
Constructor Detail
-
MissingJavadocMethodCheck
public MissingJavadocMethodCheck()
-
-
Method Detail
-
setAllowedAnnotations
public void setAllowedAnnotations(java.lang.String... userAnnotations)
Setter to configure annotations that allow missed documentation.- Parameters:
userAnnotations- user's value.- Since:
- 8.21
-
setIgnoreMethodNamesRegex
public void setIgnoreMethodNamesRegex(java.util.regex.Pattern pattern)
Setter to ignore method whose names are matching specified regex.- Parameters:
pattern- a pattern.- Since:
- 8.21
-
setMinLineCount
public void setMinLineCount(int value)
Setter to control the minimal amount of lines in method to allow no documentation.- Parameters:
value- user's value.- Since:
- 8.21
-
setAllowMissingPropertyJavadoc
public void setAllowMissingPropertyJavadoc(boolean flag)
Setter to control whether to allow missing Javadoc on accessor methods for properties (setters and getters).- Parameters:
flag- aBooleanvalue- Since:
- 8.21
-
setScope
public void setScope(Scope scope)
Setter to specify the visibility scope where Javadoc comments are checked.- Parameters:
scope- a scope.- Since:
- 8.21
-
setExcludeScope
public void setExcludeScope(Scope excludeScope)
Setter to specify the visibility scope where Javadoc comments are not checked.- Parameters:
excludeScope- a scope.- Since:
- 8.21
-
getRequiredTokens
public final int[] getRequiredTokens()
Description copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
getRequiredTokensin classAbstractCheck- Returns:
- the token set this must be registered for.
- See Also:
TokenTypes
-
getDefaultTokens
public int[] getDefaultTokens()
Description copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
getDefaultTokensin classAbstractCheck- Returns:
- the default tokens
- See Also:
TokenTypes
-
getAcceptableTokens
public int[] getAcceptableTokens()
Description copied from class:AbstractCheckThe 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:
getAcceptableTokensin classAbstractCheck- Returns:
- the token set this check is designed for.
- See Also:
TokenTypes
-
visitToken
public final void visitToken(DetailAST ast)
Description copied from class:AbstractCheckCalled to process a token.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
getMethodsNumberOfLine
private static int getMethodsNumberOfLine(DetailAST methodDef)
Some javadoc.- Parameters:
methodDef- Some javadoc.- Returns:
- Some javadoc.
-
isMissingJavadocAllowed
private boolean isMissingJavadocAllowed(DetailAST ast)
Checks if a missing Javadoc is allowed by the check's configuration.- Parameters:
ast- the tree node for the method or constructor.- Returns:
- True if this method or constructor doesn't need Javadoc.
-
isContentsAllowMissingJavadoc
private boolean isContentsAllowMissingJavadoc(DetailAST ast)
Checks if the Javadoc can be missing if the method or constructor is below the minimum line count or has a special annotation.- Parameters:
ast- the tree node for the method or constructor.- Returns:
- True if this method or constructor doesn't need Javadoc.
-
matchesSkipRegex
private boolean matchesSkipRegex(DetailAST methodDef)
Checks if the given method name matches the regex. In that case we skip enforcement of javadoc for this method- Parameters:
methodDef-METHOD_DEF- Returns:
- true if given method name matches the regex.
-
shouldCheck
private boolean shouldCheck(DetailAST ast, Scope nodeScope)
Whether we should check this node.- Parameters:
ast- a given node.nodeScope- the scope of the node.- Returns:
- whether we should check a given node.
-
isGetterMethod
public static boolean isGetterMethod(DetailAST ast)
Returns whether an AST represents a getter method.- Parameters:
ast- the AST to check with- Returns:
- whether the AST represents a getter method
-
isSetterMethod
public static boolean isSetterMethod(DetailAST ast)
Returns whether an AST represents a setter method.- Parameters:
ast- the AST to check with- Returns:
- whether the AST represents a setter method
-
-