Class PreferLiteralJavadocInlineTagCheck
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.PreferLiteralJavadocInlineTagCheck
- All Implemented Interfaces:
Configurable,Contextualizable
Checks that Javadoc inline tags are preferred over escaping entities.
According to
OpenJDK Style Guidelines v6
Javadoc inline tags should be preferred over their HTML equivalents.
Entities that are flagged by the check are:
- <
- >
- &
- "
- '
Reason of only these entities are flagged is given here : Predefined Entities
Not flagged:
- Content inside
<pre>and<code>blocks (code examples) - Content inside
{@code},{@literal},{@snippet}inline tags
- Since:
- 13.11.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionHTML entities to be replaced with{@literal ...}.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 newPreferJavadocInlineTagsCheckinstance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckForHtmlEntities(DetailNode textNode) Checks Javadoc TEXT nodes for HTML entities that should be replaced with{@literal ...}.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 booleanisInsideInlineTag(DetailNode node) Checks if the node is inside a{@code},{@literal}or{@snippet}inline tag.private static booleanChecks if the node is inside a pre or code tag.voidCalled 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
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
HTML_ENTITIES
HTML entities to be replaced with{@literal ...}.
-
-
Constructor Details
-
PreferLiteralJavadocInlineTagCheck
public PreferLiteralJavadocInlineTagCheck()Creates a newPreferJavadocInlineTagsCheckinstance.
-
-
Method Details
-
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:
-
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:
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
ast- the token to process
-
checkForHtmlEntities
Checks Javadoc TEXT nodes for HTML entities that should be replaced with{@literal ...}.- Parameters:
textNode- the TEXT node to check
-
getHtmlTagName
Gets the tag name from an HTML_ELEMENT node.- Parameters:
htmlElement- the HTML_ELEMENT node- Returns:
- the tag name (e.g., "code", "a")
-
isInsidePreOrCodeTag
Checks if the node is inside a pre or code tag.- Parameters:
node- the node to check- Returns:
- true if inside a pre or code block
-
isInsideInlineTag
Checks if the node is inside a{@code},{@literal}or{@snippet}inline tag. Content inside these tags is meant to be displayed literally, so HTML patterns within them are intentional examples and should not be flagged.- Parameters:
node- the node to check- Returns:
- true if inside a code, literal or snippet inline tag
-