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

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

Issue 103083003: Make re-exported classes appear as if they are part of the original library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 bool outputToYaml: true, bool append: false, bool parseSdk: false, 317 bool outputToYaml: true, bool append: false, bool parseSdk: false,
318 String introduction: ''}) { 318 String introduction: ''}) {
319 libs.forEach((lib) { 319 libs.forEach((lib) {
320 // Files belonging to the SDK have a uri that begins with 'dart:'. 320 // Files belonging to the SDK have a uri that begins with 'dart:'.
321 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { 321 if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
322 var library = generateLibrary(lib); 322 var library = generateLibrary(lib);
323 entityMap[library.name] = library; 323 entityMap[library.name] = library;
324 } 324 }
325 }); 325 });
326 // After everything is created, do a pass through all classes to make sure no 326 // After everything is created, do a pass through all classes to make sure no
327 // intermediate classes created by mixins are included. 327 // intermediate classes created by mixins are included, all the links to
328 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); 328 // exported members point to the new library.
329 entityMap.values.where((e) => e is Class).forEach(
330 (c) => c.updateLinksAndRemoveIntermediaryClasses());
329 // Everything is a subclass of Object, therefore empty the list to avoid a 331 // Everything is a subclass of Object, therefore empty the list to avoid a
330 // giant list of subclasses to be printed out. 332 // giant list of subclasses to be printed out.
331 if (includeSdk) (entityMap['dart-core.Object'] as Class).subclasses.clear(); 333 if (includeSdk) (entityMap['dart-core.Object'] as Class).subclasses.clear();
332 334
333 var filteredEntities = entityMap.values.where(_isVisible); 335 var filteredEntities = entityMap.values.where(_isVisible);
334 336
335 // Outputs a JSON file with all libraries and their preview comments. 337 // Outputs a JSON file with all libraries and their preview comments.
336 // This will help the viewer know what libraries are available to read in. 338 // This will help the viewer know what libraries are available to read in.
337 var libraryMap; 339 var libraryMap;
338 var linkResolver = (name) => fixReference(name, null, null, null); 340 var linkResolver = (name) => fixReference(name, null, null, null);
339 if (append) { 341 if (append) {
340 var docsDir = listDir(_outputDirectory); 342 var docsDir = listDir(_outputDirectory);
341 if (!docsDir.contains('$_outputDirectory/library_list.json')) { 343 if (!docsDir.contains('$_outputDirectory/library_list.json')) {
342 throw new StateError('No library_list.json'); 344 throw new StateError('No library_list.json');
343 } 345 }
344 libraryMap = 346 libraryMap =
345 JSON.decode(new File('$_outputDirectory/library_list.json').readAsString Sync()); 347 JSON.decode(new File(
348 '$_outputDirectory/library_list.json').readAsStringSync());
346 libraryMap['libraries'].addAll(filteredEntities 349 libraryMap['libraries'].addAll(filteredEntities
347 .where((e) => e is Library) 350 .where((e) => e is Library)
348 .map((e) => e.previewMap)); 351 .map((e) => e.previewMap));
349 if (introduction.isNotEmpty) { 352 if (introduction.isNotEmpty) {
350 var intro = libraryMap['introduction']; 353 var intro = libraryMap['introduction'];
351 if (intro.isNotEmpty) intro += '<br/><br/>'; 354 if (intro.isNotEmpty) intro += '<br/><br/>';
352 intro += markdown.markdownToHtml( 355 intro += markdown.markdownToHtml(
353 new File(introduction).readAsStringSync(), 356 new File(introduction).readAsStringSync(),
354 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes); 357 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes);
355 libraryMap['introduction'] = intro; 358 libraryMap['introduction'] = intro;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 614
612 /// Converts all [foo] references in comments to <a>libraryName.foo</a>. 615 /// Converts all [foo] references in comments to <a>libraryName.foo</a>.
613 markdown.Node fixReference(String name, LibraryMirror currentLibrary, 616 markdown.Node fixReference(String name, LibraryMirror currentLibrary,
614 ClassMirror currentClass, MemberMirror currentMember) { 617 ClassMirror currentClass, MemberMirror currentMember) {
615 // Attempt the look up the whole name up in the scope. 618 // Attempt the look up the whole name up in the scope.
616 String elementName = 619 String elementName =
617 findElementInScope(name, currentLibrary, currentClass, currentMember); 620 findElementInScope(name, currentLibrary, currentClass, currentMember);
618 if (elementName != null) { 621 if (elementName != null) {
619 return new markdown.Element.text('a', elementName); 622 return new markdown.Element.text('a', elementName);
620 } 623 }
621 return _fixComplexReference(name, currentLibrary, currentClass, currentMember) ; 624 return _fixComplexReference(name, currentLibrary, currentClass,
625 currentMember);
622 } 626 }
623 627
624 markdown.Node fixReferenceWithScope(String name, DeclarationMirror scope) { 628 markdown.Node fixReferenceWithScope(String name, DeclarationMirror scope) {
625 if (scope is LibraryMirror) return fixReference(name, scope, null, null); 629 if (scope is LibraryMirror) return fixReference(name, scope, null, null);
626 if (scope is ClassMirror) 630 if (scope is ClassMirror)
627 return fixReference(name, scope.library, scope, null); 631 return fixReference(name, scope.library, scope, null);
628 if (scope is MemberMirror) { 632 if (scope is MemberMirror) {
629 var owner = scope.owner; 633 var owner = scope.owner;
630 if (owner is ClassMirror) { 634 if (owner is ClassMirror) {
631 return fixReference(name, owner.library, owner, scope); 635 return fixReference(name, owner.library, owner, scope);
632 } else { 636 } else {
633 return fixReference(name, owner, null, scope); 637 return fixReference(name, owner, null, scope);
634 } 638 }
635 } 639 }
636 return null; 640 return null;
637 } 641 }
638 642
639 /// Writes text to a file in the output directory. 643 /// Writes text to a file in the output directory.
640 void _writeToFile(String text, String filename, {bool append: false}) { 644 void _writeToFile(String text, String filename, {bool append: false}) {
641 if (text == null) return; 645 if (text == null) return;
642 Directory dir = new Directory(_outputDirectory); 646 Directory dir = new Directory(_outputDirectory);
643 if (!dir.existsSync()) { 647 if (!dir.existsSync()) {
644 dir.createSync(); 648 dir.createSync();
645 } 649 }
646 // We assume there's a single extra level of directory structure for packages.
647 if (path.split(filename).length > 1) { 650 if (path.split(filename).length > 1) {
648 var subdir = new Directory(path.join(_outputDirectory, path.dirname(filename ))); 651 var splitList = path.split(filename);
649 if (!subdir.existsSync()) { 652 for (int i = 0; i < splitList.length; i++) {
650 subdir.createSync(); 653 var level = splitList[i];
654 }
655 for (var level in path.split(filename)) {
656 var subdir = new Directory(path.join(_outputDirectory,
657 path.dirname(filename)));
658 if (!subdir.existsSync()) {
659 subdir.createSync();
660 }
651 } 661 }
652 } 662 }
653 File file = new File(path.join(_outputDirectory, filename)); 663 File file = new File(path.join(_outputDirectory, filename));
654 file.writeAsStringSync(text, mode: append ? FileMode.APPEND : FileMode.WRITE); 664 file.writeAsStringSync(text, mode: append ? FileMode.APPEND : FileMode.WRITE);
655 } 665 }
656 666
657 /// Transforms the map by calling toMap on each value in it. 667 /// Transforms the map by calling toMap on each value in it.
658 Map recurseMap(Map inputMap) { 668 Map recurseMap(Map inputMap) {
659 var outputMap = {}; 669 var outputMap = {};
660 inputMap.forEach((key, value) { 670 inputMap.forEach((key, value) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 /// Top-level functions in the library. 860 /// Top-level functions in the library.
851 MethodGroup functions; 861 MethodGroup functions;
852 862
853 /// Classes defined within the library 863 /// Classes defined within the library
854 ClassGroup classes; 864 ClassGroup classes;
855 865
856 String packageName = ''; 866 String packageName = '';
857 bool hasBeenCheckedForPackage = false; 867 bool hasBeenCheckedForPackage = false;
858 String packageIntro; 868 String packageIntro;
859 869
870 Map<String, Exported> _exportedMembers;
871
860 Library(LibraryMirror libraryMirror) : super(libraryMirror) { 872 Library(LibraryMirror libraryMirror) : super(libraryMirror) {
861 var exported = _calcExportedItems(libraryMirror); 873 var exported = _calcExportedItems(libraryMirror);
862 this.classes = _createClasses( 874 _createClasses(exported['classes']..addAll(libraryMirror.classes));
863 exported['classes']..addAll(libraryMirror.classes));
864 this.functions = _createMethods( 875 this.functions = _createMethods(
865 exported['methods']..addAll(libraryMirror.functions)); 876 exported['methods']..addAll(libraryMirror.functions));
866 this.variables = _createVariables( 877 this.variables = _createVariables(
867 exported['variables']..addAll(libraryMirror.variables)); 878 exported['variables']..addAll(libraryMirror.variables));
879
880 var exportedVariables = {};
881 variables.forEach((key, value) {
882 if (value is ExportedVariable) {
883 exportedVariables[key] = value;
884 }
885 });
886 _exportedMembers = new Map.from(this.classes.exported)
887 ..addAll(this.functions.exported)
888 ..addAll(exportedVariables);
868 } 889 }
869 890
870 String get packagePrefix => packageName == null || packageName.isEmpty ? 891 String get packagePrefix => packageName == null || packageName.isEmpty ?
871 '' : '$packageName/'; 892 '' : '$packageName/';
872 893
873 Map get previewMap { 894 Map get previewMap {
874 var basic = super.previewMap; 895 var basic = super.previewMap;
875 basic['packageName'] = packageName; 896 basic['packageName'] = packageName;
876 if (packageIntro != null) { 897 if (packageIntro != null) {
877 basic['packageIntro'] = packageIntro; 898 basic['packageIntro'] = packageIntro;
878 } 899 }
879 return basic; 900 return basic;
880 } 901 }
881 902
882 String get owner => ''; 903 String get owner => '';
883 904
884 String get name => docName(mirror); 905 String get name => docName(mirror);
885 906
886 /// Returns a [ClassGroup] containing error, typedef and regular classes. 907 /// Returns a [ClassGroup] containing error, typedef and regular classes.
Alan Knight 2013/12/03 22:48:07 If it's void now, comment should be updated.
887 ClassGroup _createClasses(Map<String, ClassMirror> mirrorMap) { 908 void _createClasses(Map<String, ClassMirror> mirrorMap) {
888 var group = new ClassGroup(); 909 this.classes = new ClassGroup();
889 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 910 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
890 group.addClass(mirror); 911 this.classes.addClass(mirror, this);
891 }); 912 });
892 return group;
893 } 913 }
894 914
895 /// For the given library determine what items (if any) are exported. 915 /// For the given library determine what items (if any) are exported.
896 /// 916 ///
897 /// Returns a Map with three keys: "classes", "methods", and "variables" the 917 /// Returns a Map with three keys: "classes", "methods", and "variables" the
898 /// values of which point to a map of exported name identifiers with values 918 /// values of which point to a map of exported name identifiers with values
899 /// corresponding to the actual DeclarationMirror. 919 /// corresponding to the actual DeclarationMirror.
900 Map<String, Map<String, DeclarationMirror>> _calcExportedItems( 920 Map<String, Map<String, DeclarationMirror>> _calcExportedItems(
901 LibraryMirror library) { 921 LibraryMirror library) {
902 var exports = {}; 922 var exports = {};
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 if (interface.isError()) return true; 1100 if (interface.isError()) return true;
1081 } 1101 }
1082 if (superclass == null) return false; 1102 if (superclass == null) return false;
1083 return superclass.isError(); 1103 return superclass.isError();
1084 } 1104 }
1085 1105
1086 /// Check that the class exists in the owner library. 1106 /// Check that the class exists in the owner library.
1087 /// 1107 ///
1088 /// If it does not exist in the owner library, it is a mixin applciation and 1108 /// If it does not exist in the owner library, it is a mixin applciation and
1089 /// should be removed. 1109 /// should be removed.
1090 void makeValid() { 1110 void updateLinksAndRemoveIntermediaryClasses() {
1091 var library = entityMap[owner]; 1111 var library = entityMap[owner];
1092 if (library != null && !library.classes.containsKey(name)) { 1112 if (library != null) {
1093 this.isPrivate = true; 1113 if (!library.classes.containsKey(name) && mirror.isNameSynthetic) {
1094 // Since we are now making the mixin a private class, make all elements 1114 // In the mixin case, remove the intermediary classes.
1095 // with the mixin as an owner private too. 1115 this.isPrivate = true;
1096 entityMap.values.where((e) => e.owner == qualifiedName) 1116 // Since we are now making the mixin a private class, make all elements
1097 .forEach((element) => element.isPrivate = true); 1117 // with the mixin as an owner private too.
1098 // Move the subclass up to the next public superclass 1118 entityMap.values.where((e) => e.owner == qualifiedName).forEach(
1099 subclasses.forEach((subclass) => addSubclass(subclass)); 1119 (element) => element.isPrivate = true);
1120 // Move the subclass up to the next public superclass
1121 subclasses.forEach((subclass) => addSubclass(subclass));
1122 } else {
1123 // It is an exported item. Loop through each of the exported types,
1124 // and tell them to update their links, given these other exported
1125 // names within the library.
1126 for (Exported member in library._exportedMembers.values) {
1127 member.updateExports(library._exportedMembers.keys);
1128 }
1129 }
1100 } 1130 }
1101 } 1131 }
1102 1132
1103 /// Makes sure that all methods with inherited equivalents have comments. 1133 /// Makes sure that all methods with inherited equivalents have comments.
1104 void ensureComments() { 1134 void ensureComments() {
1105 if (_commentsEnsured) return; 1135 if (_commentsEnsured) return;
1106 _commentsEnsured = true; 1136 _commentsEnsured = true;
1107 inheritedMethods.forEach((qualifiedName, inheritedMethod) { 1137 inheritedMethods.forEach((qualifiedName, inheritedMethod) {
1108 var method = methods[qualifiedName]; 1138 var method = methods[qualifiedName];
1109 if (method != null) method.ensureCommentFor(inheritedMethod); 1139 if (method != null) method.ensureCommentFor(inheritedMethod);
1110 }); 1140 });
1111 } 1141 }
1112 1142
1113 /// If a class extends a private superclass, find the closest public superclas s 1143 /// If a class extends a private superclass, find the closest public
1114 /// of the private superclass. 1144 /// superclass of the private superclass.
1115 String validSuperclass() { 1145 String validSuperclass() {
1116 if (superclass == null) return 'dart.core.Object'; 1146 if (superclass == null) return 'dart.core.Object';
1117 if (_isVisible(superclass)) return superclass.qualifiedName; 1147 if (_isVisible(superclass)) return superclass.qualifiedName;
1118 return superclass.validSuperclass(); 1148 return superclass.validSuperclass();
1119 } 1149 }
1120 1150
1121 /// Generates a map describing the [Class] object. 1151 /// Generates a map describing the [Class] object.
1122 Map toMap() => { 1152 Map toMap() => {
1123 'name': name, 1153 'name': name,
1124 'qualifiedName': qualifiedName, 1154 'qualifiedName': qualifiedName,
1125 'comment': comment, 1155 'comment': comment,
1126 'isAbstract' : isAbstract, 1156 'isAbstract' : isAbstract,
1127 'superclass': validSuperclass(), 1157 'superclass': validSuperclass(),
1128 'implements': interfaces.where(_isVisible) 1158 'implements': interfaces.where(_isVisible)
1129 .map((e) => e.qualifiedName).toList(), 1159 .map((e) => e.qualifiedName).toList(),
1130 'subclass': (subclasses.toList()..sort()) 1160 'subclass': (subclasses.toList()..sort())
1131 .map((x) => x.qualifiedName).toList(), 1161 .map((x) => x.qualifiedName).toList(),
1132 'variables': recurseMap(variables), 1162 'variables': recurseMap(variables),
1133 'inheritedVariables': recurseMap(inheritedVariables), 1163 'inheritedVariables': recurseMap(inheritedVariables),
1134 'methods': methods.toMap(), 1164 'methods': methods.toMap(),
1135 'inheritedMethods': inheritedMethods.toMap(), 1165 'inheritedMethods': inheritedMethods.toMap(),
1136 'annotations': annotations.map((a) => a.toMap()).toList(), 1166 'annotations': annotations.map((a) => a.toMap()).toList(),
1137 'generics': recurseMap(generics) 1167 'generics': recurseMap(generics)
1138 }; 1168 };
1139 1169
1140 int compareTo(aClass) => name.compareTo(aClass.name); 1170 int compareTo(aClass) => name.compareTo(aClass.name);
1141 } 1171 }
1142 1172
1173 abstract class Exported {
1174 void updateExports(Map<String, Indexable> libraryExports);
1175 }
1176
Alan Knight 2013/12/03 22:48:07 I know this is the rough version. Comments and typ
1177 Map _filterMap(exported, map, test) {
1178 map.forEach((key, value) {
1179 if (test(value)) exported[key] = value;
1180 });
1181 return exported;
1182 }
1183
1184 class ExportedClass extends Class implements Exported {
1185 Class _originalClass;
1186 Library _exportingLibrary;
1187
1188 ExportedClass(ClassMirror originalClass, Library this._exportingLibrary) :
1189 super._(originalClass) {
1190 _originalClass = new Class(originalClass);
1191 }
1192
1193 // The qualified name (for URL purposes) and the file name are the same,
1194 // of the form packageName/ClassName or packageName/ClassName.methodName.
1195 // This defines both the URL and the directory structure.
1196 String get fileName => path.join(_exportingLibrary.packageName,
1197 _exportingLibrary.mirror.qualifiedName + '.' + _originalClass.name);
1198
1199 void updateExports(Map<String, Indexable> libraryExports) {
1200 // TODO(efortuna): If this class points to another exported class or type
1201 // of some sort, then that reference needs to be updated here.
1202 /* these need to be updated:
1203 'comment': comment,
1204 'superclass': validSuperclass(),
1205 'implements': interfaces.where(_isVisible)
1206 .map((e) => e.qualifiedName).toList(),
1207 'subclass': (subclasses.toList()..sort())
1208 .map((x) => x.qualifiedName).toList(),
1209 'variables': recurseMap(variables),
1210 'inheritedVariables': recurseMap(inheritedVariables),
1211 'methods': methods.toMap(),
1212 'inheritedMethods': inheritedMethods.toMap(),
1213 'annotations': annotations.map((a) => a.toMap()).toList(),
1214 'generics': recurseMap(generics)
1215 */
1216 }
1217 }
1218
1143 /// A container to categorize classes into the following groups: abstract 1219 /// A container to categorize classes into the following groups: abstract
1144 /// classes, regular classes, typedefs, and errors. 1220 /// classes, regular classes, typedefs, and errors.
1145 class ClassGroup { 1221 class ClassGroup {
1146 Map<String, Class> classes = {}; 1222 Map<String, Class> classes = {};
1147 Map<String, Typedef> typedefs = {}; 1223 Map<String, Typedef> typedefs = {};
1148 Map<String, Class> errors = {}; 1224 Map<String, Class> errors = {};
1149 1225
1150 void addClass(ClassMirror classMirror) { 1226 Map<String, Exported> get exported {
1227 var exported = _filterMap({}, classes, (value) => value is ExportedClass);
1228 // TODO(efortuna): The line below needs updating.
1229 exported = _filterMap(exported, typedefs,
1230 (value) => value is ExportedClass);
1231 exported = _filterMap(exported, errors,
1232 (value) => value is ExportedClass);
1233 return exported;
1234 }
1235
1236 void addClass(ClassMirror classMirror, Library containingLibrary) {
1151 if (classMirror.isTypedef) { 1237 if (classMirror.isTypedef) {
1152 // This is actually a Dart2jsTypedefMirror, and it does define value, 1238 // This is actually a Dart2jsTypedefMirror, and it does define value,
1153 // but we don't have visibility to that type. 1239 // but we don't have visibility to that type.
1154 var mirror = classMirror; 1240 var mirror = classMirror;
1155 if (_includePrivate || !mirror.isPrivate) { 1241 if (_includePrivate || !mirror.isPrivate) {
1156 entityMap[docName(mirror)] = new Typedef(mirror); 1242 entityMap[docName(mirror)] = new Typedef(mirror);
1157 typedefs[mirror.simpleName] = entityMap[docName(mirror)]; 1243 typedefs[mirror.simpleName] = entityMap[docName(mirror)];
1158 } 1244 }
1159 } else { 1245 } else {
1160 var clazz = new Class(classMirror); 1246 var clazz = new Class(classMirror);
1161 1247
1248 classMirror.library.qualifiedName;
1249 if (classMirror.library.qualifiedName !=
1250 containingLibrary.mirror.qualifiedName) {
1251 var exportedClass = new ExportedClass(classMirror, containingLibrary);
1252 entityMap[clazz.fileName] = exportedClass;
1253 clazz = exportedClass;
1254 }
1255
1162 if (clazz.isError()) { 1256 if (clazz.isError()) {
1163 errors[classMirror.simpleName] = clazz; 1257 errors[classMirror.simpleName] = clazz;
1164 } else if (classMirror.isClass) { 1258 } else if (classMirror.isClass) {
1165 classes[classMirror.simpleName] = clazz; 1259 classes[classMirror.simpleName] = clazz;
1166 } else { 1260 } else {
1167 throw new ArgumentError( 1261 throw new ArgumentError(
1168 '${classMirror.simpleName} - no class type match. '); 1262 '${classMirror.simpleName} - no class type match. ');
1169 } 1263 }
1170 } 1264 }
1171 } 1265 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 get comment { 1348 get comment {
1255 if (_comment != null) return _comment; 1349 if (_comment != null) return _comment;
1256 var owningClass = owningEntity; 1350 var owningClass = owningEntity;
1257 if (owningClass is Class) { 1351 if (owningClass is Class) {
1258 owningClass.ensureComments(); 1352 owningClass.ensureComments();
1259 } 1353 }
1260 return super.comment; 1354 return super.comment;
1261 } 1355 }
1262 } 1356 }
1263 1357
1358 class ExportedVariable extends Variable implements Exported {
1359 Library _exportingLibrary;
1360
1361 ExportedVariable(String variableName, VariableMirror originalVariable,
1362 Library this._exportingLibrary) : super(variableName, originalVariable);
1363
1364 String get fileName => '${_exportingLibrary.packageName}/' +
1365 super.fileName.substring(packagePrefix.length);
1366
1367 void updateExports(Map<String, Indexable> libraryExports) {
1368 // TODO(efortuna): if this class points to another exported class or type
1369 // of some sort, then that reference needs to be updated here.
1370 /* these need to be updated:
1371 'comment': comment,
1372 'type': new List.filled(1, type.toMap()),
1373 'annotations': annotations.map((a) => a.toMap()).toList()
1374 */
1375 }
1376 }
1377
1264 /// A class containing properties of a Dart method. 1378 /// A class containing properties of a Dart method.
1265 class Method extends Indexable { 1379 class Method extends Indexable {
1266 1380
1267 /// Parameters for this method. 1381 /// Parameters for this method.
1268 Map<String, Parameter> parameters; 1382 Map<String, Parameter> parameters;
1269 1383
1270 bool isStatic; 1384 bool isStatic;
1271 bool isAbstract; 1385 bool isAbstract;
1272 bool isConst; 1386 bool isConst;
1273 bool isConstructor; 1387 bool isConstructor;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 get comment { 1438 get comment {
1325 if (_comment != null) return _comment; 1439 if (_comment != null) return _comment;
1326 var owningClass = owningEntity; 1440 var owningClass = owningEntity;
1327 if (owningClass is Class) { 1441 if (owningClass is Class) {
1328 owningClass.ensureComments(); 1442 owningClass.ensureComments();
1329 } 1443 }
1330 return super.comment; 1444 return super.comment;
1331 } 1445 }
1332 } 1446 }
1333 1447
1448 class ExportedMethod extends Method implements Exported {
1449 Library _exportingLibrary;
1450
1451 ExportedMethod(MethodMirror originalMethod, Library this._exportingLibrary) :
1452 super(originalMethod);
1453
1454 String get fileName => '${_exportingLibrary.packageName}/' +
1455 super.fileName.substring(packagePrefix.length);
1456
1457 void updateExports(Map<String, Indexable> libraryExports) {
1458 // TODO(efortuna): if this class points to another exported class or type
1459 // of some sort, then that reference needs to be updated here.
1460 /* these need to be updated:
1461 'qualifiedName': qualifiedName,
1462 'comment': comment,
1463 'commentFrom': commentInheritedFrom,
1464 'return': new List.filled(1, returnType.toMap()),
1465 'parameters': recurseMap(parameters),
1466 'annotations': annotations.map((a) => a.toMap()).toList()
1467 */
1468 }
1469 }
1470
1471
1472
1334 /// A container to categorize methods into the following groups: setters, 1473 /// A container to categorize methods into the following groups: setters,
1335 /// getters, constructors, operators, regular methods. 1474 /// getters, constructors, operators, regular methods.
1336 class MethodGroup { 1475 class MethodGroup {
1337 Map<String, Method> setters = {}; 1476 Map<String, Method> setters = {};
1338 Map<String, Method> getters = {}; 1477 Map<String, Method> getters = {};
1339 Map<String, Method> constructors = {}; 1478 Map<String, Method> constructors = {};
1340 Map<String, Method> operators = {}; 1479 Map<String, Method> operators = {};
1341 Map<String, Method> regularMethods = {}; 1480 Map<String, Method> regularMethods = {};
1342 1481
1482 Map<String, Exported> get exported {
1483 var exported = {};
1484 for (Map<String, Method> group in [setters, getters, constructors,
1485 operators, regularMethods]) {
1486 exported = _filterMap(exported, group,
1487 (value) => value is ExportedMethod);
1488 }
1489 return exported;
1490 }
1491
1343 void addMethod(MethodMirror mirror) { 1492 void addMethod(MethodMirror mirror) {
1344 var method = new Method(mirror); 1493 var method = new Method(mirror);
1345 entityMap[docName(mirror)] = method; 1494 entityMap[docName(mirror)] = method;
1346 if (mirror.isSetter) { 1495 if (mirror.isSetter) {
1347 setters[mirror.simpleName] = method; 1496 setters[mirror.simpleName] = method;
1348 } else if (mirror.isGetter) { 1497 } else if (mirror.isGetter) {
1349 getters[mirror.simpleName] = method; 1498 getters[mirror.simpleName] = method;
1350 } else if (mirror.isConstructor) { 1499 } else if (mirror.isConstructor) {
1351 constructors[mirror.simpleName] = method; 1500 constructors[mirror.simpleName] = method;
1352 } else if (mirror.isOperator) { 1501 } else if (mirror.isOperator) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 /// Remove statics from the map of inherited items before adding them. 1659 /// Remove statics from the map of inherited items before adding them.
1511 Map _filterStatics(Map items) { 1660 Map _filterStatics(Map items) {
1512 var result = {}; 1661 var result = {};
1513 items.forEach((name, item) { 1662 items.forEach((name, item) {
1514 if (!item.isStatic) { 1663 if (!item.isStatic) {
1515 result[name] = item; 1664 result[name] = item;
1516 } 1665 }
1517 }); 1666 });
1518 return result; 1667 return result;
1519 } 1668 }
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