OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * **docgen** is a tool for creating machine readable representations of Dart | 6 * **docgen** is a tool for creating machine readable representations of Dart |
7 * code metadata, including: classes, members, comments and annotations. | 7 * code metadata, including: classes, members, comments and annotations. |
8 * | 8 * |
9 * docgen is run on a `.dart` file or a directory containing `.dart` files. | 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. |
10 * | 10 * |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 setters[mirrorName] = method; | 337 setters[mirrorName] = method; |
338 } else if (mirror.isGetter) { | 338 } else if (mirror.isGetter) { |
339 getters[mirrorName] = method; | 339 getters[mirrorName] = method; |
340 } else if (mirror.isConstructor) { | 340 } else if (mirror.isConstructor) { |
341 constructors[mirrorName] = method; | 341 constructors[mirrorName] = method; |
342 } else if (mirror.isOperator) { | 342 } else if (mirror.isOperator) { |
343 operators[mirrorName] = method; | 343 operators[mirrorName] = method; |
344 } else if (mirror.isRegularMethod) { | 344 } else if (mirror.isRegularMethod) { |
345 methods[mirrorName] = method; | 345 methods[mirrorName] = method; |
346 } else { | 346 } else { |
347 throw new StateError('${mirror.qualifiedName} - no method type match'); | 347 throw new ArgumentError('$mirrorName - no method type match'); |
348 } | 348 } |
349 } | 349 } |
350 }); | 350 }); |
351 return {'setters' : setters, | 351 return { |
352 'getters' : getters, | 352 'setters': setters, |
353 'constructors' : constructors, | 353 'getters': getters, |
354 'operators' : operators, | 354 'constructors': constructors, |
355 'methods' : methods}; | 355 'operators': operators, |
| 356 'methods': methods |
| 357 }; |
356 } | 358 } |
357 | 359 |
358 /** | 360 /** |
359 * Returns a map of [Class] objects constructed from inputted mirrors. | 361 * Returns a map of [Class] objects constructed from inputted mirrors. |
360 */ | 362 */ |
361 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, | 363 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, |
362 bool includePrivate) { | 364 bool includePrivate) { |
363 var data = {}; | 365 |
| 366 var abstract = {}; |
| 367 var classes = {}; |
| 368 var typedefs = {}; |
| 369 var errors = {}; |
| 370 |
364 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { | 371 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
365 if (includePrivate || !mirror.isPrivate) { | 372 if (includePrivate || !mirror.isPrivate) { |
366 _currentClass = mirror; | |
367 var superclass = (mirror.superclass != null) ? | 373 var superclass = (mirror.superclass != null) ? |
368 mirror.superclass.qualifiedName : ''; | 374 mirror.superclass.qualifiedName : ''; |
369 var interfaces = | 375 var interfaces = |
370 mirror.superinterfaces.map((interface) => interface.qualifiedName); | 376 mirror.superinterfaces.map((interface) => interface.qualifiedName); |
371 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, | 377 var clazz = new Class(mirrorName, superclass, _getComment(mirror), |
372 mirror.isTypedef, _getComment(mirror), interfaces.toList(), | 378 interfaces.toList(), _getVariables(mirror.variables, includePrivate), |
373 _getVariables(mirror.variables, includePrivate), | |
374 _getMethods(mirror.methods, includePrivate), | 379 _getMethods(mirror.methods, includePrivate), |
375 _getAnnotations(mirror), mirror.qualifiedName); | 380 _getAnnotations(mirror), mirror.qualifiedName); |
| 381 _currentClass = mirror; |
| 382 |
| 383 if (isError(mirror.qualifiedName)) { |
| 384 errors[mirrorName] = clazz; |
| 385 } else if (mirror.isTypedef) { |
| 386 typedefs[mirrorName] = clazz; |
| 387 } else if (mirror.isAbstract) { |
| 388 abstract[mirrorName] = clazz; |
| 389 } else if (mirror.isClass) { |
| 390 classes[mirrorName] = clazz; |
| 391 } else { |
| 392 throw new ArgumentError('$mirrorName - no class style match. '); |
| 393 } |
376 } | 394 } |
377 }); | 395 }); |
378 return data; | 396 return { |
| 397 'abstract': abstract, |
| 398 'class': classes, |
| 399 'typedef': typedefs, |
| 400 'error': errors |
| 401 }; |
379 } | 402 } |
380 | 403 |
381 /** | 404 /** |
382 * Returns a map of [Parameter] objects constructed from inputted mirrors. | 405 * Returns a map of [Parameter] objects constructed from inputted mirrors. |
383 */ | 406 */ |
384 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { | 407 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { |
385 var data = {}; | 408 var data = {}; |
386 mirrorList.forEach((ParameterMirror mirror) { | 409 mirrorList.forEach((ParameterMirror mirror) { |
387 _currentMember = mirror; | 410 _currentMember = mirror; |
388 data[mirror.simpleName] = new Parameter(mirror.simpleName, | 411 data[mirror.simpleName] = new Parameter(mirror.simpleName, |
(...skipping 28 matching lines...) Expand all Loading... |
417 inputMap.forEach((key, value) { | 440 inputMap.forEach((key, value) { |
418 if (value is Map) { | 441 if (value is Map) { |
419 outputMap[key] = recurseMap(value); | 442 outputMap[key] = recurseMap(value); |
420 } else { | 443 } else { |
421 outputMap[key] = value.toMap(); | 444 outputMap[key] = value.toMap(); |
422 } | 445 } |
423 }); | 446 }); |
424 return outputMap; | 447 return outputMap; |
425 } | 448 } |
426 | 449 |
| 450 bool isError(String qualifiedName) { |
| 451 return qualifiedName.toLowerCase().contains('error') || |
| 452 qualifiedName.toLowerCase().contains('exception'); |
| 453 } |
| 454 |
427 /** | 455 /** |
428 * A class representing all programming constructs, like library or class. | 456 * A class representing all programming constructs, like library or class. |
429 */ | 457 */ |
430 class Indexable { | 458 class Indexable { |
431 Indexable(String qualifiedName) { | 459 Indexable(String qualifiedName) { |
432 qualifiedNameIndex.add(qualifiedName); | 460 qualifiedNameIndex.add(qualifiedName); |
433 } | 461 } |
434 } | 462 } |
435 | 463 |
436 /** | 464 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 List<String> interfaces; | 510 List<String> interfaces; |
483 | 511 |
484 /// Top-level variables in the class. | 512 /// Top-level variables in the class. |
485 Map<String, Variable> variables; | 513 Map<String, Variable> variables; |
486 | 514 |
487 /// Methods in the class. | 515 /// Methods in the class. |
488 Map<String, Map<String, Method>> methods; | 516 Map<String, Map<String, Method>> methods; |
489 | 517 |
490 String name; | 518 String name; |
491 String superclass; | 519 String superclass; |
492 bool isAbstract; | |
493 bool isTypedef; | |
494 | 520 |
495 /// List of the meta annotations on the class. | 521 /// List of the meta annotations on the class. |
496 List<String> annotations; | 522 List<String> annotations; |
497 | 523 |
498 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, | 524 Class(this.name, this.superclass, this.comment, this.interfaces, |
499 this.comment, this.interfaces, this.variables, this.methods, | 525 this.variables, this.methods, this.annotations, |
500 this.annotations, String qualifiedName) : super(qualifiedName) {} | 526 String qualifiedName) : super(qualifiedName) {} |
501 | 527 |
502 /// Generates a map describing the [Class] object. | 528 /// Generates a map describing the [Class] object. |
503 Map toMap() { | 529 Map toMap() { |
504 var classMap = {}; | 530 var classMap = {}; |
505 classMap['name'] = name; | 531 classMap['name'] = name; |
506 classMap['comment'] = comment; | 532 classMap['comment'] = comment; |
507 classMap['superclass'] = superclass; | 533 classMap['superclass'] = superclass; |
508 classMap['abstract'] = isAbstract.toString(); | |
509 classMap['typedef'] = isTypedef.toString(); | |
510 classMap['implements'] = new List.from(interfaces); | 534 classMap['implements'] = new List.from(interfaces); |
511 classMap['variables'] = recurseMap(variables); | 535 classMap['variables'] = recurseMap(variables); |
512 classMap['methods'] = recurseMap(methods); | 536 classMap['methods'] = recurseMap(methods); |
513 classMap['annotations'] = new List.from(annotations); | 537 classMap['annotations'] = new List.from(annotations); |
514 return classMap; | 538 return classMap; |
515 } | 539 } |
516 } | 540 } |
517 | 541 |
518 /** | 542 /** |
519 * A class containing properties of a Dart variable. | 543 * A class containing properties of a Dart variable. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 parameterMap['name'] = name; | 630 parameterMap['name'] = name; |
607 parameterMap['optional'] = isOptional.toString(); | 631 parameterMap['optional'] = isOptional.toString(); |
608 parameterMap['named'] = isNamed.toString(); | 632 parameterMap['named'] = isNamed.toString(); |
609 parameterMap['default'] = hasDefaultValue.toString(); | 633 parameterMap['default'] = hasDefaultValue.toString(); |
610 parameterMap['type'] = type; | 634 parameterMap['type'] = type; |
611 parameterMap['value'] = defaultValue; | 635 parameterMap['value'] = defaultValue; |
612 parameterMap['annotations'] = new List.from(annotations); | 636 parameterMap['annotations'] = new List.from(annotations); |
613 return parameterMap; | 637 return parameterMap; |
614 } | 638 } |
615 } | 639 } |
OLD | NEW |