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

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

Issue 19500014: Typedef information showing properly. (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 | no next file » | 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 if (memberScope != null) reference = memberScope.qualifiedName; 289 if (memberScope != null) reference = memberScope.qualifiedName;
290 else { 290 else {
291 var classScope = currentClass == null ? 291 var classScope = currentClass == null ?
292 null : currentClass.lookupInScope(name); 292 null : currentClass.lookupInScope(name);
293 reference = classScope != null ? classScope.qualifiedName : name; 293 reference = classScope != null ? classScope.qualifiedName : name;
294 } 294 }
295 return new markdown.Element.text('a', reference); 295 return new markdown.Element.text('a', reference);
296 } 296 }
297 297
298 /** 298 /**
299 * Returns a map of [Variable] objects constructed from inputted mirrors. 299 * Returns a map of [Variable] objects constructed from [mirrorMap].
300 */ 300 */
301 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, 301 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap,
302 bool includePrivate) { 302 bool includePrivate) {
303 var data = {}; 303 var data = {};
304 // TODO(janicejl): When map to map feature is created, replace the below with 304 // TODO(janicejl): When map to map feature is created, replace the below with
305 // a filter. Issue(#9590). 305 // a filter. Issue(#9590).
306 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 306 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
307 if (includePrivate || !mirror.isPrivate) { 307 if (includePrivate || !mirror.isPrivate) {
308 _currentMember = mirror; 308 _currentMember = mirror;
309 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 309 data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
310 mirror.isStatic, mirror.type.qualifiedName, _getComment(mirror), 310 mirror.isStatic, mirror.type.qualifiedName, _getComment(mirror),
311 _getAnnotations(mirror), mirror.qualifiedName); 311 _getAnnotations(mirror), mirror.qualifiedName);
312 } 312 }
313 }); 313 });
314 return data; 314 return data;
315 } 315 }
316 316
317 /** 317 /**
318 * Returns a map of [Method] objects constructed from inputted mirrors. 318 * Returns a map of [Method] objects constructed from [mirrorMap].
319 */ 319 */
320 Map<String, Map<String, Method>> _getMethods 320 Map<String, Map<String, Method>> _getMethods
321 (Map<String, MethodMirror> mirrorMap, bool includePrivate) { 321 (Map<String, MethodMirror> mirrorMap, bool includePrivate) {
322 322
323 var setters = {}; 323 var setters = {};
324 var getters = {}; 324 var getters = {};
325 var constructors = {}; 325 var constructors = {};
326 var operators = {}; 326 var operators = {};
327 var methods = {}; 327 var methods = {};
328 328
(...skipping 22 matching lines...) Expand all
351 return { 351 return {
352 'setters': setters, 352 'setters': setters,
353 'getters': getters, 353 'getters': getters,
354 'constructors': constructors, 354 'constructors': constructors,
355 'operators': operators, 355 'operators': operators,
356 'methods': methods 356 'methods': methods
357 }; 357 };
358 } 358 }
359 359
360 /** 360 /**
361 * Returns a map of [Class] objects constructed from inputted mirrors. 361 * Returns a map of [Class] objects constructed from [mirrorMap].
362 */ 362 */
363 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, 363 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap,
364 bool includePrivate) { 364 bool includePrivate) {
365 365
366 var abstractClasses = {}; 366 var abstractClasses = {};
367 var classes = {}; 367 var classes = {};
368 var typedefs = {}; 368 var typedefs = {};
369 var errors = {}; 369 var errors = {};
370 370
371 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 371 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
372 if (includePrivate || !mirror.isPrivate) { 372 if (includePrivate || !mirror.isPrivate) {
373 var superclass = (mirror.superclass != null) ? 373 var superclass = (mirror.superclass != null) ?
374 mirror.superclass.qualifiedName : ''; 374 mirror.superclass.qualifiedName : '';
375 var interfaces = 375 var interfaces =
376 mirror.superinterfaces.map((interface) => interface.qualifiedName); 376 mirror.superinterfaces.map((interface) => interface.qualifiedName);
377 var clazz = new Class(mirrorName, superclass, _getComment(mirror), 377 var clazz = new Class(mirrorName, superclass, _getComment(mirror),
378 interfaces.toList(), _getVariables(mirror.variables, includePrivate), 378 interfaces.toList(), _getVariables(mirror.variables, includePrivate),
379 _getMethods(mirror.methods, includePrivate), 379 _getMethods(mirror.methods, includePrivate),
380 _getAnnotations(mirror), _getGenerics(mirror), mirror.qualifiedName); 380 _getAnnotations(mirror), _getGenerics(mirror), mirror.qualifiedName);
381 _currentClass = mirror; 381 _currentClass = mirror;
382 382
383 if (isError(mirror.qualifiedName)) { 383 if (isError(mirror.qualifiedName)) {
384 errors[mirrorName] = clazz; 384 errors[mirrorName] = clazz;
385 } else if (mirror.isTypedef) { 385 } else if (mirror.isTypedef) {
386 typedefs[mirrorName] = clazz; 386 typedefs[mirrorName] = new Typedef(mirrorName,
387 mirror.value.returnType.qualifiedName, _getComment(mirror),
388 _getGenerics(mirror), _getParameters(mirror.value.parameters),
389 _getAnnotations(mirror), mirror.qualifiedName);
387 } else if (mirror.isAbstract) { 390 } else if (mirror.isAbstract) {
388 abstractClasses[mirrorName] = clazz; 391 abstractClasses[mirrorName] = clazz;
389 } else if (mirror.isClass) { 392 } else if (mirror.isClass) {
390 classes[mirrorName] = clazz; 393 classes[mirrorName] = clazz;
391 } else { 394 } else {
392 throw new ArgumentError('$mirrorName - no class type match. '); 395 throw new ArgumentError('$mirrorName - no class type match. ');
393 } 396 }
394 } 397 }
395 }); 398 });
396 return { 399 return {
397 'abstract': abstractClasses, 400 'abstract': abstractClasses,
398 'class': classes, 401 'class': classes,
399 'typedef': typedefs, 402 'typedef': typedefs,
400 'error': errors 403 'error': errors
401 }; 404 };
402 } 405 }
403 406
404 /** 407 /**
405 * Returns a map of [Parameter] objects constructed from inputted mirrors. 408 * Returns a map of [Parameter] objects constructed from [mirrorList].
406 */ 409 */
407 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 410 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
408 var data = {}; 411 var data = {};
409 mirrorList.forEach((ParameterMirror mirror) { 412 mirrorList.forEach((ParameterMirror mirror) {
410 _currentMember = mirror; 413 _currentMember = mirror;
411 data[mirror.simpleName] = new Parameter(mirror.simpleName, 414 data[mirror.simpleName] = new Parameter(mirror.simpleName,
412 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, 415 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
413 mirror.type.qualifiedName, mirror.defaultValue, 416 mirror.type.qualifiedName, mirror.defaultValue,
414 _getAnnotations(mirror)); 417 _getAnnotations(mirror));
415 }); 418 });
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 461
459 bool isError(String qualifiedName) { 462 bool isError(String qualifiedName) {
460 return qualifiedName.toLowerCase().contains('error') || 463 return qualifiedName.toLowerCase().contains('error') ||
461 qualifiedName.toLowerCase().contains('exception'); 464 qualifiedName.toLowerCase().contains('exception');
462 } 465 }
463 466
464 /** 467 /**
465 * A class representing all programming constructs, like library or class. 468 * A class representing all programming constructs, like library or class.
466 */ 469 */
467 class Indexable { 470 class Indexable {
468 Indexable(String qualifiedName) { 471 String name;
472
473 /// Documentation comment with converted markdown.
474 String comment;
475
476 Indexable(this.name, this.comment, String qualifiedName) {
469 qualifiedNameIndex.add(qualifiedName); 477 qualifiedNameIndex.add(qualifiedName);
470 } 478 }
471 } 479 }
472 480
473 /** 481 /**
474 * A class containing contents of a Dart library. 482 * A class containing contents of a Dart library.
475 */ 483 */
476 class Library extends Indexable { 484 class Library extends Indexable {
477 485
478 /// Documentation comment with converted markdown.
479 String comment;
480
481 /// Top-level variables in the library. 486 /// Top-level variables in the library.
482 Map<String, Variable> variables; 487 Map<String, Variable> variables;
483 488
484 /// Top-level functions in the library. 489 /// Top-level functions in the library.
485 Map<String, Map<String, Method>> functions; 490 Map<String, Map<String, Method>> functions;
486 491
487 /// Classes defined within the library 492 /// Classes defined within the library
488 Map<String, Class> classes; 493 Map<String, Class> classes;
489 494
490 String name; 495 Library(String name, String comment, this.variables,
491 496 this.functions, this.classes) : super(name, comment, name) {}
492 Library(name, this.comment, this.variables,
493 this.functions, this.classes) : super(name) {
494 this.name = name;
495 }
496 497
497 /// Generates a map describing the [Library] object. 498 /// Generates a map describing the [Library] object.
498 Map toMap() { 499 Map toMap() => {
499 var libraryMap = {}; 500 'name': name,
500 libraryMap['name'] = name; 501 'comment': comment,
501 libraryMap['comment'] = comment; 502 'variables': recurseMap(variables),
502 libraryMap['variables'] = recurseMap(variables); 503 'functions': recurseMap(functions),
503 libraryMap['functions'] = recurseMap(functions); 504 'classes': recurseMap(classes)
504 libraryMap['classes'] = recurseMap(classes); 505 };
505 return libraryMap;
506 }
507 } 506 }
508 507
509 /** 508 /**
510 * A class containing contents of a Dart class. 509 * A class containing contents of a Dart class.
511 */ 510 */
512 // TODO(tmandel): Figure out how to do typedefs (what is needed) 511 // TODO(tmandel): Figure out how to do typedefs (what is needed)
513 class Class extends Indexable { 512 class Class extends Indexable {
514 513
515 /// Documentation comment with converted markdown.
516 String comment;
517
518 /// List of the names of interfaces that this class implements. 514 /// List of the names of interfaces that this class implements.
519 List<String> interfaces; 515 List<String> interfaces;
520 516
521 /// Top-level variables in the class. 517 /// Top-level variables in the class.
522 Map<String, Variable> variables; 518 Map<String, Variable> variables;
523 519
524 /// Methods in the class. 520 /// Methods in the class.
525 Map<String, Map<String, Method>> methods; 521 Map<String, Map<String, Method>> methods;
526 522
527 /// Generic infomation about the class. 523 /// Generic infomation about the class.
528 Map<String, Generic> generics; 524 Map<String, Generic> generics;
529 525
530 String name;
531 String superclass; 526 String superclass;
532 527
533 /// List of the meta annotations on the class. 528 /// List of the meta annotations on the class.
534 List<String> annotations; 529 List<String> annotations;
535 530
536 Class(this.name, this.superclass, this.comment, this.interfaces, 531 Class(String name, this.superclass, String comment, this.interfaces,
537 this.variables, this.methods, this.annotations, this.generics, 532 this.variables, this.methods, this.annotations, this.generics,
538 String qualifiedName) : super(qualifiedName) {} 533 String qualifiedName) : super(name, comment, qualifiedName) {}
539 534
540 /// Generates a map describing the [Class] object. 535 /// Generates a map describing the [Class] object.
541 Map toMap() { 536 Map toMap() => {
542 var classMap = {}; 537 'name': name,
543 classMap['name'] = name; 538 'comment': comment,
544 classMap['comment'] = comment; 539 'superclass': superclass,
545 classMap['superclass'] = superclass; 540 'implements': new List.from(interfaces),
546 classMap['implements'] = new List.from(interfaces); 541 'variables': recurseMap(variables),
547 classMap['variables'] = recurseMap(variables); 542 'methods': recurseMap(methods),
548 classMap['methods'] = recurseMap(methods); 543 'annotations': new List.from(annotations),
549 classMap['annotations'] = new List.from(annotations); 544 'generics': recurseMap(generics)
550 classMap['generics'] = recurseMap(generics); 545 };
551 return classMap; 546 }
552 } 547
548 class Typedef extends Indexable {
549 String returnType;
550
551 Map<String, Parameter> parameters;
552
553 /// Generic information about the typedef.
554 Map<String, Generic> generics;
555
556 /// List of the meta annotations on the typedef.
557 List<String> annotations;
558
559 Typedef(String name, this.returnType, String comment, this.generics,
560 this.parameters, this.annotations,
561 String qualifiedName) : super(name, comment, qualifiedName) {}
562
563 Map toMap() => {
564 'name': name,
565 'comment': comment,
566 'return': returnType,
567 'parameters': recurseMap(parameters),
568 'annotations': new List.from(annotations),
569 'generics': recurseMap(generics)
570 };
553 } 571 }
554 572
555 /** 573 /**
556 * A class containing properties of a Dart variable. 574 * A class containing properties of a Dart variable.
557 */ 575 */
558 class Variable extends Indexable { 576 class Variable extends Indexable {
559 577
560 /// Documentation comment with converted markdown.
561 String comment;
562
563 String name;
564 bool isFinal; 578 bool isFinal;
565 bool isStatic; 579 bool isStatic;
566 String type; 580 String type;
567 581
568 /// List of the meta annotations on the variable. 582 /// List of the meta annotations on the variable.
569 List<String> annotations; 583 List<String> annotations;
570 584
571 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment, 585 Variable(String name, this.isFinal, this.isStatic, this.type, String comment,
572 this.annotations, String qualifiedName) : super(qualifiedName); 586 this.annotations, String qualifiedName) : super(name, comment,
587 qualifiedName);
573 588
574 /// Generates a map describing the [Variable] object. 589 /// Generates a map describing the [Variable] object.
575 Map toMap() { 590 Map toMap() => {
576 var variableMap = {}; 591 'name': name,
577 variableMap['name'] = name; 592 'comment': comment,
578 variableMap['comment'] = comment; 593 'final': isFinal.toString(),
579 variableMap['final'] = isFinal.toString(); 594 'static': isStatic.toString(),
580 variableMap['static'] = isStatic.toString(); 595 'type': type,
581 variableMap['type'] = type; 596 'annotations': new List.from(annotations)
582 variableMap['annotations'] = new List.from(annotations); 597 };
583 return variableMap;
584 }
585 } 598 }
586 599
587 /** 600 /**
588 * A class containing properties of a Dart method. 601 * A class containing properties of a Dart method.
589 */ 602 */
590 class Method extends Indexable { 603 class Method extends Indexable {
591 604
592 /// Documentation comment with converted markdown.
593 String comment;
594
595 /// Parameters for this method. 605 /// Parameters for this method.
596 Map<String, Parameter> parameters; 606 Map<String, Parameter> parameters;
597 607
598 String name;
599 bool isStatic; 608 bool isStatic;
600 String returnType; 609 String returnType;
601 610
602 /// List of the meta annotations on the method. 611 /// List of the meta annotations on the method.
603 List<String> annotations; 612 List<String> annotations;
604 613
605 Method(this.name, this.isStatic, this.returnType, this.comment, 614 Method(String name, this.isStatic, this.returnType, String comment,
606 this.parameters, this.annotations, String qualifiedName) 615 this.parameters, this.annotations, String qualifiedName)
607 : super(qualifiedName); 616 : super(name, comment, qualifiedName);
608 617
609 /// Generates a map describing the [Method] object. 618 /// Generates a map describing the [Method] object.
610 Map toMap() { 619 Map toMap() => {
611 var methodMap = {}; 620 'name': name,
612 methodMap['name'] = name; 621 'comment': comment,
613 methodMap['comment'] = comment; 622 'static': isStatic.toString(),
614 methodMap['static'] = isStatic.toString(); 623 'return': returnType,
615 methodMap['return'] = returnType; 624 'parameters': recurseMap(parameters),
616 methodMap['parameters'] = recurseMap(parameters); 625 'annotations': new List.from(annotations)
617 methodMap['annotations'] = new List.from(annotations); 626 };
618 return methodMap;
619 }
620 } 627 }
621 628
622 /** 629 /**
623 * A class containing properties of a Dart method/function parameter. 630 * A class containing properties of a Dart method/function parameter.
624 */ 631 */
625 class Parameter { 632 class Parameter {
626 633
627 String name; 634 String name;
628 bool isOptional; 635 bool isOptional;
629 bool isNamed; 636 bool isNamed;
630 bool hasDefaultValue; 637 bool hasDefaultValue;
631 String type; 638 String type;
632 String defaultValue; 639 String defaultValue;
633 640
634 /// List of the meta annotations on the parameter. 641 /// List of the meta annotations on the parameter.
635 List<String> annotations; 642 List<String> annotations;
636 643
637 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, 644 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
638 this.type, this.defaultValue, this.annotations); 645 this.type, this.defaultValue, this.annotations);
639 646
640 /// Generates a map describing the [Parameter] object. 647 /// Generates a map describing the [Parameter] object.
641 Map toMap() { 648 Map toMap() => {
642 var parameterMap = {}; 649 'name': name,
643 parameterMap['name'] = name; 650 'optional': isOptional.toString(),
644 parameterMap['optional'] = isOptional.toString(); 651 'named': isNamed.toString(),
645 parameterMap['named'] = isNamed.toString(); 652 'default': hasDefaultValue.toString(),
646 parameterMap['default'] = hasDefaultValue.toString(); 653 'type': type,
647 parameterMap['type'] = type; 654 'value': defaultValue,
648 parameterMap['value'] = defaultValue; 655 'annotations': new List.from(annotations)
649 parameterMap['annotations'] = new List.from(annotations); 656 };
650 return parameterMap;
651 }
652 } 657 }
653 658
654 /** 659 /**
655 * A class containing properties of a Generic. 660 * A class containing properties of a Generic.
656 */ 661 */
657 class Generic { 662 class Generic {
658 String name; 663 String name;
659 String type; 664 String type;
660 665
661 Generic(this.name, this.type); 666 Generic(this.name, this.type);
662 667
663 Map toMap() { 668 Map toMap() => {
664 return {
665 'name': name, 669 'name': name,
666 'type': type 670 'type': type
667 }; 671 };
668 }
669 } 672 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698