Skip to content

Commit 7ab2bc8

Browse files
committed
some comments
1 parent dbac532 commit 7ab2bc8

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

doc/dart_documentation_comment_specification.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ This document does not cover:
3232
### **1.3. Terminology**
3333

3434
* **Doc Comment:** A comment intended to be processed by documentation generation tools, like dartdoc.
35-
* **Element**: A specific, declared element in the Dart code, such as a class, method, function, variable, or type parameter.
36-
* **Identifier:** An individual name in the code (e.g., `MyClass`, myMethod, prefix).
35+
* **Element**: Dart declarations or directives that can have documentation or be referenced in a doc comment: library directives, top-level, or member declarations such as class, menthod, or variable.
36+
* **Identifier:** An individual name in the code (e.g., `MyClass`, `myMethod`, `prefix`).
3737
* **Qualified Name:** A name composed of two or more *identifiers* separated by dots, used to access an element within a specific namespace (e.g., MyClass.myMethod, prefix.MyClass).
38+
* **Name:** A name is either a single *identifier* or a *qualified name*.
3839
* **Reference:** A string enclosed in square brackets within a doc comment (e.g., `[MyClass]` or `[MyClass.myMethod]`) that links to an element. The text inside the brackets is either a single *identifier* or a *qualified name*.
3940

4041
## **2\. Syntax of Documentation Comments**
@@ -62,11 +63,11 @@ This document does not cover:
6263

6364
### **2.3. Content Format (Markdown)**
6465

65-
The text within a documentation comment block is parsed as Markdown, allowing for rich text formatting. This includes headings, lists, code blocks, and emphasis, which are converted for instance to HTML in the generated documentation.
66+
The text within a documentation comment block is parsed as CommonMark markdown, allowing for rich text formatting. This includes headings, lists, code blocks, and emphasis, which are converted for instance to HTML in the generated documentation.
6667

6768
### **2.4. References**
6869

