Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 19708003: Catergorized classes to abstract, class, typedef, and error/exception (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/docgen/test/single_library_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 'constructors' : constructors, 353 'constructors' : constructors,
354 'operators' : operators, 354 'operators' : operators,
355 'methods' : methods}; 355 'methods' : methods};
356 } 356 }
357 357
358 /** 358 /**
359 * Returns a map of [Class] objects constructed from inputted mirrors. 359 * Returns a map of [Class] objects constructed from inputted mirrors.
360 */ 360 */
361 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, 361 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap,
362 bool includePrivate) { 362 bool includePrivate) {
363 var data = {}; 363
364 var abstract = {};
365 var classes = {};
366 var typedefs = {};
367 var errors = {};
368
364 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 369 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
365 if (includePrivate || !mirror.isPrivate) { 370 if (includePrivate || !mirror.isPrivate) {
366 _currentClass = mirror;
367 var superclass = (mirror.superclass != null) ? 371 var superclass = (mirror.superclass != null) ?
368 mirror.superclass.qualifiedName : ''; 372 mirror.superclass.qualifiedName : '';
369 var interfaces = 373 var interfaces =
370 mirror.superinterfaces.map((interface) => interface.qualifiedName); 374 mirror.superinterfaces.map((interface) => interface.qualifiedName);
371 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, 375 var clazz = new Class(mirrorName, superclass, _getComment(mirror),
372 mirror.isTypedef, _getComment(mirror), interfaces.toList(), 376 interfaces.toList(), _getVariables(mirror.variables, includePrivate),
373 _getVariables(mirror.variables, includePrivate),
374 _getMethods(mirror.methods, includePrivate), 377 _getMethods(mirror.methods, includePrivate),
375 _getAnnotations(mirror), mirror.qualifiedName); 378 _getAnnotations(mirror), mirror.qualifiedName);
379 _currentClass = mirror;
380
381 if (isError(mirror.qualifiedName)) {
382 errors[mirrorName] = clazz;
383 } else if (mirror.isTypedef) {
384 typedefs[mirrorName] = clazz;
385 } else if (mirror.isAbstract) {
386 abstract[mirrorName] = clazz;
387 } else if (mirror.isClass) {
388 classes[mirrorName] = clazz;
389 } else {
390 throw new StateError('$mirrorName - no class tyle match. ');
Bob Nystrom 2013/07/18 17:08:07 "tyle" -> "style". Also, throw ArgumentError inst
391 }
376 } 392 }
377 }); 393 });
378 return data; 394 return {'abstract' : abstract,
395 'class' : classes,
396 'typedef' : typedefs,
397 'error' : errors};
Bob Nystrom 2013/07/18 17:08:07 A couple of style nits: no space before ":", and p
379 } 398 }
380 399
381 /** 400 /**
382 * Returns a map of [Parameter] objects constructed from inputted mirrors. 401 * Returns a map of [Parameter] objects constructed from inputted mirrors.
383 */ 402 */
384 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 403 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
385 var data = {}; 404 var data = {};
386 mirrorList.forEach((ParameterMirror mirror) { 405 mirrorList.forEach((ParameterMirror mirror) {
387 _currentMember = mirror; 406 _currentMember = mirror;
388 data[mirror.simpleName] = new Parameter(mirror.simpleName, 407 data[mirror.simpleName] = new Parameter(mirror.simpleName,
(...skipping 28 matching lines...) Expand all
417 inputMap.forEach((key, value) { 436 inputMap.forEach((key, value) {
418 if (value is Map) { 437 if (value is Map) {
419 outputMap[key] = recurseMap(value); 438 outputMap[key] = recurseMap(value);
420 } else { 439 } else {
421 outputMap[key] = value.toMap(); 440 outputMap[key] = value.toMap();
422 } 441 }
423 }); 442 });
424 return outputMap; 443 return outputMap;
425 } 444 }
426 445
446 bool isError(String qualifiedName) {
447 return qualifiedName.toLowerCase().contains('error') ||
448 qualifiedName.toLowerCase().contains('exception');
449 }
450
427 /** 451 /**
428 * A class representing all programming constructs, like library or class. 452 * A class representing all programming constructs, like library or class.
429 */ 453 */
430 class IndexableItem { 454 class IndexableItem {
431 IndexableItem(String qualifiedName) { 455 IndexableItem(String qualifiedName) {
432 qualifiedNameIndex.add(qualifiedName); 456 qualifiedNameIndex.add(qualifiedName);
433 } 457 }
434 } 458 }
435 459
436 /** 460 /**
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 List<String> interfaces; 506 List<String> interfaces;
483 507
484 /// Top-level variables in the class. 508 /// Top-level variables in the class.
485 Map<String, Variable> variables; 509 Map<String, Variable> variables;
486 510
487 /// Methods in the class. 511 /// Methods in the class.
488 Map<String, Map<String, Method>> methods; 512 Map<String, Map<String, Method>> methods;
489 513
490 String name; 514 String name;
491 String superclass; 515 String superclass;
492 bool isAbstract;
493 bool isTypedef;
494 516
495 /// List of the meta annotations on the class. 517 /// List of the meta annotations on the class.
496 List<String> annotations; 518 List<String> annotations;
497 519
498 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, 520 Class(this.name, this.superclass, this.comment, this.interfaces,
499 this.comment, this.interfaces, this.variables, this.methods, 521 this.variables, this.methods, this.annotations,
500 this.annotations, String qualifiedName) : super(qualifiedName) {} 522 String qualifiedName) : super(qualifiedName) {}
501 523
502 /// Generates a map describing the [Class] object. 524 /// Generates a map describing the [Class] object.
503 Map toMap() { 525 Map toMap() {
504 var classMap = {}; 526 var classMap = {};
505 classMap['name'] = name; 527 classMap['name'] = name;
506 classMap['comment'] = comment; 528 classMap['comment'] = comment;
507 classMap['superclass'] = superclass; 529 classMap['superclass'] = superclass;
508 classMap['abstract'] = isAbstract.toString();
509 classMap['typedef'] = isTypedef.toString();
510 classMap['implements'] = new List.from(interfaces); 530 classMap['implements'] = new List.from(interfaces);
511 classMap['variables'] = recurseMap(variables); 531 classMap['variables'] = recurseMap(variables);
512 classMap['methods'] = recurseMap(methods); 532 classMap['methods'] = recurseMap(methods);
513 classMap['annotations'] = new List.from(annotations); 533 classMap['annotations'] = new List.from(annotations);
514 return classMap; 534 return classMap;
515 } 535 }
516 } 536 }
517 537
518 /** 538 /**
519 * A class containing properties of a Dart variable. 539 * A class containing properties of a Dart variable.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 parameterMap['name'] = name; 626 parameterMap['name'] = name;
607 parameterMap['optional'] = isOptional.toString(); 627 parameterMap['optional'] = isOptional.toString();
608 parameterMap['named'] = isNamed.toString(); 628 parameterMap['named'] = isNamed.toString();
609 parameterMap['default'] = hasDefaultValue.toString(); 629 parameterMap['default'] = hasDefaultValue.toString();
610 parameterMap['type'] = type; 630 parameterMap['type'] = type;
611 parameterMap['value'] = defaultValue; 631 parameterMap['value'] = defaultValue;
612 parameterMap['annotations'] = new List.from(annotations); 632 parameterMap['annotations'] = new List.from(annotations);
613 return parameterMap; 633 return parameterMap;
614 } 634 }
615 } 635 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/test/single_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698