Class JavadocContentLocationCheck
- 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.JavadocContentLocationCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public class JavadocContentLocationCheck extends AbstractCheck
Checks that the Javadoc content begins from the same position for all Javadoc comments in the project. Any leading asterisks and spaces are not counted as the beginning of the content and are therefore ignored.It is possible to enforce two different styles:
-
first_line
- Javadoc content starts from the first line:/** Summary text. * More details. */ public void method();
-
second_line
- Javadoc content starts from the second line:/** * Summary text. * More details. */ public void method();
This check does not validate the Javadoc summary itself nor its presence. The check will not report any violations for missing or malformed javadoc summary. To validate the Javadoc summary use SummaryJavadoc check.
The Documentation Comment Specification permits leading asterisks on the first line. For these Javadoc comments:
/*** * Some text. */ /************ * Some text. */ /** ** * Some text. */
The documentation generated will be just "Some text." without any asterisks. Since these asterisks will not appear in the generated documentation, they should not be considered as the beginning of the Javadoc content. In such cases, the check assumes that the Javadoc content begins on the second line.
-
Property
location
- Specify the policy on placement of the Javadoc content. Type iscom.puppycrawl.tools.checkstyle.checks.javadoc.JavadocContentLocationOption
. Default value issecond_line
.
Parent is
com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
-
javadoc.content.first.line
-
javadoc.content.second.line
- Since:
- 8.27
-
-
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 JavadocContentLocationOption
location
Specify the policy on placement of the Javadoc content.static String
MSG_JAVADOC_CONTENT_FIRST_LINE
A key is pointing to the warning message text in "messages.properties" file.static String
MSG_JAVADOC_CONTENT_SECOND_LINE
A key is pointing to the warning message text in "messages.properties" file.
-
Constructor Summary
Constructors Constructor Description JavadocContentLocationCheck()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
findIndexOfFirstNonBlankLine(String commentContent)
Returns the index of the first non-blank line.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.boolean
isCommentNodesRequired()
Whether comment nodes are required or not.private static boolean
isMultilineComment(DetailAST node)
Checks if a DetailAST of typeTokenTypes.BLOCK_COMMENT_BEGIN
span more than one line.void
setLocation(String value)
Setter to specify the policy on placement of the Javadoc content.void
visitToken(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, 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_CONTENT_FIRST_LINE
public static final String MSG_JAVADOC_CONTENT_FIRST_LINE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_JAVADOC_CONTENT_SECOND_LINE
public static final String MSG_JAVADOC_CONTENT_SECOND_LINE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
location
private JavadocContentLocationOption location
Specify the policy on placement of the Javadoc content.
-
-
Constructor Detail
-
JavadocContentLocationCheck
public JavadocContentLocationCheck()
-
-
Method Detail
-
getRequiredTokens
public int[] getRequiredTokens()
Description copied from class:AbstractCheck
The tokens that this check must be registered for.- Specified by:
getRequiredTokens
in classAbstractCheck
- Returns:
- the token set this must be registered for.
- 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
-
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
-
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.
-
setLocation
public void setLocation(String value)
Setter to specify the policy on placement of the Javadoc content.- Parameters:
value
- string to decode location from- Throws:
IllegalArgumentException
- if unable to decode- Since:
- 8.27
-
visitToken
public void visitToken(DetailAST ast)
Description copied from class:AbstractCheck
Called to process a token.- Overrides:
visitToken
in classAbstractCheck
- Parameters:
ast
- the token to process
-
isMultilineComment
private static boolean isMultilineComment(DetailAST node)
Checks if a DetailAST of typeTokenTypes.BLOCK_COMMENT_BEGIN
span more than one line. The node always has at least one child of the typeTokenTypes.BLOCK_COMMENT_END
.- Parameters:
node
- node to check- Returns:
true
for multi-line comment nodes
-
findIndexOfFirstNonBlankLine
private static int findIndexOfFirstNonBlankLine(String commentContent)
Returns the index of the first non-blank line. All lines consists only of asterisks and whitespaces are treated as blank.- Parameters:
commentContent
- Javadoc content to process- Returns:
- the index of the first non-blank line or
-1
if all lines are blank
-
-