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.
location - Specify the policy on placement of the Javadoc content.
Type is com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocContentLocationOption.
Default value is second_line.
To configure the default check to validate that the Javadoc content starts from the second line:
<module name="JavadocContentLocationCheck"/>
This setting produces a violation for each multi-line comment starting on the same line as the initial asterisks:
/** This comment causes a violation because it starts from the first line * and spans several lines. */ /** * This comment is OK because it starts from the second line. */ /** This comment is OK because it is on the single line. */
To ensure that Javadoc content starts from the first line:
<module name="JavadocContentLocationCheck"> <property name="location" value="first_line"/> </module>
This setting produces a violation for each comment not starting on the same line as the initial asterisks:
/** This comment is OK because it starts on the first line.
* There may be additional text.
*/
/**
* This comment causes a violation because it starts on the second line.
*/
/** This single-line comment also is OK. */
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
javadoc.content.first.line
javadoc.content.second.line
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
private JavadocContentLocationOption |
location
Specify the policy on placement of the Javadoc content.
|
static java.lang.String |
MSG_JAVADOC_CONTENT_FIRST_LINE
A key is pointing to the warning message text in "messages.properties" file.
|
static java.lang.String |
MSG_JAVADOC_CONTENT_SECOND_LINE
A key is pointing to the warning message text in "messages.properties" file.
|
| Constructor and Description |
|---|
JavadocContentLocationCheck() |
| Modifier and Type | Method and Description |
|---|---|
private static int |
findIndexOfFirstNonBlankLine(java.lang.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 type
TokenTypes.BLOCK_COMMENT_BEGIN span
more than one line. |
void |
setLocation(java.lang.String value)
Setter to specify the policy on placement of the Javadoc content.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearViolations, destroy, finishTree, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_JAVADOC_CONTENT_FIRST_LINE
public static final java.lang.String MSG_JAVADOC_CONTENT_SECOND_LINE
private JavadocContentLocationOption location
public JavadocContentLocationCheck()
public int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic boolean isCommentNodesRequired()
AbstractCheckisCommentNodesRequired in class AbstractCheckpublic void setLocation(java.lang.String value)
value - string to decode location fromjava.lang.IllegalArgumentException - if unable to decodepublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processprivate static boolean isMultilineComment(DetailAST node)
TokenTypes.BLOCK_COMMENT_BEGIN span
more than one line. The node always has at least one child of the type
TokenTypes.BLOCK_COMMENT_END.node - node to checktrue for multi-line comment nodesprivate static int findIndexOfFirstNonBlankLine(java.lang.String commentContent)
commentContent - Javadoc content to process-1 if all lines are blankCopyright © 2001-2022. All Rights Reserved.