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

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

Issue 20617005: Returning the closest public superclass rather than returning "" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 entityMap[library.qualifiedName] = library; 209 entityMap[library.qualifiedName] = library;
210 } 210 }
211 }); 211 });
212 // After everything is created, do a pass through all classes to make sure no 212 // After everything is created, do a pass through all classes to make sure no
213 // intermediate classes created by mixins are included. 213 // intermediate classes created by mixins are included.
214 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); 214 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid());
215 // Everything is a subclass of Object, therefore empty the list to avoid a 215 // Everything is a subclass of Object, therefore empty the list to avoid a
216 // giant list of subclasses to be printed out. 216 // giant list of subclasses to be printed out.
217 entityMap['dart.core.Object'].subclasses.clear(); 217 entityMap['dart.core.Object'].subclasses.clear();
218 218
219 var filteredEntities = entityMap.values.where((e) => _filterPrivate(e)); 219 var filteredEntities = entityMap.values.where((e) => _isHidden(e));
220 // Output libraries and classes to file after all information is generated. 220 // Output libraries and classes to file after all information is generated.
221 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { 221 filteredEntities.where((e) => e is Class || e is Library).forEach((output) {
222 _writeIndexableToFile(output, outputToYaml); 222 _writeIndexableToFile(output, outputToYaml);
223 }); 223 });
224 // Outputs a text file with a list of libraries available after creating all 224 // Outputs a text file with a list of libraries available after creating all
225 // the libraries. This will help the viewer know what libraries are available 225 // the libraries. This will help the viewer know what libraries are available
226 // to read in. 226 // to read in.
227 _writeToFile(filteredEntities.where((e) => e is Library) 227 _writeToFile(filteredEntities.where((e) => e is Library)
228 .map((e) => e.qualifiedName).join('\n'), 'library_list.txt', 228 .map((e) => e.qualifiedName).join('\n'), 'library_list.txt',
229 append: append); 229 append: append);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 bool _isPrivate(DeclarationMirror mirror) { 272 bool _isPrivate(DeclarationMirror mirror) {
273 if (mirror is LibraryMirror) { 273 if (mirror is LibraryMirror) {
274 return _isLibraryPrivate(mirror); 274 return _isLibraryPrivate(mirror);
275 } else if (mirror.owner is LibraryMirror) { 275 } else if (mirror.owner is LibraryMirror) {
276 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner)); 276 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner));
277 } else { 277 } else {
278 return (mirror.isPrivate || _isPrivate(mirror.owner)); 278 return (mirror.isPrivate || _isPrivate(mirror.owner));
279 } 279 }
280 } 280 }
281 281
282 bool _filterPrivate(Indexable item) { 282 bool _isHidden(Indexable item) {
Bob Nystrom 2013/08/02 02:25:03 Hmm, I think I told you to name this backwards. It
283 return _includePrivate || !item.isPrivate; 283 return _includePrivate || !item.isPrivate;
284 } 284 }
285 285
286 /** 286 /**
287 * Returns a list of meta annotations assocated with a mirror. 287 * Returns a list of meta annotations assocated with a mirror.
288 */ 288 */
289 List<String> _annotations(DeclarationMirror mirror) { 289 List<String> _annotations(DeclarationMirror mirror) {
290 var annotations = mirror.metadata.where((e) => 290 var annotations = mirror.metadata.where((e) =>
291 e is dart2js.Dart2JsConstructedConstantMirror); 291 e is dart2js.Dart2JsConstructedConstantMirror);
292 return annotations.map((e) => e.type.qualifiedName).toList(); 292 return annotations.map((e) => e.type.qualifiedName).toList();
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 return parent; 571 return parent;
572 } 572 }
573 573
574 /** 574 /**
575 * Add all inherited variables and methods from the provided superclass. 575 * Add all inherited variables and methods from the provided superclass.
576 * If [_includePrivate] is true, it also adds the variables and methods from 576 * If [_includePrivate] is true, it also adds the variables and methods from
577 * the superclass. 577 * the superclass.
578 */ 578 */
579 void addInherited(Class superclass) { 579 void addInherited(Class superclass) {
580 inheritedVariables.addAll(superclass.inheritedVariables); 580 inheritedVariables.addAll(superclass.inheritedVariables);
581 if (_filterPrivate(superclass)) { 581 if (_isHidden(superclass)) {
582 inheritedVariables.addAll(superclass.variables); 582 inheritedVariables.addAll(superclass.variables);
583 } 583 }
584 inheritedMethods.addInherited(superclass); 584 inheritedMethods.addInherited(superclass);
585 } 585 }
586 586
587 /** 587 /**
588 * Add the subclass to the class. 588 * Add the subclass to the class.
589 * 589 *
590 * If [this] is private, it will add the subclass to the list of subclasses in 590 * If [this] is private, it will add the subclass to the list of subclasses in
591 * the superclasses. 591 * the superclasses.
(...skipping 21 matching lines...) Expand all
613 this.isPrivate = true; 613 this.isPrivate = true;
614 // Since we are now making the mixin a private class, make all elements 614 // Since we are now making the mixin a private class, make all elements
615 // with the mixin as an owner private too. 615 // with the mixin as an owner private too.
616 entityMap.values.where((e) => e.owner == qualifiedName) 616 entityMap.values.where((e) => e.owner == qualifiedName)
617 .forEach((element) => element.isPrivate = true); 617 .forEach((element) => element.isPrivate = true);
618 // Move the subclass up to the next public superclass 618 // Move the subclass up to the next public superclass
619 subclasses.forEach((subclass) => addSubclass(entityMap[subclass])); 619 subclasses.forEach((subclass) => addSubclass(entityMap[subclass]));
620 } 620 }
621 } 621 }
622 622
623 /**
624 * If a class extends a private superclass, find the closest public superclass
625 * of the private superclass.
626 */
627 String validSuperclass() {
628 if (superclass == null) return 'dart.core.Object';
629 if (_isHidden(superclass)) return superclass.qualifiedName;
630 return superclass.validSuperclass();
631 }
632
623 /// Generates a map describing the [Class] object. 633 /// Generates a map describing the [Class] object.
624 Map toMap() => { 634 Map toMap() => {
625 'name': name, 635 'name': name,
626 'qualifiedname': qualifiedName, 636 'qualifiedname': qualifiedName,
627 'comment': comment, 637 'comment': comment,
628 'superclass': superclass == null ? "" : (_filterPrivate(superclass)) ? 638 'superclass': validSuperclass(),
629 superclass.qualifiedName : "", 639 'implements': new List.from(interfaces.where((e) => _isHidden(e))
Bob Nystrom 2013/08/02 02:25:03 Instead of where((e) => _isHidden(e)), you can jus
630 'implements': new List.from(interfaces.where((e) => _filterPrivate(e))
631 .map((e) => e.qualifiedName)), 640 .map((e) => e.qualifiedName)),
632 'subclass': new List.from(subclasses), 641 'subclass': new List.from(subclasses),
633 'variables': recurseMap(variables), 642 'variables': recurseMap(variables),
634 'inheritedvariables': recurseMap(inheritedVariables), 643 'inheritedvariables': recurseMap(inheritedVariables),
635 'methods': methods.toMap(), 644 'methods': methods.toMap(),
636 'inheritedmethods': inheritedMethods.toMap(), 645 'inheritedmethods': inheritedMethods.toMap(),
637 'annotations': new List.from(annotations), 646 'annotations': new List.from(annotations),
638 'generics': recurseMap(generics) 647 'generics': recurseMap(generics)
639 }; 648 };
640 } 649 }
641 650
642 /** 651 /**
643 * A container to categorize classes into the following groups: abstract 652 * A container to categorize classes into the following groups: abstract
644 * classes, regular classes, typedefs, and errors. 653 * classes, regular classes, typedefs, and errors.
645 */ 654 */
646 class ClassGroup { 655 class ClassGroup {
647 Map<String, Class> abstractClasses = {}; 656 Map<String, Class> abstractClasses = {};
648 Map<String, Class> regularClasses = {}; 657 Map<String, Class> regularClasses = {};
649 Map<String, Typedef> typedefs = {}; 658 Map<String, Typedef> typedefs = {};
650 Map<String, Class> errors = {}; 659 Map<String, Class> errors = {};
651 660
652 void addClass(ClassMirror mirror) { 661 void addClass(ClassMirror mirror) {
653 _currentClass = mirror; 662 _currentClass = mirror;
654 var clazz = _class(mirror); 663 var clazz = _class(mirror);
655 664
656 // Adding inherited parent variables and methods. 665 // Adding inherited parent variables and methods.
657 clazz.parent().forEach((parent) { 666 clazz.parent().forEach((parent) {
658 if (_filterPrivate(clazz)) { 667 if (_isHidden(clazz)) {
659 parent.addSubclass(clazz); 668 parent.addSubclass(clazz);
660 } 669 }
661 clazz.addInherited(parent); 670 clazz.addInherited(parent);
662 }); 671 });
663 672
664 if (isError(mirror.qualifiedName)) { 673 if (isError(mirror.qualifiedName)) {
665 errors[mirror.simpleName] = clazz; 674 errors[mirror.simpleName] = clazz;
666 } else if (mirror.isTypedef) { 675 } else if (mirror.isTypedef) {
667 if (_includePrivate || !mirror.isPrivate) { 676 if (_includePrivate || !mirror.isPrivate) {
668 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName, 677 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName,
(...skipping 16 matching lines...) Expand all
685 * Checks if the given name is a key for any of the Class Maps. 694 * Checks if the given name is a key for any of the Class Maps.
686 */ 695 */
687 bool containsKey(String name) { 696 bool containsKey(String name) {
688 return abstractClasses.containsKey(name) || 697 return abstractClasses.containsKey(name) ||
689 regularClasses.containsKey(name) || 698 regularClasses.containsKey(name) ||
690 errors.containsKey(name); 699 errors.containsKey(name);
691 } 700 }
692 701
693 Map toMap() => { 702 Map toMap() => {
694 'abstract': new List.from(abstractClasses.values 703 'abstract': new List.from(abstractClasses.values
695 .where((e) => _filterPrivate(e)).map((e) => e.qualifiedName)), 704 .where((e) => _isHidden(e)).map((e) => e.qualifiedName)),
Bob Nystrom 2013/08/02 02:25:03 And here too: where(_isHidden)
696 'class': new List.from(regularClasses.values 705 'class': new List.from(regularClasses.values
697 .where((e) => _filterPrivate(e)).map((e) => e.qualifiedName)), 706 .where((e) => _isHidden(e)).map((e) => e.qualifiedName)),
698 'typedef': recurseMap(typedefs), 707 'typedef': recurseMap(typedefs),
699 'error': new List.from(errors.values 708 'error': new List.from(errors.values
700 .where((e) => _filterPrivate(e)).map((e) => e.qualifiedName)) 709 .where((e) => _isHidden(e)).map((e) => e.qualifiedName))
701 }; 710 };
702 } 711 }
703 712
704 class Typedef extends Indexable { 713 class Typedef extends Indexable {
705 String returnType; 714 String returnType;
706 715
707 Map<String, Parameter> parameters; 716 Map<String, Parameter> parameters;
708 717
709 /// Generic information about the typedef. 718 /// Generic information about the typedef.
710 Map<String, Generic> generics; 719 Map<String, Generic> generics;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } else { 834 } else {
826 throw new ArgumentError('${mirror.simpleName} - no method type match'); 835 throw new ArgumentError('${mirror.simpleName} - no method type match');
827 } 836 }
828 } 837 }
829 838
830 void addInherited(Class parent) { 839 void addInherited(Class parent) {
831 setters.addAll(parent.inheritedMethods.setters); 840 setters.addAll(parent.inheritedMethods.setters);
832 getters.addAll(parent.inheritedMethods.getters); 841 getters.addAll(parent.inheritedMethods.getters);
833 operators.addAll(parent.inheritedMethods.operators); 842 operators.addAll(parent.inheritedMethods.operators);
834 regularMethods.addAll(parent.inheritedMethods.regularMethods); 843 regularMethods.addAll(parent.inheritedMethods.regularMethods);
835 if (_filterPrivate(parent)) { 844 if (_isHidden(parent)) {
836 setters.addAll(parent.methods.setters); 845 setters.addAll(parent.methods.setters);
837 getters.addAll(parent.methods.getters); 846 getters.addAll(parent.methods.getters);
838 operators.addAll(parent.methods.operators); 847 operators.addAll(parent.methods.operators);
839 regularMethods.addAll(parent.methods.regularMethods); 848 regularMethods.addAll(parent.methods.regularMethods);
840 } 849 }
841 } 850 }
842 851
843 Map toMap() => { 852 Map toMap() => {
844 'setters': recurseMap(setters), 853 'setters': recurseMap(setters),
845 'getters': recurseMap(getters), 854 'getters': recurseMap(getters),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 String outer; 937 String outer;
929 List<Type> inner; 938 List<Type> inner;
930 939
931 Type(this.outer, this.inner); 940 Type(this.outer, this.inner);
932 941
933 Map toMap() => { 942 Map toMap() => {
934 'outer': outer, 943 'outer': outer,
935 'inner': new List.from(inner.map((e) => e.toMap())) 944 'inner': new List.from(inner.map((e) => e.toMap()))
936 }; 945 };
937 } 946 }
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