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