You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/dart_documentation_comment_specification.md
+31-24Lines changed: 31 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,9 +32,10 @@ This document does not cover:
32
32
### **1.3. Terminology**
33
33
34
34
***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`).
37
37
***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*.
38
39
***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*.
39
40
40
41
## **2\. Syntax of Documentation Comments**
@@ -62,11 +63,11 @@ This document does not cover:
62
63
63
64
### **2.3. Content Format (Markdown)**
64
65
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.
66
67
67
68
### **2.4. References**
68
69
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.
70
71
71
72
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.
72
73
@@ -96,7 +97,7 @@ Doc comments are associated with the declaration that immediately follows them.
96
97
* Methods (instance, static)
97
98
* Operators
98
99
* 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)
100
101
101
102
### **3.4. Enum Constants**
102
103
@@ -126,16 +127,16 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
### **4.4. Local Scope Parameters (within a member's doc comment):**
136
137
137
138
* 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]`)
139
140
140
141
## **5\. Reference Lookup and Resolution**
141
142
@@ -151,7 +152,7 @@ When a name is enclosed in square brackets (e.g., `[MyClass.myMethod]`), documen
151
152
152
153
### **5.2. Scope Precedence Hierarchy**
153
154
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).
155
156
156
157
The hierarchy is searched from the inside out. Below is an example for an instance method:
157
158
```
@@ -180,7 +181,7 @@ The hierarchy is searched from the inside out. Below is an example for an instan
180
181
```
181
182
### **5.3. Detailed Lookup Process**
182
183
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.
184
185
185
186
The following sections detail the starting scope for each type of declaration.
186
187
@@ -210,7 +211,9 @@ class MyClass<T> {
210
211
/// * [R]: Resolves to the method type parameter (Method Type Parameter Scope).
211
212
/// * [value]: Resolves to the class member (Class Member Scope).
212
213
/// * [myStaticMethod]: Resolves to the static class member (Class Member Scope).
214
+
/// * [myMethod]: Resolves to this method itself (Class Member Scope).
213
215
/// * [T]: Resolves to the class type parameter (Class Type Parameter Scope).
216
+
/// * [MyClass]: Resolves to the parent class (Library Scope).
214
217
/// * [AnotherClass]: Resolves to the library member (Library Scope).
215
218
/// * [List]: Resolves from 'dart:core' (Imported Scopes).
216
219
/// * [JsonCodec]: Resolves from 'dart:convert' (Imported Scope).
@@ -262,6 +265,7 @@ For doc comments placed directly on classes, enums, mixins, extensions, extensio
262
265
/// * [input]: Resolves to the parameter (Formal Parameter Scope).
263
266
/// * [R]: Resolves to the function type parameter (Function Type Parameter Scope).
264
267
/// * [globalConstant]: Resolves to the library member (Library Scope).
268
+
/// * [topLevelFunction]: Resolves to the function itself (Library Scope).
265
269
/// * [String]: Resolves from 'dart:core'(Imported Scope).
266
270
R topLevelFunction<R>(String input) {
267
271
// ...
@@ -271,6 +275,7 @@ R topLevelFunction<R>(String input) {
271
275
///
272
276
/// Lookup examples:
273
277
/// * [topLevelFunction]: Resolves to the library member (Library Scope).
278
+
/// * [globalConstant]: Resolves to the variable itself (Library Scope).
274
279
/// * [Duration]: Resolves from 'dart:core' (Imported Scope).
275
280
/// * [Random]: Resolves from 'dart:math' (Doc Imported Scope).
276
281
const int globalConstant = 10;
@@ -281,6 +286,7 @@ const int globalConstant = 10;
281
286
/// * [myMethod]: Resolves to the class member (Class Member Scope).
282
287
/// * [T]: Resolves to the class type parameter (Class Type Parameter Scope).
283
288
/// * [topLevelFunction]: Resolves to the library member (Library Scope).
289
+
/// * [MyClass]: Resolves to the class itself (Library Scope).
284
290
/// * [List]: Resolves from 'dart:core' (Imported Scopes).
285
291
/// * [Random]: Resolves from 'dart:math' (Doc Imported Scope).
286
292
class MyClass<T> {
@@ -312,7 +318,8 @@ class AnotherClass {}
312
318
/// A typedef for a Map.
313
319
///
314
320
/// 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).
316
323
/// * [AnotherClass]: Resolves to the library member (Library Scope).
317
324
/// * [Map]: Resolves from 'dart:core' (Imported Scope).
318
325
/// * [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
364
371
*Case 1: Import Prefix*
365
372
366
373
***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.
369
376
370
377
*Case 2: Class-like top-level declaration*
371
378
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.
374
381
* Static Members
375
382
* Constructors
376
383
377
384
***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.
379
386
* References are also made to the generic declaration, not a specific instantiation (e.g., write `[List.filled]`, not `[List<int>.filled]`).
380
387
***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.
384
391
385
392
**Leaf Elements (Empty Namespace)**
386
393
@@ -423,12 +430,12 @@ class A {
423
430
424
431
/// An instance method.
425
432
void foo() {}
426
-
}
427
433
428
434
/// Usage in documentation:
429
435
/// * [foo] -> Resolves to the method foo().
430
436
/// * [A.foo] -> Resolves to the constructor A.foo().
431
437
438
+
}
432
439
```
433
440
434
441
***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
453
460
454
461
***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.
455
462
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").
457
464
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.
459
466
460
467
#### **6.2.2. Getters and Setters**
461
468
@@ -469,10 +476,10 @@ Documentation tools should handle this property with the following rules:
469
476
* The tooling should *issue a warning* if both a getter and its corresponding setter have unique doc comments.
470
477
* The only situation the documentation of the setter is considered is in the case of no getter existing.
471
478
***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.
473
480
* When a final field (which acts as an implicit getter) is paired with an explicit setter of the same name.
474
481
* When a getter and setter for the same property are brought into scope, even if they are imported from different libraries.
475
482
476
483
#### **6.2.3. Parameters**
477
484
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