@@ -4,6 +4,17 @@ import javascript
4
4
5
5
/**
6
6
* A JSDoc comment.
7
+ *
8
+ * Example:
9
+ *
10
+ * <pre>
11
+ * /**
12
+ * * An example JSDoc comment documenting a constructor function.
13
+ * *
14
+ * * @constructor
15
+ * * @param {Object=} options An object literal with options.
16
+ * */
17
+ * </pre>
7
18
*/
8
19
class JSDoc extends @jsdoc, Locatable {
9
20
override Location getLocation ( ) { hasLocation ( this , result ) }
@@ -28,6 +39,20 @@ class JSDoc extends @jsdoc, Locatable {
28
39
29
40
/**
30
41
* A program element that can have a JSDoc comment.
42
+ *
43
+ * Example:
44
+ *
45
+ * <pre>
46
+ * /**
47
+ * * An example JSDoc comment documenting a constructor function.
48
+ * *
49
+ * * @constructor
50
+ * * @param {Object=} options An object literal with options.
51
+ * */
52
+ * function MyConstructor(options) { // documentable
53
+ * this.options = options || {};
54
+ * }
55
+ * </pre>
31
56
*/
32
57
abstract class Documentable extends ASTNode {
33
58
/** Gets the JSDoc comment for this element, if any. */
@@ -38,6 +63,13 @@ abstract class Documentable extends ASTNode {
38
63
/**
39
64
* A syntactic element that a JSDoc type expression may be nested in, that is,
40
65
* either a JSDoc tag or another JSDoc type expression.
66
+ *
67
+ * Examples:
68
+ *
69
+ * ```
70
+ * // the `@param` tag and the `...=` type expressions are JSDoc type expression parents
71
+ * @param {Object=} options An object literal with options.
72
+ * ```
41
73
*/
42
74
class JSDocTypeExprParent extends @jsdoc_type_expr_parent, Locatable {
43
75
override Location getLocation ( ) { hasLocation ( this , result ) }
@@ -46,7 +78,14 @@ class JSDocTypeExprParent extends @jsdoc_type_expr_parent, Locatable {
46
78
}
47
79
48
80
/**
49
- * A JSDoc tag such as `@param Object options An object literal with options.`
81
+ * A JSDoc tag.
82
+ *
83
+ * Examples:
84
+ *
85
+ * ```
86
+ * @param {Object=} options An object literal with options.
87
+ * @return {!Server}
88
+ * ```
50
89
*/
51
90
class JSDocTag extends @jsdoc_tag, JSDocTypeExprParent {
52
91
/** Gets the tag title; for instance, the title of a `@param` tag is `"param"`. */
@@ -90,6 +129,12 @@ class JSDocTag extends @jsdoc_tag, JSDocTypeExprParent {
90
129
91
130
/**
92
131
* A `@param` tag.
132
+ *
133
+ * Example:
134
+ *
135
+ * ```
136
+ * @param {Object=} options An object literal with options.
137
+ * ```
93
138
*/
94
139
class JSDocParamTag extends JSDocTag {
95
140
JSDocParamTag ( ) { getTitle ( ) .regexpMatch ( "param|arg(ument)?" ) }
@@ -104,6 +149,14 @@ class JSDocParamTag extends JSDocTag {
104
149
105
150
/**
106
151
* A JSDoc type expression.
152
+ *
153
+ * Examples:
154
+ *
155
+ * ```
156
+ * *
157
+ * Array<string>
158
+ * !Object
159
+ * ```
107
160
*/
108
161
class JSDocTypeExpr extends @jsdoc_type_expr, JSDocTypeExprParent , TypeAnnotation {
109
162
/**
@@ -148,32 +201,81 @@ class JSDocTypeExpr extends @jsdoc_type_expr, JSDocTypeExprParent, TypeAnnotatio
148
201
override TopLevel getTopLevel ( ) { result = getEnclosingStmt ( ) .getTopLevel ( ) }
149
202
}
150
203
151
- /** An `any` type expression `*`. */
204
+ /**
205
+ * An `any` type expression.
206
+ *
207
+ * Example:
208
+ *
209
+ * ```
210
+ * *
211
+ * ```
212
+ */
152
213
class JSDocAnyTypeExpr extends @jsdoc_any_type_expr, JSDocTypeExpr {
153
214
override predicate isAny ( ) { any ( ) }
154
215
}
155
216
156
- /** A null type expression. */
217
+ /**
218
+ * A null type expression.
219
+ *
220
+ * Example:
221
+ *
222
+ * ```
223
+ * null
224
+ * ```
225
+ */
157
226
class JSDocNullTypeExpr extends @jsdoc_null_type_expr, JSDocTypeExpr {
158
227
override predicate isNull ( ) { any ( ) }
159
228
}
160
229
161
- /** A type expression representing the type of `undefined`. */
230
+ /**
231
+ * A type expression representing the type of `undefined`.
232
+ *
233
+ * Example:
234
+ *
235
+ * ```
236
+ * undefined
237
+ * ```
238
+ */
162
239
class JSDocUndefinedTypeExpr extends @jsdoc_undefined_type_expr, JSDocTypeExpr {
163
240
override predicate isUndefined ( ) { any ( ) }
164
241
}
165
242
166
- /** A type expression representing an unknown type `?`. */
243
+ /**
244
+ * A type expression representing an unknown type.
245
+ *
246
+ * Example:
247
+ *
248
+ * ```
249
+ * ?
250
+ * ```
251
+ */
167
252
class JSDocUnknownTypeExpr extends @jsdoc_unknown_type_expr, JSDocTypeExpr {
168
253
override predicate isUnknownKeyword ( ) { any ( ) }
169
254
}
170
255
171
- /** A type expression representing the void type. */
256
+ /**
257
+ * A type expression representing the void type.
258
+ *
259
+ * Example:
260
+ *
261
+ * ```
262
+ * void
263
+ * ```
264
+ */
172
265
class JSDocVoidTypeExpr extends @jsdoc_void_type_expr, JSDocTypeExpr {
173
266
override predicate isVoid ( ) { any ( ) }
174
267
}
175
268
176
- /** A type expression referring to a named type. */
269
+ /**
270
+ * A type expression referring to a named type.
271
+ *
272
+ * Example:
273
+ *
274
+ * ```
275
+ * string
276
+ * Object
277
+ * ```
278
+ */
177
279
class JSDocNamedTypeExpr extends @jsdoc_named_type_expr, JSDocTypeExpr {
178
280
/** Gets the name of the type the expression refers to. */
179
281
string getName ( ) { result = toString ( ) }
@@ -268,7 +370,13 @@ class JSDocNamedTypeExpr extends @jsdoc_named_type_expr, JSDocTypeExpr {
268
370
}
269
371
270
372
/**
271
- * An applied type expression such as `Array<string>`.
373
+ * An applied type expression.
374
+ *
375
+ * Example:
376
+ *
377
+ * ```
378
+ * Array<string>
379
+ * ```
272
380
*/
273
381
class JSDocAppliedTypeExpr extends @jsdoc_applied_type_expr, JSDocTypeExpr {
274
382
/** Gets the head type expression, such as `Array` in `Array<string>`. */
@@ -298,7 +406,13 @@ class JSDocAppliedTypeExpr extends @jsdoc_applied_type_expr, JSDocTypeExpr {
298
406
}
299
407
300
408
/**
301
- * A nullable type expression such as `?number`.
409
+ * A nullable type expression.
410
+ *
411
+ * Example:
412
+ *
413
+ * ```
414
+ * ?Array
415
+ * ```
302
416
*/
303
417
class JSDocNullableTypeExpr extends @jsdoc_nullable_type_expr, JSDocTypeExpr {
304
418
/** Gets the argument type expression. */
@@ -315,7 +429,13 @@ class JSDocNullableTypeExpr extends @jsdoc_nullable_type_expr, JSDocTypeExpr {
315
429
}
316
430
317
431
/**
318
- * A non-nullable type expression such as `!number`.
432
+ * A non-nullable type expression.
433
+ *
434
+ * Example:
435
+ *
436
+ * ```
437
+ * !Array
438
+ * ```
319
439
*/
320
440
class JSDocNonNullableTypeExpr extends @jsdoc_non_nullable_type_expr, JSDocTypeExpr {
321
441
/** Gets the argument type expression. */
@@ -332,7 +452,13 @@ class JSDocNonNullableTypeExpr extends @jsdoc_non_nullable_type_expr, JSDocTypeE
332
452
}
333
453
334
454
/**
335
- * A record type expression such as `{ x: number, y: string }`.
455
+ * A record type expression.
456
+ *
457
+ * Example:
458
+ *
459
+ * ```
460
+ * { x: number, y: string }
461
+ * ```
336
462
*/
337
463
class JSDocRecordTypeExpr extends @jsdoc_record_type_expr, JSDocTypeExpr {
338
464
/** Gets the name of the `i`th field of the record type. */
@@ -351,7 +477,13 @@ class JSDocRecordTypeExpr extends @jsdoc_record_type_expr, JSDocTypeExpr {
351
477
}
352
478
353
479
/**
354
- * An array type expression such as `[string]`.
480
+ * An array type expression.
481
+ *
482
+ * Example:
483
+ *
484
+ * ```
485
+ * [string]
486
+ * ```
355
487
*/
356
488
class JSDocArrayTypeExpr extends @jsdoc_array_type_expr, JSDocTypeExpr {
357
489
/** Gets the type of the `i`th element of this array type. */
@@ -362,7 +494,13 @@ class JSDocArrayTypeExpr extends @jsdoc_array_type_expr, JSDocTypeExpr {
362
494
}
363
495
364
496
/**
365
- * A union type expression such as `number|string`.
497
+ * A union type expression.
498
+ *
499
+ * Example:
500
+ *
501
+ * ```
502
+ * number|string
503
+ * ```
366
504
*/
367
505
class JSDocUnionTypeExpr extends @jsdoc_union_type_expr, JSDocTypeExpr {
368
506
/** Gets one of the type alternatives of this union type. */
@@ -372,7 +510,13 @@ class JSDocUnionTypeExpr extends @jsdoc_union_type_expr, JSDocTypeExpr {
372
510
}
373
511
374
512
/**
375
- * A function type expression such as `function(string): number`.
513
+ * A function type expression.
514
+ *
515
+ * Example:
516
+ *
517
+ * ```
518
+ * function(string): number
519
+ * ```
376
520
*/
377
521
class JSDocFunctionTypeExpr extends @jsdoc_function_type_expr, JSDocTypeExpr {
378
522
/** Gets the result type of this function type. */
@@ -392,7 +536,13 @@ class JSDocFunctionTypeExpr extends @jsdoc_function_type_expr, JSDocTypeExpr {
392
536
}
393
537
394
538
/**
395
- * An optional parameter type such as `number=`.
539
+ * An optional parameter type.
540
+ *
541
+ * Example:
542
+ *
543
+ * ```
544
+ * number=
545
+ * ```
396
546
*/
397
547
class JSDocOptionalParameterTypeExpr extends @jsdoc_optional_type_expr, JSDocTypeExpr {
398
548
/** Gets the underlying type of this optional type. */
@@ -406,7 +556,13 @@ class JSDocOptionalParameterTypeExpr extends @jsdoc_optional_type_expr, JSDocTyp
406
556
}
407
557
408
558
/**
409
- * A rest parameter type such as `string...`.
559
+ * A rest parameter type.
560
+ *
561
+ * Example:
562
+ *
563
+ * ```
564
+ * string...
565
+ * ```
410
566
*/
411
567
class JSDocRestParameterTypeExpr extends @jsdoc_rest_type_expr, JSDocTypeExpr {
412
568
/** Gets the underlying type of this rest parameter type. */
0 commit comments