diff --git a/closed/src/jdk.javadoc/share/specs/javadoc/doc-comment-spec.md b/closed/src/jdk.javadoc/share/specs/javadoc/doc-comment-spec.md index 6d0d6e5bab..df7b46726f 100644 --- a/closed/src/jdk.javadoc/share/specs/javadoc/doc-comment-spec.md +++ b/closed/src/jdk.javadoc/share/specs/javadoc/doc-comment-spec.md @@ -129,72 +129,73 @@ indentation preserved. Spaces are interpreted by browsers more uniformly than tabs. Indentation is relative to the left margin (rather than the separator `/**` or `
` tag). -## Comment Inheritance +## Method Documentation -### Class and Interface Inheritance +When the standard doclet encounters a method declaration that needs to be +documented, the doclet looks for the following: -Comment inheritance occurs in all possible cases of inheritance from classes -and interfaces: +* The main description -* When a method in a class overrides a method in a superclass -* When a method in an interface overrides a method in a superinterface -* When a method in a class implements a method in an interface +* A [`@param`](#param) tag for each of the type parameters, if any -In the first two cases, the standard doclet generates the subheading "Overrides" -in the documentation for the overriding method. A link to the method being -overridden is included, whether or not the comment is inherited. +* One of [`@return` or `{@return ...}`](#return) tag for the result, if the + return type is not `void` -In the third case, when a method in a specified class implements a method in an -interface, the standard doclet generates the subheading "Specified by" in the -documentation for the overriding method. A link to the method being implemented -is included, whether or not the comment is inherited. +* A `@param` tag for each of the formal parameters, if any -### Method Comment Inheritance +* At least one [`@throws`](#throws) tag for each exception type in the `throws` + clause, if any -The standard doclet allows method comment inheritance in classes and interfaces -to fill in missing text or to explicitly inherit method comments. -Constructors, fields, and nested classes do not inherit documentation comments. +The doclet first looks for the above items in the documentation comment for the +declaration. Any item that the doclet cannot find there is considered missing, +unless this is an overriding method declaration ([JLS 9.6.4.4][]), in which case +the item is considered as if it had an appropriate tag with [`{@inheritDoc}`](#inheritdoc) +as its description. The doclet then processes all found and as-if items as +described in the following section. -Note: The source file for an inherited method must be on the path specified by -the `-sourcepath` option for the documentation comment to be available to copy. -Neither the class nor its package needs to be passed in on the command line. +### Algorithm for Processing the `{@inheritDoc ...}` Tags -#### Fill in Missing Text +When processing a description of a declaration of a method, replace +`{@inheritDoc ...}` tags: -When a main description, or `@return`, `@param`, or `@throws` tag is missing -from a method comment, the information is copied from the method it overrides or -implements (if any). +* Replace `{@inheritDoc S}` with the corresponding description of a method in + `S` that this method overrides, after applying this algorithm recursively to + that description. Raise an error if this method does not override a method in + `S` or `S` encloses this declaration. +* Replace `{@inheritDoc}` with the corresponding description of a method that + this method overrides, after applying this algorithm recursively to that + description. Look for the overridden method as follows; if not found, consider + the description missing. + 1. Look in the immediate superclass. If there is no such method or its + description is missing, then + 2. Look in the immediate superinterfaces in the order that they appear in + the `implements` or `extends` clause. Pick the first method whose + corresponding description is present, after applying this algorithm + recursively to that description. If there is no such method, raise an + error. -When an `@param` tag for a particular parameter is missing, the comment for that -parameter is copied from the method further up the inheritance hierarchy. -When an `@throws` tag for a particular exception is missing, the `@throws` tag -is copied only when that exception is declared. +To provide for a declaration whose signature is override-equivalent with a +public method of `java.lang.Object` ([JLS 8.4.2][]), the above algorithm behaves +as if an interface had a superclass `java.lang.Object`. -#### Explicit Inheritance +Note: The source file for an inherited method must be on the path specified by +the `-sourcepath` option for the documentation comment to be available to copy. +Neither the class nor its package needs to be passed in on the command line. + +[jls 9.6.4.4]: https://docs.oracle.com/javase/specs/jls/se@@VERSION_SPECIFICATION@@/html/jls-9.html#jls-9.6.4.4 +[jls 8.4.2]: https://docs.oracle.com/javase/specs/jls/se@@VERSION_SPECIFICATION@@/html/jls-8.html#jls-8.4.2 -Insert the `{@inheritDoc}` inline tag in a method main description or `@return`, -`@param`, or `@throws` tag comment. The corresponding inherited main description -or tag comment is copied into that spot. +### Overriding Methods in Classes and Interfaces -### Method Comments Algorithm +When a method declaration overrides a method in the superclass or an extended +superinterface, the standard doclet generates the subheading "Overrides" in the +documentation for the overriding method. -If a method does not have a documentation comment, or has an `{@inheritDoc}` tag, -then the standard doclet uses the following algorithm to search for an -applicable comment. The algorithm is designed to find the most specific -applicable documentation comment, and to give preference to interfaces over -superclasses: +When a method declaration in a class overrides a method in an interface, the +standard doclet generates the subheading "Specified by" in the documentation for +the overriding method. -1. Look in each directly implemented (or extended) interface in the order they - appear following the word `implements` (or `extends`) in the type declaration. - Use the first documentation comment found for this method. -2. If Step 1 failed to find a documentation comment, then recursively apply this - entire algorithm to each directly implemented (or extended) interface in the - same order they were examined in Step 1. -3. When Step 2 fails to find a documentation comment and this is a class other - than the Object class, but not an interface: - a. If the superclass has a documentation comment for this method, then use it. - b. If Step 3a failed to find a documentation comment, then recursively apply - this entire algorithm to the superclass. +In both cases, a link to the overridden method is included. ## Standard Tags @@ -328,11 +329,12 @@ Introduced in JDK 9. ### {@inheritDoc} * `{@inheritDoc}` +* `{@inheritDoc _supertype_}` -Inherits (copies) documentation from the nearest inheritable class or -implementable interface into the current documentation comment at this tag's +Inherits (copies) documentation from a superclass or +a superinterface into the current documentation comment at this tag's location. This enables you to write more general comments higher up the -inheritance tree and to write around the copied text. +inheritance hierarchy and to write around the copied text. This tag is valid only in these places in a documentation comment: @@ -344,10 +346,8 @@ hierarchy. See [Method Comment Inheritance](#method-comment-inheritance) for a description of how comments are found in the inheritance hierarchy. -Note that if this tag is missing, then the comment is or is not automatically -inherited according to rules described in that section. -Introduced in JDK 1.4. +Introduced in JDK 1.4; accepts an optional argument since JDK 19. ### {@link} @@ -910,12 +910,6 @@ not exist for an exception in the throws clause, the standard doclet adds that exception to the generated output (with no description) as if it were documented with the `@throws` tag. -The `@throws` documentation is copied from an overridden method to a subclass -only when the exception is explicitly declared in the overridden method. -The same is true for copying from an interface method to an implementing method. -You can use the `{@inheritDoc}` tag to force the `@throws` tag to inherit -documentation. - The [`@exception`](#exception) tag is equivalent to this tag, although the `@throws` form is now recommended.