@@ -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
/**
@@ -142,32 +195,81 @@ class JSDocTypeExpr extends @jsdoc_type_expr, JSDocTypeExprParent, TypeAnnotatio
142
195
override TopLevel getTopLevel ( ) { result = getEnclosingStmt ( ) .getTopLevel ( ) }
143
196
}
144
197
145
- /** An `any` type expression `*`. */
198
+ /**
199
+ * An `any` type expression.
200
+ *
201
+ * Example:
202
+ *
203
+ * ```
204
+ * *
205
+ * ```
206
+ */
146
207
class JSDocAnyTypeExpr extends @jsdoc_any_type_expr, JSDocTypeExpr {
147
208
override predicate isAny ( ) { any ( ) }
148
209
}
149
210
150
- /** A null type expression. */
211
+ /**
212
+ * A null type expression.
213
+ *
214
+ * Example:
215
+ *
216
+ * ```
217
+ * null
218
+ * ```
219
+ */
151
220
class JSDocNullTypeExpr extends @jsdoc_null_type_expr, JSDocTypeExpr {
152
221
override predicate isNull ( ) { any ( ) }
153
222
}
154
223
155
- /** A type expression representing the type of `undefined`. */
224
+ /**
225
+ * A type expression representing the type of `undefined`.
226
+ *
227
+ * Example:
228
+ *
229
+ * ```
230
+ * undefined
231
+ * ```
232
+ */
156
233
class JSDocUndefinedTypeExpr extends @jsdoc_undefined_type_expr, JSDocTypeExpr {
157
234
override predicate isUndefined ( ) { any ( ) }
158
235
}
159
236
160
- /** A type expression representing an unknown type `?`. */
237
+ /**
238
+ * A type expression representing an unknown type.
239
+ *
240
+ * Example:
241
+ *
242
+ * ```
243
+ * ?
244
+ * ```
245
+ */
161
246
class JSDocUnknownTypeExpr extends @jsdoc_unknown_type_expr, JSDocTypeExpr {
162
247
override predicate isUnknownKeyword ( ) { any ( ) }
163
248
}
164
249
165
- /** A type expression representing the void type. */
250
+ /**
251
+ * A type expression representing the void type.
252
+ *
253
+ * Example:
254
+ *
255
+ * ```
256
+ * void
257
+ * ```
258
+ */
166
259
class JSDocVoidTypeExpr extends @jsdoc_void_type_expr, JSDocTypeExpr {
167
260
override predicate isVoid ( ) { any ( ) }
168
261
}
169
262
170
- /** A type expression referring to a named type. */
263
+ /**
264
+ * A type expression referring to a named type.
265
+ *
266
+ * Example:
267
+ *
268
+ * ```
269
+ * string
270
+ * Object
271
+ * ```
272
+ */
171
273
class JSDocNamedTypeExpr extends @jsdoc_named_type_expr, JSDocTypeExpr {
172
274
/** Gets the name of the type the expression refers to. */
173
275
string getName ( ) { result = toString ( ) }
@@ -211,7 +313,13 @@ class JSDocNamedTypeExpr extends @jsdoc_named_type_expr, JSDocTypeExpr {
211
313
}
212
314
213
315
/**
214
- * An applied type expression such as `Array<string>`.
316
+ * An applied type expression.
317
+ *
318
+ * Example:
319
+ *
320
+ * ```
321
+ * Array<string>
322
+ * ```
215
323
*/
216
324
class JSDocAppliedTypeExpr extends @jsdoc_applied_type_expr, JSDocTypeExpr {
217
325
/** Gets the head type expression, such as `Array` in `Array<string>`. */
@@ -237,7 +345,13 @@ class JSDocAppliedTypeExpr extends @jsdoc_applied_type_expr, JSDocTypeExpr {
237
345
}
238
346
239
347
/**
240
- * A nullable type expression such as `?number`.
348
+ * A nullable type expression.
349
+ *
350
+ * Example:
351
+ *
352
+ * ```
353
+ * ?Array
354
+ * ```
241
355
*/
242
356
class JSDocNullableTypeExpr extends @jsdoc_nullable_type_expr, JSDocTypeExpr {
243
357
/** Gets the argument type expression. */
@@ -250,7 +364,13 @@ class JSDocNullableTypeExpr extends @jsdoc_nullable_type_expr, JSDocTypeExpr {
250
364
}
251
365
252
366
/**
253
- * A non-nullable type expression such as `!number`.
367
+ * A non-nullable type expression.
368
+ *
369
+ * Example:
370
+ *
371
+ * ```
372
+ * !Array
373
+ * ```
254
374
*/
255
375
class JSDocNonNullableTypeExpr extends @jsdoc_non_nullable_type_expr, JSDocTypeExpr {
256
376
/** Gets the argument type expression. */
@@ -263,7 +383,13 @@ class JSDocNonNullableTypeExpr extends @jsdoc_non_nullable_type_expr, JSDocTypeE
263
383
}
264
384
265
385
/**
266
- * A record type expression such as `{ x: number, y: string }`.
386
+ * A record type expression.
387
+ *
388
+ * Example:
389
+ *
390
+ * ```
391
+ * { x: number, y: string }
392
+ * ```
267
393
*/
268
394
class JSDocRecordTypeExpr extends @jsdoc_record_type_expr, JSDocTypeExpr {
269
395
/** Gets the name of the `i`th field of the record type. */
@@ -282,7 +408,13 @@ class JSDocRecordTypeExpr extends @jsdoc_record_type_expr, JSDocTypeExpr {
282
408
}
283
409
284
410
/**
285
- * An array type expression such as `[string]`.
411
+ * An array type expression.
412
+ *
413
+ * Example:
414
+ *
415
+ * ```
416
+ * [string]
417
+ * ```
286
418
*/
287
419
class JSDocArrayTypeExpr extends @jsdoc_array_type_expr, JSDocTypeExpr {
288
420
/** Gets the type of the `i`th element of this array type. */
@@ -293,7 +425,13 @@ class JSDocArrayTypeExpr extends @jsdoc_array_type_expr, JSDocTypeExpr {
293
425
}
294
426
295
427
/**
296
- * A union type expression such as `number|string`.
428
+ * A union type expression.
429
+ *
430
+ * Example:
431
+ *
432
+ * ```
433
+ * number|string
434
+ * ```
297
435
*/
298
436
class JSDocUnionTypeExpr extends @jsdoc_union_type_expr, JSDocTypeExpr {
299
437
/** Gets one of the type alternatives of this union type. */
@@ -303,7 +441,13 @@ class JSDocUnionTypeExpr extends @jsdoc_union_type_expr, JSDocTypeExpr {
303
441
}
304
442
305
443
/**
306
- * A function type expression such as `function(string): number`.
444
+ * A function type expression.
445
+ *
446
+ * Example:
447
+ *
448
+ * ```
449
+ * function(string): number
450
+ * ```
307
451
*/
308
452
class JSDocFunctionTypeExpr extends @jsdoc_function_type_expr, JSDocTypeExpr {
309
453
/** Gets the result type of this function type. */
@@ -323,7 +467,13 @@ class JSDocFunctionTypeExpr extends @jsdoc_function_type_expr, JSDocTypeExpr {
323
467
}
324
468
325
469
/**
326
- * An optional parameter type such as `number=`.
470
+ * An optional parameter type.
471
+ *
472
+ * Example:
473
+ *
474
+ * ```
475
+ * number=
476
+ * ```
327
477
*/
328
478
class JSDocOptionalParameterTypeExpr extends @jsdoc_optional_type_expr, JSDocTypeExpr {
329
479
/** Gets the underlying type of this optional type. */
@@ -333,7 +483,13 @@ class JSDocOptionalParameterTypeExpr extends @jsdoc_optional_type_expr, JSDocTyp
333
483
}
334
484
335
485
/**
336
- * A rest parameter type such as `string...`.
486
+ * A rest parameter type.
487
+ *
488
+ * Example:
489
+ *
490
+ * ```
491
+ * string...
492
+ * ```
337
493
*/
338
494
class JSDocRestParameterTypeExpr extends @jsdoc_rest_type_expr, JSDocTypeExpr {
339
495
/** Gets the underlying type of this rest parameter type. */
0 commit comments