Class JavadocSeeTagOrderCheck
- All Implemented Interfaces:
Configurable,Contextualizable
@see tags are ordered in a predictable way,
roughly following the order in which their arguments are searched for by javadoc,
from nearest to farthest access, from least-qualified to fully-qualified.
The order of @see tags should be:
- local members first
- simple class references after local members
- simple class member references after simple class references
- qualified class references after simple class member references
- qualified class member references after qualified class references
- package references last
Inside each member group, fields come first, then constructors, then methods. Overloaded constructors and methods with the same name must be grouped together and ordered by the number of parameters, with the fewest parameters first.
For example, this is the order recommended by the OpenJDK documentation comments style guide:
@see #field @see #Constructor(Type, Type...) @see #Constructor(Type id, Type id...) @see #method(Type, Type,...) @see #method(Type id, Type, id...) @see Class @see Class#field @see Class#Constructor(Type, Type...) @see Class#Constructor(Type id, Type id) @see Class#method(Type, Type,...) @see Class#method(Type id, Type id,...) @see package.Class @see package.Class#field @see package.Class#Constructor(Type, Type...) @see package.Class#Constructor(Type id, Type id) @see package.Class#method(Type, Type,...) @see package.Class#method(Type id, Type, id) @see package
References that are not in a recognizable structured form (for example
@see "Effective Java", or an HTML anchor) are ignored for ordering
purposes, so the check only reports violations when it is confident about
the correct order. References using the Type##fragment syntax to
link to a named fragment within a page (rather than to a member) are
intentionally ignored as well, since such fragments are not javadoc type
or member references and cannot be meaningfully compared to one.
- Since:
- 14.2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumCategory of a@seereference, ordered from the closest to the most distant access.private static enumKind of a member@seereference, ordered from the closest to the most distant access.private static final recordRepresents a parsed@seereference together with the ordering information needed to validate the order.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charDot.private StringSimple name of the type that most closely encloses the current Javadoc comment.private static final charHash sign used to separate a type name from its member.private static final intNumber ofJavadocSeeTagOrderCheck.Kindvalues, used to combine category and kind into one key.The most recent reference for each member name within the current Javadoc tree.The most distant structural position seen so far in the current Javadoc tree.static final StringA key is pointing to the warning message text in "messages.properties" file.The reference that immediately precedes the current one.private static final BitSetToken types that represent a type declaration.Fields inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
MSG_JAVADOC_PARSE_RULE_ERROR, MSG_KEY_UNCLOSED_HTML_TAG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginJavadocTree(DetailNode rootAst) Called before the starting to process a tree.private static StringfindEnclosingTypeName(DetailAST commentBlock) Finds the simple name of the type declaration that most closely encloses the given block comment, so that local@see #Name()references can be recognized as referring to a constructor of that type.int[]Returns the default javadoc token types a check is interested in.int[]The javadoc tokens that this check must be registered for.private booleanChecks whether the current reference breaks the grouping of overloaded members with the same name.private static booleanisStructuralViolation(JavadocSeeTagOrderCheck.SeeReference current, JavadocSeeTagOrderCheck.SeeReference maximum) Checks whether the current reference breaks the structural order (category and field-before-constructor-before-method).private booleanChecks whether the current reference breaks the telescoping order of an overloaded constructor or method with the same name.private static booleanChecks whether the given node is a type declaration.private static StringlastByKey(JavadocSeeTagOrderCheck.SeeReference reference) Returns the map key that scopes a member name to its owning type and category group, so that grouping and telescoping checks only apply to overloads of the same member on the same type.voidCalled to process a Javadoc token.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, 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:
-
DOT
Dot.- See Also:
-
HASH
Hash sign used to separate a type name from its member.- See Also:
-
KIND_COUNT
Number ofJavadocSeeTagOrderCheck.Kindvalues, used to combine category and kind into one key.- See Also:
-
TYPE_DEFINITION_TOKENS
Token types that represent a type declaration. -
maxReference
The most distant structural position seen so far in the current Javadoc tree. -
previousReference
The reference that immediately precedes the current one. -
lastByName
The most recent reference for each member name within the current Javadoc tree. -
enclosingTypeName
Simple name of the type that most closely encloses the current Javadoc comment.
-
-
Constructor Details
-
JavadocSeeTagOrderCheck
public JavadocSeeTagOrderCheck()Creates a newJavadocSeeTagOrderCheckinstance.
-
-
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:
-
beginJavadocTree
Description copied from class:AbstractJavadocCheckCalled before the starting to process a tree.- Overrides:
beginJavadocTreein classAbstractJavadocCheck- Parameters:
rootAst- the root of the tree
-
findEnclosingTypeName
Finds the simple name of the type declaration that most closely encloses the given block comment, so that local@see #Name()references can be recognized as referring to a constructor of that type.- Parameters:
commentBlock- the block comment to start searching from- Returns:
- the enclosing type's simple name, or an empty string if none is found
-
isTypeDefinition
Checks whether the given node is a type declaration.- Parameters:
ast- the node to check- Returns:
trueif the node is a class, interface, enum, record, or annotation declaration
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
ast- the token to process
-
isStructuralViolation
private static boolean isStructuralViolation(JavadocSeeTagOrderCheck.SeeReference current, JavadocSeeTagOrderCheck.SeeReference maximum) Checks whether the current reference breaks the structural order (category and field-before-constructor-before-method).- Parameters:
current- the current referencemaximum- the greatest structural reference seen so far- Returns:
trueif the structural order is violated
-
isTelescopingViolation
Checks whether the current reference breaks the telescoping order of an overloaded constructor or method with the same name.- Parameters:
current- the current reference- Returns:
trueif the telescoping order is violated
-
isGroupingViolation
Checks whether the current reference breaks the grouping of overloaded members with the same name.- Parameters:
current- the current reference- Returns:
trueif the grouping is violated
-
lastByKey
Returns the map key that scopes a member name to its owning type and category group, so that grouping and telescoping checks only apply to overloads of the same member on the same type.- Parameters:
reference- the reference- Returns:
- the map key
-