Class PreferCodeOrSnippetJavadocInlineTagCheck
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.PreferCodeOrSnippetJavadocInlineTagCheck
- All Implemented Interfaces:
Configurable,Contextualizable
Checks that Javadoc inline tags
{@code ...} and {@snippet ...}
are preferred over HTML tags <code> and <pre>.
This check enforces using either {@code ...} or {@snippet ...} inline tags
instead of single-line <code> and <pre> HTML tags, and using
{@snippet ...} inline tags instead of multi-line <code> and <pre>
HTML tags.
Per OpenJDK Style Guidelines v6, Javadoc inline tags should be preferred over their HTML equivalents.
To suppress violation for snippet inline tag:
<module name="SuppressionSingleFilter">
<property name="checks" value="PreferCodeOrSnippetJavadocInlineTag"/>
<property name="files" value="file-name"/>
<property name="message" value="Use snippet inline tag instead of.*"/>
</module>
- Tags which have unbalanced curly braces
- Tags which have content that starts with star.
- Tags which are inside other tags
- Since:
- 14.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA key is pointing to the warning message text in "messages.properties" file.static final StringA 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_PARSE_RULE_ERROR, MSG_KEY_UNCLOSED_HTML_TAG -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newPreferCodeOrSnippetJavadocInlineTagCheckinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<DetailNode> collectTextNodes(DetailNode node) Collects all text nodes contained within the specified node, including text nested inside HTML elements and inline tags.static booleancontainsBalancedBraces(Iterable<DetailNode> listOfTextNodes) Checks if the text list contains balanced braces.int[]Returns the default javadoc token types a check is interested in.private static StringgetHtmlTagName(DetailNode htmlElement) Gets the tag name from an HTML_ELEMENT node.int[]The javadoc tokens that this check must be registered for.private static List<DetailNode> getTextNodesFromInlineTags(Iterable<DetailNode> inlineTags) Extracts text nodes from child nodes of the provided list of inline tags.private static booleanisCodeOrPreTag(DetailNode node) Checks if the tag is code or pre tag.private static booleanisCompleteTag(DetailNode node) Checks if the tag is complete.static booleanisConvertableInInlineTag(Iterable<DetailNode> listOfTextNodes) Checks if the tag is convertable in inline tag.private static booleanisNested(DetailNode node) Checks if the tag is nested inside any other code or pre tag.private static booleanisSingleLineTag(DetailNode node) Checks if the tag is single-line.private static booleanisStartWithStar(Iterable<DetailNode> listOfTextNodes) Checks if the first element of the text list starts with a star.voidvisitJavadocToken(DetailNode node) Called to process a Javadoc token.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginJavadocTree, beginTree, destroy, finishJavadocTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, log, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitTokenMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_KEY_SINGLE_LINE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MSG_KEY_MULTI_LINE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
-
Constructor Details
-
PreferCodeOrSnippetJavadocInlineTagCheck
Creates a newPreferCodeOrSnippetJavadocInlineTagCheckinstance.
-
-
Method Details
-
getRequiredJavadocTokens
Description copied from class:AbstractJavadocCheckThe javadoc tokens that this check must be registered for.- Overrides:
getRequiredJavadocTokensin classAbstractJavadocCheck- Returns:
- the javadoc token set this must be registered for.
- See Also:
-
getDefaultJavadocTokens
Description copied from class:AbstractJavadocCheckReturns the default javadoc token types a check is interested in.- Specified by:
getDefaultJavadocTokensin classAbstractJavadocCheck- Returns:
- the default javadoc token types
- See Also:
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
node- the token to process
-
isCodeOrPreTag
Checks if the tag is code or pre tag.- Parameters:
node- the node to check- Returns:
trueif the tag is code or pre tag,falseotherwise
-
isNested
Checks if the tag is nested inside any other code or pre tag.- Parameters:
node- the node to check- Returns:
trueif the tag is nested,falseotherwise
-
isConvertableInInlineTag
Checks if the tag is convertable in inline tag.- Parameters:
listOfTextNodes- the list of text nodes to check.- Returns:
trueif the tag is convertable in inline tag,falseotherwise.
-
containsBalancedBraces
Checks if the text list contains balanced braces.- Parameters:
listOfTextNodes- the list of text nodes to check- Returns:
trueif the text list contains balanced braces,falseotherwise
-
isStartWithStar
Checks if the first element of the text list starts with a star.- Parameters:
listOfTextNodes- the list of text nodes to check- Returns:
trueif the first element of the text list does not start with a star,falseotherwise
-
collectTextNodes
Collects all text nodes contained within the specified node, including text nested inside HTML elements and inline tags.- Parameters:
node- the rootDetailNodeto extract text nodes from- Returns:
- a list of text
DetailNodeinstances
-
getTextNodesFromInlineTags
Extracts text nodes from child nodes of the provided list of inline tags.- Parameters:
inlineTags- the list of inline tagDetailNodes- Returns:
- a list of text
DetailNodeinstances found inside the inline tags
-
isSingleLineTag
Checks if the tag is single-line.- Parameters:
node- the node to check- Returns:
trueif the tag is single-line,falseotherwise
-
isCompleteTag
Checks if the tag is complete.- Parameters:
node- the node to check- Returns:
trueif the tag is complete,falseotherwise
-
getHtmlTagName
Gets the tag name from an HTML_ELEMENT node.- Parameters:
htmlElement- the HTML_ELEMENT node- Returns:
- the tag name (e.g., "code", "pre")
-