Class JavadocLeadingAsteriskAlignCheck
- 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.AbstractJavadocCheck
-
- com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocLeadingAsteriskAlignCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public class JavadocLeadingAsteriskAlignCheck extends AbstractJavadocCheck
Checks the alignment of leading asterisks in a Javadoc comment. The Check ensures that leading asterisks are aligned vertically under the first asterisk ( * ) of opening Javadoc tag. The alignment of closing Javadoc tag ( */ ) is also checked. If a closing Javadoc tag contains non-whitespace character before it then it's alignment will be ignored. If the ending javadoc line contains a leading asterisk, then that leading asterisk's alignment will be considered, the closing Javadoc tag will be ignored.If you're using tabs then specify the the tab width in the tabWidth property.
-
Property
violateExecutionOnNonTightHtml
- Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Type isboolean
. Default value isfalse
.
Parent is
com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
-
javadoc.asterisk.indentation
-
javadoc.missed.html.close
-
javadoc.parse.rule.error
-
javadoc.unclosedHtml
-
javadoc.wrong.singleton.html.tag
- Since:
- 10.18.0
-
-
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 int
expectedColumnNumberTabsExpanded
Specifies the column number of starting block of the javadoc comment with tabs expanded.private int
expectedColumnNumberWithoutExpandedTabs
Specifies the column number of the leading asterisk without tabs expanded.private String[]
fileLines
Specifies the lines of the file being processed.private int
javadocStartLineNumber
Specifies the line number of starting block of the javadoc comment.static String
MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.-
Fields inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
MSG_JAVADOC_MISSED_HTML_CLOSE, MSG_JAVADOC_PARSE_RULE_ERROR, MSG_JAVADOC_WRONG_SINGLETON_TAG, MSG_KEY_UNCLOSED_HTML_TAG
-
-
Constructor Summary
Constructors Constructor Description JavadocLeadingAsteriskAlignCheck()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginJavadocTree(DetailNode rootAst)
Called before the starting to process a tree.private int
expandedTabs(String line, int columnNumber)
Processes and returns the column number of leading asterisk with tabs expanded.void
finishJavadocTree(DetailNode rootAst)
Called after finished processing a tree.private static Optional<Integer>
getAsteriskColumnNumber(String line)
Processes and returns an OptionalInt containing the column number of leading asterisk without tabs expanded.int[]
getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.int[]
getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.private static boolean
hasValidAlignment(int expectedColNumber, int asteriskColNumber)
Checks the column difference between expected column number and leading asterisk column number.private void
logViolation(int lineNumber, int asteriskColNumber, int expectedColNumber)
Checks alignment of asterisks and logs violations.void
visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.-
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginTree, destroy, finishTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitToken
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, 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_KEY
public static final String MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
javadocStartLineNumber
private int javadocStartLineNumber
Specifies the line number of starting block of the javadoc comment.
-
expectedColumnNumberTabsExpanded
private int expectedColumnNumberTabsExpanded
Specifies the column number of starting block of the javadoc comment with tabs expanded.
-
expectedColumnNumberWithoutExpandedTabs
private int expectedColumnNumberWithoutExpandedTabs
Specifies the column number of the leading asterisk without tabs expanded.
-
-
Constructor Detail
-
JavadocLeadingAsteriskAlignCheck
public JavadocLeadingAsteriskAlignCheck()
-
-
Method Detail
-
getDefaultJavadocTokens
public int[] getDefaultJavadocTokens()
Description copied from class:AbstractJavadocCheck
Returns the default javadoc token types a check is interested in.- Specified by:
getDefaultJavadocTokens
in classAbstractJavadocCheck
- Returns:
- the default javadoc token types
- See Also:
JavadocTokenTypes
-
getRequiredJavadocTokens
public int[] getRequiredJavadocTokens()
Description copied from class:AbstractJavadocCheck
The javadoc tokens that this check must be registered for.- Overrides:
getRequiredJavadocTokens
in classAbstractJavadocCheck
- Returns:
- the javadoc token set this must be registered for.
- See Also:
JavadocTokenTypes
-
beginJavadocTree
public void beginJavadocTree(DetailNode rootAst)
Description copied from class:AbstractJavadocCheck
Called before the starting to process a tree.- Overrides:
beginJavadocTree
in classAbstractJavadocCheck
- Parameters:
rootAst
- the root of the tree
-
visitJavadocToken
public void visitJavadocToken(DetailNode ast)
Description copied from class:AbstractJavadocCheck
Called to process a Javadoc token.- Specified by:
visitJavadocToken
in classAbstractJavadocCheck
- Parameters:
ast
- the token to process
-
finishJavadocTree
public void finishJavadocTree(DetailNode rootAst)
Description copied from class:AbstractJavadocCheck
Called after finished processing a tree.- Overrides:
finishJavadocTree
in classAbstractJavadocCheck
- Parameters:
rootAst
- the root of the tree
-
expandedTabs
private int expandedTabs(String line, int columnNumber)
Processes and returns the column number of leading asterisk with tabs expanded. Also sets 'expectedColumnNumberWithoutExpandedTabs' if the leading asterisk is present.- Parameters:
line
- javadoc comment linecolumnNumber
- column number of leading asterisk- Returns:
- column number of leading asterisk with tabs expanded
-
getAsteriskColumnNumber
private static Optional<Integer> getAsteriskColumnNumber(String line)
Processes and returns an OptionalInt containing the column number of leading asterisk without tabs expanded.- Parameters:
line
- javadoc comment line- Returns:
- asterisk's column number
-
logViolation
private void logViolation(int lineNumber, int asteriskColNumber, int expectedColNumber)
Checks alignment of asterisks and logs violations.- Parameters:
lineNumber
- line number of current comment lineasteriskColNumber
- column number of leading asteriskexpectedColNumber
- column number of javadoc starting token
-
hasValidAlignment
private static boolean hasValidAlignment(int expectedColNumber, int asteriskColNumber)
Checks the column difference between expected column number and leading asterisk column number.- Parameters:
expectedColNumber
- column number of javadoc starting tokenasteriskColNumber
- column number of leading asterisk- Returns:
- true if the asterisk is aligned properly, false otherwise
-
-