Class JavadocLinkWellKnownApiCheck
- All Implemented Interfaces:
Configurable,Contextualizable
{@link} and {@linkplain} tags
for APIs that are considered well-known. Linking well-known APIs can make comments harder to
read without adding much value for the reader.
This check reports {@link} references to configured well-known APIs.
Two properties are supported:
wellKnownQualifiedPackages and wellKnownSimpleNames.
Both properties are needed because Checkstyle does not resolve Javadoc link targets.
For example, java.lang.String contains the package name, so it can be
matched through wellKnownQualifiedPackages. However, String
only contains the simple name String, so it needs to be matched through
wellKnownSimpleNames. Resolution of imports is not a solution since
java.lang is implicitly imported.
For wellKnownQualifiedPackages, only references to classes that are
direct members of a well-known package are reported. References to a member
(for example, String#length()), a nested class (for example,
System.Logger), a subpackage (for example, java.lang.ref.WeakReference),
and a package itself (for example, java.lang.ref) are not reported.
- Since:
- 14.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charDot.static 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.Package names whose fully qualified API references should not be linked.Simple API names that should not be linked.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 newJavadocLinkWellKnownApiCheckinstance. -
Method Summary
Modifier and TypeMethodDescriptionint[]Returns the default javadoc token types a check is interested in.int[]The javadoc tokens that this check must be registered for.private booleanisWellKnownQualified(String apiName) Checks whether the given API name belongs to a well-known qualified package.final voidsetWellKnownQualifiedPackages(String... values) Setter to specify package names whose fully qualified API references should not be linked.final voidsetWellKnownSimpleNames(String... values) Setter to specify simple API names that should not be linked.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_WELL_KNOWN_API
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MSG_WELL_KNOWN_PACKAGE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
DOT
Dot.- See Also:
-
wellKnownQualifiedPackages
Package names whose fully qualified API references should not be linked. -
wellKnownSimpleNames
Simple API names that should not be linked.
-
-
Constructor Details
-
JavadocLinkWellKnownApiCheck
public JavadocLinkWellKnownApiCheck()Creates a newJavadocLinkWellKnownApiCheckinstance.
-
-
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:
-
setWellKnownQualifiedPackages
Setter to specify package names whose fully qualified API references should not be linked.- Parameters:
values- user's values.- Since:
- 14.1.0
-
setWellKnownSimpleNames
Setter to specify simple API names that should not be linked.- Parameters:
values- user's values.- Since:
- 14.1.0
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
ast- the token to process
-
isWellKnownQualified
Checks whether the given API name belongs to a well-known qualified package.- Parameters:
apiName- the API name to check- Returns:
- true if the API name belongs to a well-known qualified package
-