Class RequireEmptyLineBeforeBlockTagGroupCheck
- 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.RequireEmptyLineBeforeBlockTagGroupCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public class RequireEmptyLineBeforeBlockTagGroupCheck extends AbstractJavadocCheck
Checks that one blank line before the block tag if it is present in Javadoc.
-
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.missed.html.close
-
javadoc.parse.rule.error
-
javadoc.tag.line.before
-
javadoc.unclosedHtml
-
javadoc.wrong.singleton.html.tag
- Since:
- 8.36
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description static String
MSG_JAVADOC_TAG_LINE_BEFORE
The key in "messages.properties" for the message that describes a tag in javadoc requiring an empty line before it.private static List<Integer>
ONLY_TAG_VARIATION_1
Case when space separates the tag and the asterisk like in the below example.private static List<Integer>
ONLY_TAG_VARIATION_2
Case when no space separates the tag and the asterisk like in the below example.-
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 RequireEmptyLineBeforeBlockTagGroupCheck()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getDefaultJavadocTokens()
Returns only javadoc tags so visitJavadocToken only receives javadoc tags.int[]
getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.private static boolean
hasInsufficientConsecutiveNewlines(DetailNode tagNode)
Returns true when there are not enough empty lines before the provided tagNode.private static boolean
isAnotherTagBefore(DetailNode tagNode)
Returns true when there is a javadoc tag before the provided tagNode.private static boolean
isOnlyTagInWholeJavadoc(DetailNode tagNode)
Returns true when there are is only whitespace and asterisks before the provided tagNode.void
visitJavadocToken(DetailNode tagNode)
Logs when there is no empty line before the tag.-
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginJavadocTree, beginTree, destroy, finishJavadocTree, 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_JAVADOC_TAG_LINE_BEFORE
public static final String MSG_JAVADOC_TAG_LINE_BEFORE
The key in "messages.properties" for the message that describes a tag in javadoc requiring an empty line before it.- See Also:
- Constant Field Values
-
ONLY_TAG_VARIATION_1
private static final List<Integer> ONLY_TAG_VARIATION_1
Case when space separates the tag and the asterisk like in the below example./** * @param noSpace there is no space here
-
ONLY_TAG_VARIATION_2
private static final List<Integer> ONLY_TAG_VARIATION_2
Case when no space separates the tag and the asterisk like in the below example./** *@param noSpace there is no space here
-
-
Constructor Detail
-
RequireEmptyLineBeforeBlockTagGroupCheck
public RequireEmptyLineBeforeBlockTagGroupCheck()
-
-
Method Detail
-
getDefaultJavadocTokens
public int[] getDefaultJavadocTokens()
Returns only javadoc tags so visitJavadocToken only receives javadoc tags.- Specified by:
getDefaultJavadocTokens
in classAbstractJavadocCheck
- Returns:
- only javadoc tags.
- 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
-
visitJavadocToken
public void visitJavadocToken(DetailNode tagNode)
Logs when there is no empty line before the tag.- Specified by:
visitJavadocToken
in classAbstractJavadocCheck
- Parameters:
tagNode
- the at tag node to check for an empty space before it.
-
isAnotherTagBefore
private static boolean isAnotherTagBefore(DetailNode tagNode)
Returns true when there is a javadoc tag before the provided tagNode.- Parameters:
tagNode
- the javadoc tag node, to look for more tags before it.- Returns:
- true when there is a javadoc tag before the provided tagNode.
-
isOnlyTagInWholeJavadoc
private static boolean isOnlyTagInWholeJavadoc(DetailNode tagNode)
Returns true when there are is only whitespace and asterisks before the provided tagNode. When javadoc has only a javadoc tag like @ in it, the JAVADOC_TAG in a JAVADOC detail node will always have 2 or 3 siblings before it. The parse tree looks like:JAVADOC[3x0] |--NEWLINE[3x0] : [\n] |--LEADING_ASTERISK[4x0] : [ *] |--WS[4x2] : [ ] |--JAVADOC_TAG[4x3] : [@param T The bar.\n ]
Or it can also look like:JAVADOC[3x0] |--NEWLINE[3x0] : [\n] |--LEADING_ASTERISK[4x0] : [ *] |--JAVADOC_TAG[4x3] : [@param T The bar.\n ]
We do not include the variation/**@param noSpace there is no space here
which results in the treeJAVADOC[3x0] |--JAVADOC_TAG[4x3] : [@param noSpace there is no space here\n ]
because this one is invalid. We must recommend placing a blank line to separate @param from the first javadoc asterisks.- Parameters:
tagNode
- the at tag node to check if there is nothing before it- Returns:
- true if there is no text before the tagNode
-
hasInsufficientConsecutiveNewlines
private static boolean hasInsufficientConsecutiveNewlines(DetailNode tagNode)
Returns true when there are not enough empty lines before the provided tagNode.Iterates through the previous siblings of the tagNode looking for empty lines until there are no more siblings or it hits something other than asterisk, whitespace or newline. If it finds at least one empty line, return true. Return false otherwise.
- Parameters:
tagNode
- the tagNode to check if there are sufficient empty lines before it.- Returns:
- true if there are not enough empty lines before the tagNode.
-
-