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 /// **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] |
11 /// | 11 /// |
12 /// This creates files called `docs/<library_name>.yaml` in your current | 12 /// This creates files called `docs/<library_name>.yaml` in your current |
13 /// working directory. | 13 /// working directory. |
14 library docgen; | 14 library docgen; |
15 | 15 |
16 import 'dart:convert'; | 16 import 'dart:convert'; |
17 import 'dart:io'; | 17 import 'dart:io'; |
18 import 'dart:async'; | 18 import 'dart:async'; |
19 | 19 |
20 import 'package:logging/logging.dart'; | 20 import 'package:logging/logging.dart'; |
21 import 'package:markdown/markdown.dart' as markdown; | 21 import 'package:markdown/markdown.dart' as markdown; |
22 import 'package:path/path.dart' as path; | 22 import 'package:path/path.dart' as path; |
23 import 'package:yaml/yaml.dart'; | 23 import 'package:yaml/yaml.dart'; |
24 | 24 |
25 import 'dart2yaml.dart'; | 25 import 'dart2yaml.dart'; |
26 import 'src/io.dart'; | 26 import 'src/io.dart'; |
27 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 27 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
28 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 28 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
29 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
r.dart' | 29 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
rs.dart' |
30 as dart2js; | 30 as dart2js; |
31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'
; | 31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart' |
| 32 as dart2js; |
| 33 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror
s.dart'; |
32 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart' | 34 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart' |
33 as dart2js_util; | 35 as dart2js_util; |
34 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; | 36 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; |
35 import '../../../sdk/lib/_internal/libraries.dart'; | 37 import '../../../sdk/lib/_internal/libraries.dart'; |
36 | 38 |
37 const _DEFAULT_OUTPUT_DIRECTORY = 'docs'; | 39 const _DEFAULT_OUTPUT_DIRECTORY = 'docs'; |
38 | 40 |
39 /// Annotations that we do not display in the viewer. | 41 /// Annotations that we do not display in the viewer. |
40 const List<String> _SKIPPED_ANNOTATIONS = const [ | 42 const List<String> _SKIPPED_ANNOTATIONS = const [ |
41 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates', | 43 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates', |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 117 |
116 /// Given a Dart2jsMirror, find the corresponding Docgen [MirrorBased] object. | 118 /// Given a Dart2jsMirror, find the corresponding Docgen [MirrorBased] object. |
117 /// | 119 /// |
118 /// We have this global lookup function to avoid re-implementing looking up the | 120 /// We have this global lookup function to avoid re-implementing looking up the |
119 /// scoping rules for comment resolution here (it is currently done in mirrors). | 121 /// scoping rules for comment resolution here (it is currently done in mirrors). |
120 /// If no corresponding MirrorBased object is found, we return a [DummyMirror] | 122 /// If no corresponding MirrorBased object is found, we return a [DummyMirror] |
121 /// that simply returns the original mirror's qualifiedName while behaving like | 123 /// that simply returns the original mirror's qualifiedName while behaving like |
122 /// a MirrorBased object. | 124 /// a MirrorBased object. |
123 MirrorBased getDocgenObject(DeclarationMirror mirror, [Indexable owner]) { | 125 MirrorBased getDocgenObject(DeclarationMirror mirror, [Indexable owner]) { |
124 Map<String, Set<MirrorBased>> docgenObj = | 126 Map<String, Set<MirrorBased>> docgenObj = |
125 mirrorToDocgen[mirror.qualifiedName]; | 127 mirrorToDocgen[dart2js_util.qualifiedNameOf(mirror)]; |
126 if (docgenObj == null) { | 128 if (docgenObj == null) { |
127 return new DummyMirror(mirror, owner); | 129 return new DummyMirror(mirror, owner); |
128 } | 130 } |
129 | 131 |
130 Set<MirrorBased> results = new Set<MirrorBased>(); | 132 Set<MirrorBased> results = new Set<MirrorBased>(); |
131 var setToExamine = new Set(); | 133 var setToExamine = new Set(); |
132 if (owner != null) { | 134 if (owner != null) { |
133 var firstSet = docgenObj[owner.docName]; | 135 var firstSet = docgenObj[owner.docName]; |
134 if (firstSet != null) setToExamine.addAll(firstSet); | 136 if (firstSet != null) setToExamine.addAll(firstSet); |
135 if (Indexable._coreLibrary != null && | 137 if (Indexable._coreLibrary != null && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DeclarationMirror mirror; | 172 DeclarationMirror mirror; |
171 /// The library that contains this element, if any. Used as a hint to help | 173 /// The library that contains this element, if any. Used as a hint to help |
172 /// determine which object we're referring to when looking up this mirror in | 174 /// determine which object we're referring to when looking up this mirror in |
173 /// our map. | 175 /// our map. |
174 Indexable owner; | 176 Indexable owner; |
175 DummyMirror(this.mirror, [this.owner]); | 177 DummyMirror(this.mirror, [this.owner]); |
176 | 178 |
177 String get docName { | 179 String get docName { |
178 if (mirror == null) return ''; | 180 if (mirror == null) return ''; |
179 if (mirror is LibraryMirror) { | 181 if (mirror is LibraryMirror) { |
180 return mirror.qualifiedName.replaceAll('.','-'); | 182 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); |
181 } | 183 } |
182 var mirrorOwner = mirror.owner; | 184 var mirrorOwner = mirror.owner; |
183 if (mirrorOwner == null) return mirror.qualifiedName; | 185 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror); |
184 var simpleName = mirror.simpleName; | 186 var simpleName = dart2js_util.nameOf(mirror); |
185 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { | 187 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { |
186 // We name constructors specially -- including the class name again and a | 188 // We name constructors specially -- including the class name again and a |
187 // "-" to separate the constructor from its name (if any). | 189 // "-" to separate the constructor from its name (if any). |
188 simpleName = '${mirrorOwner.simpleName}-$simpleName'; | 190 simpleName = '${dart2js_util.nameOf(mirrorOwner)}-$simpleName'; |
189 } | 191 } |
190 return getDocgenObject(mirrorOwner, owner).docName + '.' + simpleName; | 192 return getDocgenObject(mirrorOwner, owner).docName + '.' + simpleName; |
191 } | 193 } |
192 List<Annotation> _createAnnotations(DeclarationMirror mirror, | 194 List<Annotation> _createAnnotations(DeclarationMirror mirror, |
193 Library owningLibrary) => null; | 195 Library owningLibrary) => null; |
194 | 196 |
195 bool get isPrivate => mirror == null? false : mirror.isPrivate; | 197 bool get isPrivate => mirror == null? false : mirror.isPrivate; |
196 } | 198 } |
197 | 199 |
198 abstract class MirrorBased { | 200 abstract class MirrorBased { |
199 DeclarationMirror get mirror; | 201 DeclarationMirror get mirror; |
200 MirrorBased owner; | 202 MirrorBased owner; |
201 | 203 |
202 /// Returns this object's qualified name, but following the conventions | 204 /// Returns this object's qualified name, but following the conventions |
203 /// we're using in Dartdoc, which is that library names with dots in them | 205 /// we're using in Dartdoc, which is that library names with dots in them |
204 /// have them replaced with hyphens. | 206 /// have them replaced with hyphens. |
205 String get docName => owner.docName + '.' + mirror.simpleName; | 207 String get docName => owner.docName + '.' + dart2js_util.nameOf(mirror); |
206 | 208 |
207 /// Returns a list of meta annotations assocated with a mirror. | 209 /// Returns a list of meta annotations assocated with a mirror. |
208 List<Annotation> _createAnnotations(DeclarationMirror mirror, | 210 List<Annotation> _createAnnotations(DeclarationMirror mirror, |
209 Library owningLibrary) { | 211 Library owningLibrary) { |
210 var annotationMirrors = mirror.metadata.where((e) => | 212 var annotationMirrors = mirror.metadata.where((e) => |
211 e is dart2js.Dart2JsConstructedConstantMirror); | 213 e is dart2js.Dart2JsConstructedConstantMirror); |
212 var annotations = []; | 214 var annotations = []; |
213 annotationMirrors.forEach((annotation) { | 215 annotationMirrors.forEach((annotation) { |
214 var docgenAnnotation = new Annotation(annotation, owningLibrary); | 216 var docgenAnnotation = new Annotation(annotation, owningLibrary); |
215 if (!_SKIPPED_ANNOTATIONS.contains( | 217 if (!_SKIPPED_ANNOTATIONS.contains( |
216 docgenAnnotation.mirror.qualifiedName)) { | 218 dart2js_util.qualifiedNameOf(docgenAnnotation.mirror))) { |
217 annotations.add(docgenAnnotation); | 219 annotations.add(docgenAnnotation); |
218 } | 220 } |
219 }); | 221 }); |
220 return annotations; | 222 return annotations; |
221 } | 223 } |
222 | 224 |
223 bool get isPrivate => false; | 225 bool get isPrivate => false; |
224 } | 226 } |
225 | 227 |
226 /// Docgen constructor initializes the link resolver for markdown parsing. | 228 /// Docgen constructor initializes the link resolver for markdown parsing. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 (each) => each.uri.scheme == 'file'); | 319 (each) => each.uri.scheme == 'file'); |
318 var availableLibrariesByPath = new Map.fromIterables( | 320 var availableLibrariesByPath = new Map.fromIterables( |
319 availableLibraries.map((each) => each.uri), | 321 availableLibraries.map((each) => each.uri), |
320 availableLibraries); | 322 availableLibraries); |
321 var librariesToDocument = requestedLibraries.map( | 323 var librariesToDocument = requestedLibraries.map( |
322 (each) => availableLibrariesByPath.putIfAbsent(each, | 324 (each) => availableLibrariesByPath.putIfAbsent(each, |
323 () => throw "Missing library $each")).toList(); | 325 () => throw "Missing library $each")).toList(); |
324 librariesToDocument.addAll( | 326 librariesToDocument.addAll( |
325 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); | 327 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); |
326 librariesToDocument.removeWhere( | 328 librariesToDocument.removeWhere( |
327 (x) => _excluded.contains(x.simpleName)); | 329 (x) => _excluded.contains(dart2js_util.nameOf(x))); |
328 _documentLibraries(librariesToDocument, includeSdk: includeSdk, | 330 _documentLibraries(librariesToDocument, includeSdk: includeSdk, |
329 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, | 331 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, |
330 introFileName: introFileName); | 332 introFileName: introFileName); |
331 return true; | 333 return true; |
332 }); | 334 }); |
333 } | 335 } |
334 | 336 |
335 /// Writes text to a file in the output directory. | 337 /// Writes text to a file in the output directory. |
336 static void _writeToFile(String text, String filename, {bool append: false}) { | 338 static void _writeToFile(String text, String filename, {bool append: false}) { |
337 if (text == null) return; | 339 if (text == null) return; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 | 668 |
667 // TODO(janicejl): Make MDN content generic or pluggable. Maybe move | 669 // TODO(janicejl): Make MDN content generic or pluggable. Maybe move |
668 // MDN-specific code to its own library that is imported into the default | 670 // MDN-specific code to its own library that is imported into the default |
669 // impl? | 671 // impl? |
670 /// Map of all the comments for dom elements from MDN. | 672 /// Map of all the comments for dom elements from MDN. |
671 static Map _mdn; | 673 static Map _mdn; |
672 | 674 |
673 Indexable(this.mirror) { | 675 Indexable(this.mirror) { |
674 this.isPrivate = _isHidden(mirror); | 676 this.isPrivate = _isHidden(mirror); |
675 | 677 |
676 var map = mirrorToDocgen[this.mirror.qualifiedName]; | 678 var map = mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)]; |
677 if (map == null) map = new Map<String, Set<MirrorBased>>(); | 679 if (map == null) map = new Map<String, Set<MirrorBased>>(); |
678 | 680 |
679 var set = map[owner.docName]; | 681 var set = map[owner.docName]; |
680 if (set == null) set = new Set<MirrorBased>(); | 682 if (set == null) set = new Set<MirrorBased>(); |
681 set.add(this); | 683 set.add(this); |
682 map[owner.docName] = set; | 684 map[owner.docName] = set; |
683 mirrorToDocgen[this.mirror.qualifiedName] = map; | 685 mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)] = map; |
684 } | 686 } |
685 | 687 |
686 /** Walk up the owner chain to find the owning library. */ | 688 /** Walk up the owner chain to find the owning library. */ |
687 Library _getOwningLibrary(Indexable indexable) { | 689 Library _getOwningLibrary(Indexable indexable) { |
688 if (indexable is Library) return indexable; | 690 if (indexable is Library) return indexable; |
689 // TODO: is this needed? | 691 // TODO: is this needed? |
690 if (indexable is DummyMirror) return getDocgenObject(indexable.mirror.librar
y); | 692 if (indexable is DummyMirror) { |
| 693 return getDocgenObject(dart2js_util.getLibrary(indexable.mirror)); |
| 694 } |
691 return _getOwningLibrary(indexable.owner); | 695 return _getOwningLibrary(indexable.owner); |
692 } | 696 } |
693 | 697 |
694 static initializeTopLevelLibraries(MirrorSystem mirrorSystem) { | 698 static initializeTopLevelLibraries(MirrorSystem mirrorSystem) { |
695 _sdkLibraries = mirrorSystem.libraries.values.where( | 699 _sdkLibraries = mirrorSystem.libraries.values.where( |
696 (each) => each.uri.scheme == 'dart'); | 700 (each) => each.uri.scheme == 'dart'); |
697 _coreLibrary = new Library(_sdkLibraries.singleWhere((lib) => | 701 _coreLibrary = new Library(_sdkLibraries.singleWhere((lib) => |
698 lib.uri.toString().startsWith('dart:core'))); | 702 lib.uri.toString().startsWith('dart:core'))); |
699 } | 703 } |
700 | 704 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 742 |
739 _comment = _commentToHtml(); | 743 _comment = _commentToHtml(); |
740 if (_comment.isEmpty) { | 744 if (_comment.isEmpty) { |
741 _comment = _mdnComment(); | 745 _comment = _mdnComment(); |
742 } | 746 } |
743 return _comment; | 747 return _comment; |
744 } | 748 } |
745 | 749 |
746 set comment(x) => _comment = x; | 750 set comment(x) => _comment = x; |
747 | 751 |
748 String get name => mirror.simpleName; | 752 String get name => dart2js_util.nameOf(mirror); |
749 | 753 |
750 MirrorBased get owner => new DummyMirror(mirror.owner); | 754 MirrorBased get owner => new DummyMirror(mirror.owner); |
751 | 755 |
752 /// Generates MDN comments from database.json. | 756 /// Generates MDN comments from database.json. |
753 String _mdnComment() { | 757 String _mdnComment() { |
754 //Check if MDN is loaded. | 758 //Check if MDN is loaded. |
755 if (_mdn == null) { | 759 if (_mdn == null) { |
756 // Reading in MDN related json file. | 760 // Reading in MDN related json file. |
757 var root = _Generator._rootDirectory; | 761 var root = _Generator._rootDirectory; |
758 var mdnPath = path.join(root, 'utils/apidoc/mdn/database.json'); | 762 var mdnPath = path.join(root, 'utils/apidoc/mdn/database.json'); |
759 _mdn = JSON.decode(new File(mdnPath).readAsStringSync()); | 763 _mdn = JSON.decode(new File(mdnPath).readAsStringSync()); |
760 } | 764 } |
761 // TODO: refactor OOP | 765 // TODO: refactor OOP |
762 if (this is Library) return ''; | 766 if (this is Library) return ''; |
763 var domAnnotation = this.annotations.firstWhere( | 767 var domAnnotation = this.annotations.firstWhere( |
764 (e) => e.mirror.qualifiedName == 'metadata.DomName', | 768 (e) => dart2js_util.qualifiedNameOf(e.mirror) == 'metadata.DomName', |
765 orElse: () => null); | 769 orElse: () => null); |
766 if (domAnnotation == null) return ''; | 770 if (domAnnotation == null) return ''; |
767 var domName = domAnnotation.parameters.single; | 771 var domName = domAnnotation.parameters.single; |
768 var parts = domName.split('.'); | 772 var parts = domName.split('.'); |
769 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); | 773 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); |
770 if (parts.length == 1) return _mdnTypeComment(parts[0]); | 774 if (parts.length == 1) return _mdnTypeComment(parts[0]); |
771 } | 775 } |
772 | 776 |
773 /// Generates the MDN Comment for variables and method DOM elements. | 777 /// Generates the MDN Comment for variables and method DOM elements. |
774 String _mdnMemberComment(String type, String member) { | 778 String _mdnMemberComment(String type, String member) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 commentText = commentText == null ? '' : | 845 commentText = commentText == null ? '' : |
842 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver, | 846 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver, |
843 inlineSyntaxes: _MARKDOWN_SYNTAXES); | 847 inlineSyntaxes: _MARKDOWN_SYNTAXES); |
844 return commentText; | 848 return commentText; |
845 } | 849 } |
846 | 850 |
847 /// Returns a map of [Variable] objects constructed from [mirrorMap]. | 851 /// Returns a map of [Variable] objects constructed from [mirrorMap]. |
848 /// The optional parameter [containingLibrary] is contains data for variables | 852 /// The optional parameter [containingLibrary] is contains data for variables |
849 /// defined at the top level of a library (potentially for exporting | 853 /// defined at the top level of a library (potentially for exporting |
850 /// purposes). | 854 /// purposes). |
851 Map<String, Variable> _createVariables(Map<String, VariableMirror> mirrorMap, | 855 Map<String, Variable> _createVariables(Iterable<VariableMirror> mirrors, |
852 Indexable owner) { | 856 Indexable owner) { |
853 var data = {}; | 857 var data = {}; |
854 // TODO(janicejl): When map to map feature is created, replace the below | 858 // TODO(janicejl): When map to map feature is created, replace the below |
855 // with a filter. Issue(#9590). | 859 // with a filter. Issue(#9590). |
856 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { | 860 mirrors.forEach((VariableMirror mirror) { |
857 if (_Generator._includePrivate || !_isHidden(mirror)) { | 861 if (_Generator._includePrivate || !_isHidden(mirror)) { |
| 862 var mirrorName = dart2js_util.nameOf(mirror); |
858 var variable = new Variable(mirrorName, mirror, owner); | 863 var variable = new Variable(mirrorName, mirror, owner); |
859 entityMap[variable.docName] = variable; | 864 entityMap[variable.docName] = variable; |
860 data[mirrorName] = entityMap[variable.docName]; | 865 data[mirrorName] = entityMap[variable.docName]; |
861 } | 866 } |
862 }); | 867 }); |
863 return data; | 868 return data; |
864 } | 869 } |
865 | 870 |
866 /// Returns a map of [Method] objects constructed from [mirrorMap]. | 871 /// Returns a map of [Method] objects constructed from [mirrorMap]. |
867 /// The optional parameter [containingLibrary] is contains data for variables | 872 /// The optional parameter [containingLibrary] is contains data for variables |
868 /// defined at the top level of a library (potentially for exporting | 873 /// defined at the top level of a library (potentially for exporting |
869 /// purposes). | 874 /// purposes). |
870 Map<String, Method> _createMethods(Map<String, MethodMirror> mirrorMap, | 875 Map<String, Method> _createMethods(Iterable<MethodMirror> mirrors, |
871 Indexable owner) { | 876 Indexable owner) { |
872 var group = new Map<String, Method>(); | 877 var group = new Map<String, Method>(); |
873 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { | 878 mirrors.forEach((MethodMirror mirror) { |
874 if (_Generator._includePrivate || !mirror.isPrivate) { | 879 if (_Generator._includePrivate || !mirror.isPrivate) { |
875 var method = new Method(mirror, owner); | 880 var method = new Method(mirror, owner); |
876 entityMap[method.docName] = method; | 881 entityMap[method.docName] = method; |
877 group[mirror.simpleName] = method; | 882 group[dart2js_util.nameOf(mirror)] = method; |
878 } | 883 } |
879 }); | 884 }); |
880 return group; | 885 return group; |
881 } | 886 } |
882 | 887 |
883 /// Returns a map of [Parameter] objects constructed from [mirrorList]. | 888 /// Returns a map of [Parameter] objects constructed from [mirrorList]. |
884 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList, | 889 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList, |
885 Indexable owner) { | 890 Indexable owner) { |
886 var data = {}; | 891 var data = {}; |
887 mirrorList.forEach((ParameterMirror mirror) { | 892 mirrorList.forEach((ParameterMirror mirror) { |
888 data[mirror.simpleName] = new Parameter(mirror, _getOwningLibrary(owner)); | 893 data[dart2js_util.nameOf(mirror)] = |
| 894 new Parameter(mirror, _getOwningLibrary(owner)); |
889 }); | 895 }); |
890 return data; | 896 return data; |
891 } | 897 } |
892 | 898 |
893 /// Returns a map of [Generic] objects constructed from the class mirror. | 899 /// Returns a map of [Generic] objects constructed from the class mirror. |
894 Map<String, Generic> _createGenerics(ClassMirror mirror) { | 900 Map<String, Generic> _createGenerics(TypeMirror mirror) { |
895 return new Map.fromIterable(mirror.typeVariables, | 901 return new Map.fromIterable(mirror.typeVariables, |
896 key: (e) => e.toString(), | 902 key: (e) => e.toString(), |
897 value: (e) => new Generic(e)); | 903 value: (e) => new Generic(e)); |
898 } | 904 } |
899 | 905 |
900 /// Return an informative [Object.toString] for debugging. | 906 /// Return an informative [Object.toString] for debugging. |
901 String toString() => "${super.toString()}(${name.toString()})"; | 907 String toString() => "${super.toString()}(${name.toString()})"; |
902 | 908 |
903 /// Return a map representation of this type. | 909 /// Return a map representation of this type. |
904 Map toMap() {} | 910 Map toMap() {} |
(...skipping 13 matching lines...) Expand all Loading... |
918 } | 924 } |
919 } | 925 } |
920 | 926 |
921 /// Returns true if a library name starts with an underscore, and false | 927 /// Returns true if a library name starts with an underscore, and false |
922 /// otherwise. | 928 /// otherwise. |
923 /// | 929 /// |
924 /// An example that starts with _ is _js_helper. | 930 /// An example that starts with _ is _js_helper. |
925 /// An example that contains ._ is dart._collection.dev | 931 /// An example that contains ._ is dart._collection.dev |
926 // This is because LibraryMirror.isPrivate returns `false` all the time. | 932 // This is because LibraryMirror.isPrivate returns `false` all the time. |
927 bool _isLibraryPrivate(LibraryMirror mirror) { | 933 bool _isLibraryPrivate(LibraryMirror mirror) { |
928 var sdkLibrary = LIBRARIES[mirror.simpleName]; | 934 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; |
929 if (sdkLibrary != null) { | 935 if (sdkLibrary != null) { |
930 return !sdkLibrary.documented; | 936 return !sdkLibrary.documented; |
931 } else if (mirror.simpleName.startsWith('_') || | 937 } else if (dart2js_util.nameOf(mirror).startsWith('_') || |
932 mirror.simpleName.contains('._')) { | 938 dart2js_util.nameOf(mirror).contains('._')) { |
933 return true; | 939 return true; |
934 } | 940 } |
935 return false; | 941 return false; |
936 } | 942 } |
937 | 943 |
938 ////// Top level resolution functions | 944 ////// Top level resolution functions |
939 /// Converts all [foo] references in comments to <a>libraryName.foo</a>. | 945 /// Converts all [foo] references in comments to <a>libraryName.foo</a>. |
940 static markdown.Node globalFixReference(String name) { | 946 static markdown.Node globalFixReference(String name) { |
941 // Attempt the look up the whole name up in the scope. | 947 // Attempt the look up the whole name up in the scope. |
942 String elementName = _findElementInScope(name, ''); | 948 String elementName = _findElementInScope(name, ''); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 factory Library(LibraryMirror mirror) { | 1114 factory Library(LibraryMirror mirror) { |
1109 var library = getDocgenObject(mirror); | 1115 var library = getDocgenObject(mirror); |
1110 if (library is DummyMirror) { | 1116 if (library is DummyMirror) { |
1111 library = new Library._(mirror); | 1117 library = new Library._(mirror); |
1112 } | 1118 } |
1113 return library; | 1119 return library; |
1114 } | 1120 } |
1115 | 1121 |
1116 Library._(LibraryMirror libraryMirror) : super(libraryMirror) { | 1122 Library._(LibraryMirror libraryMirror) : super(libraryMirror) { |
1117 var exported = _calcExportedItems(libraryMirror); | 1123 var exported = _calcExportedItems(libraryMirror); |
1118 var exportedClasses = exported['classes']..addAll(libraryMirror.classes); | 1124 var exportedClasses = _addAll(exported['classes'], |
| 1125 dart2js_util.typesOf(libraryMirror.declarations)); |
1119 _findPackage(mirror); | 1126 _findPackage(mirror); |
1120 classes = {}; | 1127 classes = {}; |
1121 typedefs = {}; | 1128 typedefs = {}; |
1122 errors = {}; | 1129 errors = {}; |
1123 exportedClasses.forEach((String mirrorName, ClassMirror classMirror) { | 1130 exportedClasses.forEach((String mirrorName, TypeMirror mirror) { |
1124 if (classMirror.isTypedef) { | 1131 if (mirror is TypedefMirror) { |
1125 // This is actually a Dart2jsTypedefMirror, and it does define value, | 1132 // This is actually a Dart2jsTypedefMirror, and it does define value, |
1126 // but we don't have visibility to that type. | 1133 // but we don't have visibility to that type. |
1127 var mirror = classMirror; | |
1128 if (_Generator._includePrivate || !mirror.isPrivate) { | 1134 if (_Generator._includePrivate || !mirror.isPrivate) { |
1129 entityMap[getDocgenObject(mirror).docName] = | 1135 entityMap[getDocgenObject(mirror).docName] = |
1130 new Typedef(mirror, this); | 1136 new Typedef(mirror, this); |
1131 typedefs[mirror.simpleName] = | 1137 typedefs[dart2js_util.nameOf(mirror)] = |
1132 entityMap[getDocgenObject(mirror).docName]; | 1138 entityMap[getDocgenObject(mirror).docName]; |
1133 } | 1139 } |
1134 } else { | 1140 } else if (mirror is ClassMirror) { |
1135 var clazz = new Class(classMirror, this); | 1141 var clazz = new Class(mirror, this); |
1136 | 1142 |
1137 if (clazz.isError()) { | 1143 if (clazz.isError()) { |
1138 errors[classMirror.simpleName] = clazz; | 1144 errors[dart2js_util.nameOf(mirror)] = clazz; |
1139 } else if (classMirror.isClass) { | |
1140 classes[classMirror.simpleName] = clazz; | |
1141 } else { | 1145 } else { |
1142 throw new ArgumentError( | 1146 classes[dart2js_util.nameOf(mirror)] = clazz; |
1143 '${classMirror.simpleName} - no class type match. '); | |
1144 } | 1147 } |
| 1148 } else { |
| 1149 throw new ArgumentError( |
| 1150 '${dart2js_util.nameOf(mirror)} - no class type match. '); |
1145 } | 1151 } |
1146 }); | 1152 }); |
1147 this.functions = _createMethods(exported['methods'] | 1153 this.functions = _createMethods(_addAll(exported['methods'], |
1148 ..addAll(libraryMirror.functions), this); | 1154 dart2js_util.methodsOf(libraryMirror.declarations)).values, this); |
1149 this.variables = _createVariables(exported['variables'] | 1155 this.variables = _createVariables(_addAll(exported['variables'], |
1150 ..addAll(libraryMirror.variables), this); | 1156 dart2js_util.variablesOf(libraryMirror.declarations)).values, this); |
1151 } | 1157 } |
1152 | 1158 |
1153 /// Look for the specified name starting with the current member, and | 1159 /// Look for the specified name starting with the current member, and |
1154 /// progressively working outward to the current library scope. | 1160 /// progressively working outward to the current library scope. |
1155 String findElementInScope(String name) { | 1161 String findElementInScope(String name) { |
1156 var lookupFunc = Indexable.determineLookupFunc(name); | 1162 var lookupFunc = Indexable.determineLookupFunc(name); |
1157 var libraryScope = lookupFunc(mirror, name); | 1163 var libraryScope = lookupFunc(mirror, name); |
1158 if (libraryScope != null) { | 1164 if (libraryScope != null) { |
1159 var result = getDocgenObject(libraryScope, this); | 1165 var result = getDocgenObject(libraryScope, this); |
1160 if (result is DummyMirror) return packagePrefix + result.docName; | 1166 if (result is DummyMirror) return packagePrefix + result.docName; |
1161 return result.packagePrefix + result.docName; | 1167 return result.packagePrefix + result.docName; |
1162 } | 1168 } |
1163 return super.findElementInScope(name); | 1169 return super.findElementInScope(name); |
1164 } | 1170 } |
1165 | 1171 |
| 1172 /// Helper that maps [mirrors] to their simple name in map. |
| 1173 Map _addAll(Map map, Iterable<DeclarationMirror> mirrors) { |
| 1174 for (var mirror in mirrors) { |
| 1175 map[dart2js_util.nameOf(mirror)] = mirror; |
| 1176 } |
| 1177 return map; |
| 1178 } |
| 1179 |
1166 /// For a library's [mirror], determine the name of the package (if any) we | 1180 /// For a library's [mirror], determine the name of the package (if any) we |
1167 /// believe it came from (because of its file URI). | 1181 /// believe it came from (because of its file URI). |
1168 /// | 1182 /// |
1169 /// If no package could be determined, we return an empty string. | 1183 /// If no package could be determined, we return an empty string. |
1170 String _findPackage(LibraryMirror mirror) { | 1184 String _findPackage(LibraryMirror mirror) { |
1171 if (mirror == null) return ''; | 1185 if (mirror == null) return ''; |
1172 if (hasBeenCheckedForPackage) return packageName; | 1186 if (hasBeenCheckedForPackage) return packageName; |
1173 hasBeenCheckedForPackage = true; | 1187 hasBeenCheckedForPackage = true; |
1174 if (mirror.uri.scheme != 'file') return ''; | 1188 if (mirror.uri.scheme != 'file') return ''; |
1175 var filePath = mirror.uri.toFilePath(); | 1189 var filePath = mirror.uri.toFilePath(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 var basic = super.previewMap; | 1233 var basic = super.previewMap; |
1220 basic['packageName'] = packageName; | 1234 basic['packageName'] = packageName; |
1221 if (packageIntro != null) { | 1235 if (packageIntro != null) { |
1222 basic['packageIntro'] = packageIntro; | 1236 basic['packageIntro'] = packageIntro; |
1223 } | 1237 } |
1224 return basic; | 1238 return basic; |
1225 } | 1239 } |
1226 | 1240 |
1227 String get name => docName; | 1241 String get name => docName; |
1228 | 1242 |
1229 String get docName => mirror.qualifiedName.replaceAll('.','-'); | 1243 String get docName { |
| 1244 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); |
| 1245 } |
1230 | 1246 |
1231 /// For the given library determine what items (if any) are exported. | 1247 /// For the given library determine what items (if any) are exported. |
1232 /// | 1248 /// |
1233 /// Returns a Map with three keys: "classes", "methods", and "variables" the | 1249 /// Returns a Map with three keys: "classes", "methods", and "variables" the |
1234 /// values of which point to a map of exported name identifiers with values | 1250 /// values of which point to a map of exported name identifiers with values |
1235 /// corresponding to the actual DeclarationMirror. | 1251 /// corresponding to the actual DeclarationMirror. |
1236 Map<String, Map<String, DeclarationMirror>> _calcExportedItems( | 1252 Map<String, Map<String, DeclarationMirror>> _calcExportedItems( |
1237 LibraryMirror library) { | 1253 LibraryMirror library) { |
1238 var exports = {}; | 1254 var exports = {}; |
1239 exports['classes'] = {}; | 1255 exports['classes'] = {}; |
1240 exports['methods'] = {}; | 1256 exports['methods'] = {}; |
1241 exports['variables'] = {}; | 1257 exports['variables'] = {}; |
1242 | 1258 |
1243 // Determine the classes, variables and methods that are exported for a | 1259 // Determine the classes, variables and methods that are exported for a |
1244 // specific dependency. | 1260 // specific dependency. |
1245 _populateExports(LibraryDependencyMirror export, bool showExport) { | 1261 _populateExports(LibraryDependencyMirror export, bool showExport) { |
1246 if (!showExport) { | 1262 if (!showExport) { |
1247 // Add all items, and then remove the hidden ones. | 1263 // Add all items, and then remove the hidden ones. |
1248 // Ex: "export foo hide bar" | 1264 // Ex: "export foo hide bar" |
1249 exports['classes'].addAll(export.targetLibrary.classes); | 1265 _addAll(exports['classes'], |
1250 exports['methods'].addAll(export.targetLibrary.functions); | 1266 dart2js_util.typesOf(export.targetLibrary.declarations)); |
1251 exports['variables'].addAll(export.targetLibrary.variables); | 1267 _addAll(exports['methods'], |
| 1268 dart2js_util.methodsOf(export.targetLibrary.declarations)); |
| 1269 _addAll(exports['variables'], |
| 1270 dart2js_util.variablesOf(export.targetLibrary.declarations)); |
1252 } | 1271 } |
1253 for (CombinatorMirror combinator in export.combinators) { | 1272 for (CombinatorMirror combinator in export.combinators) { |
1254 for (String identifier in combinator.identifiers) { | 1273 for (String identifier in combinator.identifiers) { |
1255 DeclarationMirror declaration = | 1274 DeclarationMirror declaration = |
1256 export.targetLibrary.lookupInScope(identifier); | 1275 export.targetLibrary.lookupInScope(identifier); |
1257 if (declaration == null) { | 1276 if (declaration == null) { |
1258 // Technically this should be a bug, but some of our packages | 1277 // Technically this should be a bug, but some of our packages |
1259 // (such as the polymer package) are curently broken in this | 1278 // (such as the polymer package) are curently broken in this |
1260 // way, so we just produce a warning. | 1279 // way, so we just produce a warning. |
1261 print('Warning identifier $identifier not found in library ' | 1280 print('Warning identifier $identifier not found in library ' |
1262 '${export.targetLibrary.qualifiedName}'); | 1281 '${dart2js_util.qualifiedNameOf(export.targetLibrary)}'); |
1263 } else { | 1282 } else { |
1264 var subMap = exports['classes']; | 1283 var subMap = exports['classes']; |
1265 if (declaration is MethodMirror) { | 1284 if (declaration is MethodMirror) { |
1266 subMap = exports['methods']; | 1285 subMap = exports['methods']; |
1267 } else if (declaration is VariableMirror) { | 1286 } else if (declaration is VariableMirror) { |
1268 subMap = exports['variables']; | 1287 subMap = exports['variables']; |
1269 } | 1288 } |
1270 if (showExport) { | 1289 if (showExport) { |
1271 subMap[identifier] = declaration; | 1290 subMap[identifier] = declaration; |
1272 } else { | 1291 } else { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 inheritedVariables = {}; | 1402 inheritedVariables = {}; |
1384 | 1403 |
1385 // The reason we do this madness is the superclass and interface owners may | 1404 // The reason we do this madness is the superclass and interface owners may |
1386 // not be this class's owner!! Example: BaseClient in http pkg. | 1405 // not be this class's owner!! Example: BaseClient in http pkg. |
1387 var superinterfaces = classMirror.superinterfaces.map( | 1406 var superinterfaces = classMirror.superinterfaces.map( |
1388 (interface) => new Class._possiblyDifferentOwner(interface, owner)); | 1407 (interface) => new Class._possiblyDifferentOwner(interface, owner)); |
1389 this.superclass = classMirror.superclass == null? null : | 1408 this.superclass = classMirror.superclass == null? null : |
1390 new Class._possiblyDifferentOwner(classMirror.superclass, owner); | 1409 new Class._possiblyDifferentOwner(classMirror.superclass, owner); |
1391 | 1410 |
1392 interfaces = superinterfaces.toList(); | 1411 interfaces = superinterfaces.toList(); |
1393 variables = _createVariables(classMirror.variables, this); | 1412 variables = _createVariables( |
1394 methods = _createMethods(classMirror.methods, this); | 1413 dart2js_util.variablesOf(classMirror.declarations), this); |
| 1414 methods = _createMethods( |
| 1415 dart2js_util.methodsOf(classMirror.declarations), this); |
1395 annotations = _createAnnotations(classMirror, _getOwningLibrary(owner)); | 1416 annotations = _createAnnotations(classMirror, _getOwningLibrary(owner)); |
1396 generics = _createGenerics(classMirror); | 1417 generics = _createGenerics(classMirror); |
1397 isAbstract = classMirror.isAbstract; | 1418 isAbstract = classMirror.isAbstract; |
1398 inheritedMethods = new Map<String, Method>(); | 1419 inheritedMethods = new Map<String, Method>(); |
1399 | 1420 |
1400 // Tell all superclasses that you are a subclass, unless you are not | 1421 // Tell all superclasses that you are a subclass, unless you are not |
1401 // visible or an intermediary mixin class. | 1422 // visible or an intermediary mixin class. |
1402 if (!classMirror.isNameSynthetic && _isVisible) { | 1423 if (!classMirror.isNameSynthetic && _isVisible) { |
1403 parentChain().forEach((parentClass) { | 1424 parentChain().forEach((parentClass) { |
1404 parentClass.addSubclass(this); | 1425 parentClass.addSubclass(this); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 // can get for their inherited versions the comments. | 1551 // can get for their inherited versions the comments. |
1531 methods.forEach((qualifiedName, method) { | 1552 methods.forEach((qualifiedName, method) { |
1532 if (!method.mirror.isConstructor) method.ensureCommentFor(method); | 1553 if (!method.mirror.isConstructor) method.ensureCommentFor(method); |
1533 }); | 1554 }); |
1534 } | 1555 } |
1535 | 1556 |
1536 /// If a class extends a private superclass, find the closest public | 1557 /// If a class extends a private superclass, find the closest public |
1537 /// superclass of the private superclass. | 1558 /// superclass of the private superclass. |
1538 String validSuperclass() { | 1559 String validSuperclass() { |
1539 if (superclass == null) return 'dart.core.Object'; | 1560 if (superclass == null) return 'dart.core.Object'; |
1540 if (superclass._isVisible) return superclass.qualifiedName; | 1561 if (superclass._isVisible) return dart2js_util.qualifiedNameOf(superclass); |
1541 return superclass.validSuperclass(); | 1562 return superclass.validSuperclass(); |
1542 } | 1563 } |
1543 | 1564 |
1544 /// Generates a map describing the [Class] object. | 1565 /// Generates a map describing the [Class] object. |
1545 Map toMap() => { | 1566 Map toMap() => { |
1546 'name': name, | 1567 'name': name, |
1547 'qualifiedName': qualifiedName, | 1568 'qualifiedName': qualifiedName, |
1548 'comment': comment, | 1569 'comment': comment, |
1549 'isAbstract' : isAbstract, | 1570 'isAbstract' : isAbstract, |
1550 'superclass': validSuperclass(), | 1571 'superclass': validSuperclass(), |
(...skipping 28 matching lines...) Expand all Loading... |
1579 factory Typedef(TypedefMirror mirror, Library owningLibrary) { | 1600 factory Typedef(TypedefMirror mirror, Library owningLibrary) { |
1580 var aTypedef = getDocgenObject(mirror, owningLibrary); | 1601 var aTypedef = getDocgenObject(mirror, owningLibrary); |
1581 if (aTypedef is DummyMirror) { | 1602 if (aTypedef is DummyMirror) { |
1582 aTypedef = new Typedef._(mirror, owningLibrary); | 1603 aTypedef = new Typedef._(mirror, owningLibrary); |
1583 } | 1604 } |
1584 return aTypedef; | 1605 return aTypedef; |
1585 } | 1606 } |
1586 | 1607 |
1587 Typedef._(TypedefMirror mirror, Library owningLibrary) : super(mirror) { | 1608 Typedef._(TypedefMirror mirror, Library owningLibrary) : super(mirror) { |
1588 owner = owningLibrary; | 1609 owner = owningLibrary; |
1589 returnType = getDocgenObject(mirror.value.returnType).docName; | 1610 returnType = getDocgenObject(mirror.referent.returnType).docName; |
1590 generics = _createGenerics(mirror); | 1611 generics = _createGenerics(mirror); |
1591 parameters = _createParameters(mirror.value.parameters, owningLibrary); | 1612 parameters = _createParameters(mirror.referent.parameters, owningLibrary); |
1592 annotations = _createAnnotations(mirror, owningLibrary); | 1613 annotations = _createAnnotations(mirror, owningLibrary); |
1593 } | 1614 } |
1594 | 1615 |
1595 Map toMap() => { | 1616 Map toMap() => { |
1596 'name': name, | 1617 'name': name, |
1597 'qualifiedName': qualifiedName, | 1618 'qualifiedName': qualifiedName, |
1598 'comment': comment, | 1619 'comment': comment, |
1599 'return': returnType, | 1620 'return': returnType, |
1600 'parameters': recurseMap(parameters), | 1621 'parameters': recurseMap(parameters), |
1601 'annotations': annotations.map((a) => a.toMap()).toList(), | 1622 'annotations': annotations.map((a) => a.toMap()).toList(), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 var result = owner.findElementInScope(name); | 1782 var result = owner.findElementInScope(name); |
1762 if (result != null) return result; | 1783 if (result != null) return result; |
1763 } | 1784 } |
1764 return super.findElementInScope(name); | 1785 return super.findElementInScope(name); |
1765 } | 1786 } |
1766 | 1787 |
1767 String get docName { | 1788 String get docName { |
1768 if ((mirror as MethodMirror).isConstructor) { | 1789 if ((mirror as MethodMirror).isConstructor) { |
1769 // We name constructors specially -- including the class name again and a | 1790 // We name constructors specially -- including the class name again and a |
1770 // "-" to separate the constructor from its name (if any). | 1791 // "-" to separate the constructor from its name (if any). |
1771 return '${owner.docName}.${mirror.owner.simpleName}-${mirror.simpleName}'; | 1792 return '${owner.docName}.${dart2js_util.nameOf(mirror.owner)}-' |
| 1793 '${dart2js_util.nameOf(mirror)}'; |
1772 } | 1794 } |
1773 return super.docName; | 1795 return super.docName; |
1774 } | 1796 } |
1775 | 1797 |
1776 String get fileName => packagePrefix + docName; | 1798 String get fileName => packagePrefix + docName; |
1777 | 1799 |
1778 /// Makes sure that the method with an inherited equivalent have comments. | 1800 /// Makes sure that the method with an inherited equivalent have comments. |
1779 void ensureCommentFor(Method inheritedMethod) { | 1801 void ensureCommentFor(Method inheritedMethod) { |
1780 if (comment.isNotEmpty) return; | 1802 if (comment.isNotEmpty) return; |
1781 | 1803 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 String name; | 1858 String name; |
1837 bool isOptional; | 1859 bool isOptional; |
1838 bool isNamed; | 1860 bool isNamed; |
1839 bool hasDefaultValue; | 1861 bool hasDefaultValue; |
1840 Type type; | 1862 Type type; |
1841 String defaultValue; | 1863 String defaultValue; |
1842 /// List of the meta annotations on the parameter. | 1864 /// List of the meta annotations on the parameter. |
1843 List<Annotation> annotations; | 1865 List<Annotation> annotations; |
1844 | 1866 |
1845 Parameter(this.mirror, Library owningLibrary) { | 1867 Parameter(this.mirror, Library owningLibrary) { |
1846 name = mirror.simpleName; | 1868 name = dart2js_util.nameOf(mirror); |
1847 isOptional = mirror.isOptional; | 1869 isOptional = mirror.isOptional; |
1848 isNamed = mirror.isNamed; | 1870 isNamed = mirror.isNamed; |
1849 hasDefaultValue = mirror.hasDefaultValue; | 1871 hasDefaultValue = mirror.hasDefaultValue; |
1850 defaultValue = mirror.defaultValue; | 1872 defaultValue = '${mirror.defaultValue}'; |
1851 type = new Type(mirror.type, owningLibrary); | 1873 type = new Type(mirror.type, owningLibrary); |
1852 annotations = _createAnnotations(mirror, owningLibrary); | 1874 annotations = _createAnnotations(mirror, owningLibrary); |
1853 } | 1875 } |
1854 | 1876 |
1855 /// Generates a map describing the [Parameter] object. | 1877 /// Generates a map describing the [Parameter] object. |
1856 Map toMap() => { | 1878 Map toMap() => { |
1857 'name': name, | 1879 'name': name, |
1858 'optional': isOptional.toString(), | 1880 'optional': isOptional.toString(), |
1859 'named': isNamed.toString(), | 1881 'named': isNamed.toString(), |
1860 'default': hasDefaultValue.toString(), | 1882 'default': hasDefaultValue.toString(), |
1861 'type': new List.filled(1, type.toMap()), | 1883 'type': new List.filled(1, type.toMap()), |
1862 'value': defaultValue, | 1884 'value': defaultValue, |
1863 'annotations': annotations.map((a) => a.toMap()).toList() | 1885 'annotations': annotations.map((a) => a.toMap()).toList() |
1864 }; | 1886 }; |
1865 } | 1887 } |
1866 | 1888 |
1867 /// A Docgen wrapper around the dart2js mirror for a generic type. | 1889 /// A Docgen wrapper around the dart2js mirror for a generic type. |
1868 class Generic extends MirrorBased { | 1890 class Generic extends MirrorBased { |
1869 TypeVariableMirror mirror; | 1891 TypeVariableMirror mirror; |
1870 Generic(this.mirror); | 1892 Generic(this.mirror); |
1871 Map toMap() => { | 1893 Map toMap() => { |
1872 'name': mirror.toString(), | 1894 'name': mirror.toString(), |
1873 'type': mirror.upperBound.qualifiedName | 1895 'type': dart2js_util.qualifiedNameOf(mirror.upperBound) |
1874 }; | 1896 }; |
1875 } | 1897 } |
1876 | 1898 |
1877 /// Docgen wrapper around the mirror for a return type, and/or its generic | 1899 /// Docgen wrapper around the mirror for a return type, and/or its generic |
1878 /// type parameters. | 1900 /// type parameters. |
1879 /// | 1901 /// |
1880 /// Return types are of a form [outer]<[inner]>. | 1902 /// Return types are of a form [outer]<[inner]>. |
1881 /// If there is no [inner] part, [inner] will be an empty list. | 1903 /// If there is no [inner] part, [inner] will be an empty list. |
1882 /// | 1904 /// |
1883 /// For example: | 1905 /// For example: |
(...skipping 20 matching lines...) Expand all Loading... |
1904 /// - "outer" : "dart-core.int" | 1926 /// - "outer" : "dart-core.int" |
1905 /// "inner" : | 1927 /// "inner" : |
1906 class Type extends MirrorBased { | 1928 class Type extends MirrorBased { |
1907 TypeMirror mirror; | 1929 TypeMirror mirror; |
1908 MirrorBased owningLibrary; | 1930 MirrorBased owningLibrary; |
1909 | 1931 |
1910 Type(this.mirror, this.owningLibrary); | 1932 Type(this.mirror, this.owningLibrary); |
1911 | 1933 |
1912 /// Returns a list of [Type] objects constructed from TypeMirrors. | 1934 /// Returns a list of [Type] objects constructed from TypeMirrors. |
1913 List<Type> _createTypeGenerics(TypeMirror mirror) { | 1935 List<Type> _createTypeGenerics(TypeMirror mirror) { |
1914 if (mirror is ClassMirror && !mirror.isTypedef) { | 1936 if (mirror is ClassMirror) { |
1915 var innerList = []; | 1937 var innerList = []; |
1916 mirror.typeArguments.forEach((e) { | 1938 mirror.typeArguments.forEach((e) { |
1917 innerList.add(new Type(e, owningLibrary)); | 1939 innerList.add(new Type(e, owningLibrary)); |
1918 }); | 1940 }); |
1919 return innerList; | 1941 return innerList; |
1920 } | 1942 } |
1921 return []; | 1943 return []; |
1922 } | 1944 } |
1923 | 1945 |
1924 Map toMap() => { | 1946 Map toMap() => { |
1925 // We may encounter types whose corresponding library has not been | 1947 // We may encounter types whose corresponding library has not been |
1926 // processed yet, so look up with the owningLibrary at the last moment. | 1948 // processed yet, so look up with the owningLibrary at the last moment. |
1927 'outer': getDocgenObject(mirror, owningLibrary).docName, | 1949 'outer': getDocgenObject(mirror, owningLibrary).docName, |
1928 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), | 1950 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), |
1929 }; | 1951 }; |
1930 } | 1952 } |
1931 | 1953 |
1932 /// Holds the name of the annotation, and its parameters. | 1954 /// Holds the name of the annotation, and its parameters. |
1933 class Annotation extends MirrorBased { | 1955 class Annotation extends MirrorBased { |
1934 List<String> parameters; | 1956 List<String> parameters; |
1935 /// The class of this annotation. | 1957 /// The class of this annotation. |
1936 ClassMirror mirror; | 1958 ClassMirror mirror; |
1937 Library owningLibrary; | 1959 Library owningLibrary; |
1938 | 1960 |
1939 Annotation(InstanceMirror originalMirror, this.owningLibrary) { | 1961 Annotation(InstanceMirror originalMirror, this.owningLibrary) { |
1940 mirror = originalMirror.type; | 1962 mirror = originalMirror.type; |
1941 parameters = originalMirror.type.variables.values | 1963 parameters = dart2js_util.variablesOf(originalMirror.type.declarations) |
1942 .where((e) => e.isFinal) | 1964 .where((e) => e.isFinal) |
1943 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 1965 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
1944 .where((e) => e != null) | 1966 .where((e) => e != null) |
1945 .toList(); | 1967 .toList(); |
1946 } | 1968 } |
1947 | 1969 |
1948 Map toMap() => { | 1970 Map toMap() => { |
1949 'name': getDocgenObject(mirror, owningLibrary).docName, | 1971 'name': getDocgenObject(mirror, owningLibrary).docName, |
1950 'parameters': parameters | 1972 'parameters': parameters |
1951 }; | 1973 }; |
1952 } | 1974 } |
OLD | NEW |