69-
A reference is a special directive within the Markdown content that creates a hyperlink to a Dart element. It is written by enclosing a Dart identifier in square brackets (e.g., `[foo]`). See [Section 4](#4.-referenceable-elements) for detailed information about which elements can be referenced.
70+
A reference is a special directive within the Markdown content that creates a hyperlink to a Dart element. It is written by enclosing a name in square brackets (e.g., `[foo]`). See [Section 4](#4.-referenceable-elements) for detailed information about which elements can be referenced.
7071

7172
Conceptually, these behave like [reference-style links](https://www.markdownguide.org/basic-syntax/#reference-style-links) in Markdown. The documentation generator resolves the name against the available source code to create the link's destination. See [Section 5](#5.-reference-lookup-and-resolution) for detailed resolution rules.
7273

@@ -96,7 +97,7 @@ Doc comments are associated with the declaration that immediately follows them.
9697
* Methods (instance, static)
9798
* Operators
9899
* Fields (instance, static)
99-
* Getters or setters (Not both, prefer getter)
100+
* Getters or setters (See [Section 6.2.2](#6.2.2.-getters-and-setters) for details)
100101

101102
### **3.4. Enum Constants**
102103

@@ -126,16 +127,16 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
126127

127128
### **4.3. Members**
128129

129-
* Methods (e.g., `[myMethod]`, `[MyClass.myMethod]`,` `[MyClass.myMethod()]`)
130+
* Methods (e.g., `[myMethod]`, `[MyClass.myMethod]`)
130131
* Fields (constants and variables) (e.g., `[myField]`, `[MyClass.myField]`)
131132
* Getters and Setters (See [Section 6.2.2](#6.2.2.-getters-and-setters) for full details)
132-
* Constructors (e.g., `[MyClass.new]`, `[MyClass.named]`, `[MyClass.named()]`)
133+
* Constructors (e.g., `[MyClass.new]`, `[MyClass.named]`)
133134
* Enum constants (e.g., `[MyEnum.value]`)
134135

135136
### **4.4. Local Scope Parameters (within a member's doc comment):**
136137

137138
* Parameters of the documented method/function (e.g., `[parameterName]`)
138-
* Type parameters of the documented element (e.g., `[T]`)
139+
* Type parameters of the documented element and the enclosing element (e.g., `[T]`)
139140

140141
## **5\. Reference Lookup and Resolution**
141142

@@ -151,7 +152,7 @@ When a name is enclosed in square brackets (e.g., `[MyClass.myMethod]`), documen
151152

152153
### **5.2. Scope Precedence Hierarchy**
153154

154-
The resolution process for a reference `[name]` follows the standard Dart scope of the documented element with the extension of the doc imported scope at the end. Search is done in a specific order of precedence from the narrowest (most local) scope to the broadest (globally available).
155+
The resolution process for a reference `[name]` follows the standard Dart scope of the documented element with the extension of the doc imported scope at the end. The resolution starts with the first *identifier* of a name. Search is done in a specific order of precedence from the narrowest (most local) scope to the broadest (globally available).
155156

156157
The hierarchy is searched from the inside out. Below is an example for an instance method:
157158
```
@@ -180,7 +181,7 @@ The hierarchy is searched from the inside out. Below is an example for an instan
180181
```
181182
### **5.3. Detailed Lookup Process**
182183

183-
The lookup process begins at a specific "starting scope" determined by the context of the doc comment and then follows the scope hierarchy.
184+
The lookup process begins at a specific "starting scope" determined by the context of the doc comment and then follows the scope hierarchy.
184185

185186
The following sections detail the starting scope for each type of declaration.
186187

@@ -210,7 +211,9 @@ class MyClass<T> {
210211
/// * [R]: Resolves to the method type parameter (Method Type Parameter Scope).
211212
/// * [value]: Resolves to the class member (Class Member Scope).
212213
/// * [myStaticMethod]: Resolves to the static class member (Class Member Scope).
214+
/// * [myMethod]: Resolves to this method itself (Class Member Scope).
213215
/// * [T]: Resolves to the class type parameter (Class Type Parameter Scope).
216+
/// * [MyClass]: Resolves to the parent class (Library Scope).
214217
/// * [AnotherClass]: Resolves to the library member (Library Scope).
215218
/// * [List]: Resolves from 'dart:core' (Imported Scopes).
216219
/// * [JsonCodec]: Resolves from 'dart:convert' (Imported Scope).
@@ -262,6 +265,7 @@ For doc comments placed directly on classes, enums, mixins, extensions, extensio
262265
/// * [input]: Resolves to the parameter (Formal Parameter Scope).
263266
/// * [R]: Resolves to the function type parameter (Function Type Parameter Scope).
264267
/// * [globalConstant]: Resolves to the library member (Library Scope).
268+
/// * [topLevelFunction]: Resolves to the function itself (Library Scope).
265269
/// * [String]: Resolves from 'dart:core'(Imported Scope).
266270
R topLevelFunction<R>(String input) {
267271
// ...
@@ -271,6 +275,7 @@ R topLevelFunction<R>(String input) {
271275
///
272276
/// Lookup examples:
273277
/// * [topLevelFunction]: Resolves to the library member (Library Scope).
278+
/// * [globalConstant]: Resolves to the variable itself (Library Scope).
274279
/// * [Duration]: Resolves from 'dart:core' (Imported Scope).
275280
/// * [Random]: Resolves from 'dart:math' (Doc Imported Scope).
276281
const int globalConstant = 10;
@@ -281,6 +286,7 @@ const int globalConstant = 10;
281286
/// * [myMethod]: Resolves to the class member (Class Member Scope).
282287
/// * [T]: Resolves to the class type parameter (Class Type Parameter Scope).
283288
/// * [topLevelFunction]: Resolves to the library member (Library Scope).
289+
/// * [MyClass]: Resolves to the class itself (Library Scope).
284290
/// * [List]: Resolves from 'dart:core' (Imported Scopes).
285291
/// * [Random]: Resolves from 'dart:math' (Doc Imported Scope).
286292
class MyClass<T> {
@@ -312,7 +318,8 @@ class AnotherClass {}
312318
/// A typedef for a Map.
313319
///
314320
/// Lookup examples:
315-
/// * [T]: Resolves to the typedef type parameter (typedef type parameter scope).
321+
/// * [T]: Resolves to the typedef type parameter (Typedef Type Parameter Scope).
322+
/// * [JsonMap]: Resolves to the typedef itself (Library Scope).
316323
/// * [AnotherClass]: Resolves to the library member (Library Scope).
317324
/// * [Map]: Resolves from 'dart:core' (Imported Scope).
318325
/// * [String]: Resolves from 'dart:core' (Imported Scope).
@@ -364,23 +371,23 @@ If an Identifier resolves to one of the following elements, it establishes a new
364371
*Case 1: Import Prefix*
365372

366373
* **Namespace:** The export scope of the imported library, as filtered by any show or hide combinators on the import directive.
367-
* **Example:** In `[math.pi]`, the identifier `math` resolves to an import prefix (e.g., from `import dart:math' as math;`). The tool then searches the public namespace of dart:math for the identifier pi.
368-
* **Combinator Example:** If the import was import 'dart:math' as math show sin;, the namespace for math would *only* contain sin. A reference to `[math.pi]` would fail to resolve, as `pi` was not included in the show list.
374+
* **Example:** In `[math.pi]`, the identifier `math` resolves to an import prefix (e.g., from `import 'dart:math' as math;`). The tool then searches the public namespace of dart:math for the identifier pi.
375+
* **Combinator Example:** If the import was `import 'dart:math' as math show sin;`, the namespace for `math` would *only* contain `sin`. A reference to `[math.pi]` would fail to resolve, as `pi` was not included in the show list.
369376

370377
*Case 2: Class-like top-level declaration*
371378

372-
* **Namespace:** The set of all members declared within that element, including:
373-
* Instance Members (fields, methods, etc.)
379+
* **Namespace:** The set of all members accesible on that element, including:
380+
* Instance Members (fields, methods, etc.), including those inherited from supertypes.
374381
* Static Members
375382
* Constructors
376383

377384
* **Notes on Generics:**
378-
* The namespace does not include the element's own type parameters. For a class `MyClass<T>`, a reference like `[MyClass.T]` is invalid because T is not a member of `MyClass`'s namespace.
385+
* The namespace does not include the element's own type parameters. For a class `MyClass<T>`, a reference like `[MyClass.T]` is invalid because `T` is not a member of `MyClass`'s namespace.
379386
* References are also made to the generic declaration, not a specific instantiation (e.g., write `[List.filled]`, not `[List<int>.filled]`).
380387
* **Example:** To resolve the reference `[collection.BoolList.empty]`:
381-
* The identifier collection resolves to an import prefix.
382-
* The identifier BoolList resolves to a class element within the collection library's public namespace.
383-
* The identifier empty resolves to a named constructor element within the BoolList class's member namespace.
388+
* The identifier `collection` resolves to an import prefix.
389+
* The identifier `BoolList` resolves to a class element within the `collection` library's public namespace.
390+
* The identifier `empty` resolves to a named constructor element within the `BoolList` class's member namespace.
384391

385392
**Leaf Elements (Empty Namespace)**
386393

@@ -423,12 +430,12 @@ class A {
423430
424431
/// An instance method.
425432
void foo() {}
426-
}
427433
428434
/// Usage in documentation:
429435
/// * [foo] -> Resolves to the method foo().
430436
/// * [A.foo] -> Resolves to the constructor A.foo().
431437
438+
}
432439
```
433440

434441
* **Getters and Setters:** A reference to a property name (e.g., `[value]`) resolves to the *conceptual property* rather than the individual getter or setter. See full discussion in [Section 6.2.2](#6.2.2.-getters-and-setters).
@@ -453,9 +460,9 @@ When a member overrides an ancestor, its documentation is determined by a set of
453460

454461
* **Explicit Documentation:** If an overriding member does have its own doc comment, that comment takes full precedence. The documentation from any base members is ignored.
455462

456-
* **Unambiguous Documentation Inheritance** If a member overrides a member from an ancestor and does not have its own doc comment, it inherits the documentation from the base member. This rule applies when the source of the documentation is unambiguous (e.g., overriding a single concrete method). Documentation tools should display this inherited comment, ideally noting its origin (e.g., "Copied from BaseClass").
463+
* **Unambiguous Documentation Inheritance:** If a member overrides a member from an ancestor and does not have its own doc comment, it inherits the documentation from the base member. This rule applies when the source of the documentation is unambiguous (e.g., overriding a single method). Documentation tools should display this inherited comment, ideally noting its origin (e.g., "Copied from BaseClass").
457464

458-
* **Ambiguous Documentation from Multiple Ancestors** The behavior for resolving documentation when a member inherits conflicting documentation from multiple ancestors is *reserved for future standardization*. Currently, tools may handle this case at their discretion, or ignore inherited documentation in ambiguous scenarios. It is recommended that tools *issue a warning* when this scenario is encountered, prompting the user to provide explicit documentation to resolve the ambiguity.
465+
* **Ambiguous Documentation from Multiple Ancestors:** The behavior for resolving documentation when a member inherits conflicting documentation from multiple ancestors is *reserved for future standardization*. Currently, tools may handle this case at their discretion, or ignore inherited documentation in ambiguous scenarios. It is recommended that tools *issue a warning* when this scenario is encountered, prompting the user to provide explicit documentation to resolve the ambiguity.
459466

460467
#### **6.2.2. Getters and Setters**
461468

@@ -469,10 +476,10 @@ Documentation tools should handle this property with the following rules:
469476
* The tooling should *issue a warning* if both a getter and its corresponding setter have unique doc comments.
470477
* The only situation the documentation of the setter is considered is in the case of no getter existing.
471478
* **Reference:** A reference to a property name (e.g., `[value]`) resolves to the conceptual property rather than the individual getter or setter. This applies in all cases where a getter and setter share the same name, including:
472-
* When an explicit getter (get value) and setter (set value(...)) are declared.
479+
* When an explicit getter (`get value`) and setter (s`et value(...)`) are declared.
473480
* When a final field (which acts as an implicit getter) is paired with an explicit setter of the same name.
474481
* When a getter and setter for the same property are brought into scope, even if they are imported from different libraries.
475482

476483
#### **6.2.3. Parameters**
477484

478-
Parameters of functions, methods, and constructors do not have their own preceding doc comments. They are documented within the doc comment of their enclosing element using square brackets `[p]`.
485+
Parameters of functions, methods, and constructors do not have their own preceding doc comments. They are documented within the doc comment of their enclosing element and referenced using an element reference `[p]`.

0 commit comments

Comments
 (0)