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 /** | 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 bool _isLibraryPrivate(LibraryMirror mirror) { | 262 bool _isLibraryPrivate(LibraryMirror mirror) { |
263 if (mirror.simpleName.startsWith('_') || mirror.simpleName.contains('._')) { | 263 if (mirror.simpleName.startsWith('_') || mirror.simpleName.contains('._')) { |
264 return true; | 264 return true; |
265 } | 265 } |
266 return false; | 266 return false; |
267 } | 267 } |
268 | 268 |
269 /** | 269 /** |
270 * A declaration is private if itself is private, or the owner is private. | 270 * A declaration is private if itself is private, or the owner is private. |
271 */ | 271 */ |
272 // Issue(12202) - A declaration is public even if it's owner is private. | |
272 bool _isPrivate(DeclarationMirror mirror) { | 273 bool _isPrivate(DeclarationMirror mirror) { |
Bob Nystrom
2013/08/02 15:36:04
I worry about using "private" here because this de
janicejl
2013/08/02 22:08:07
Done.
| |
273 if (mirror is LibraryMirror) { | 274 if (mirror is LibraryMirror) { |
274 return _isLibraryPrivate(mirror); | 275 return _isLibraryPrivate(mirror); |
275 } else if (mirror.owner is LibraryMirror) { | 276 } else if (mirror.owner is LibraryMirror) { |
276 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner)); | 277 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner)); |
277 } else { | 278 } else { |
278 return (mirror.isPrivate || _isPrivate(mirror.owner)); | 279 return (mirror.isPrivate || _isPrivate(mirror.owner)); |
279 } | 280 } |
280 } | 281 } |
281 | 282 |
282 bool _filterPrivate(Indexable item) { | 283 bool _filterPrivate(Indexable item) { |
283 return _includePrivate || !item.isPrivate; | 284 return _includePrivate || !item.isPrivate; |
284 } | 285 } |
285 | 286 |
286 /** | 287 /** |
287 * Returns a list of meta annotations assocated with a mirror. | 288 * Returns a list of meta annotations assocated with a mirror. |
288 */ | 289 */ |
289 List<String> _annotations(DeclarationMirror mirror) { | 290 List<String> _annotations(DeclarationMirror mirror) { |
290 var annotations = mirror.metadata.where((e) => | 291 var annotationMirrors = mirror.metadata.where((e) => |
291 e is dart2js.Dart2JsConstructedConstantMirror); | 292 e is dart2js.Dart2JsConstructedConstantMirror); |
292 return annotations.map((e) => e.type.qualifiedName).toList(); | 293 var annotations = []; |
294 annotationMirrors.forEach((annotation) { | |
295 var parameterList = []; | |
296 annotation.type.variables.values.where((e) => e.isFinal).forEach ((v) { | |
297 parameterList.add(annotation.getField(v.simpleName).reflectee); | |
298 }); | |
Bob Nystrom
2013/08/02 15:36:04
When you iterate over a sequence and call .add() o
janicejl
2013/08/02 22:08:07
Done.
| |
299 annotations.add(new Annotation(annotation.type.qualifiedName, | |
300 parameterList)); | |
301 }); | |
302 return annotations; | |
293 } | 303 } |
294 | 304 |
295 /** | 305 /** |
296 * Returns any documentation comments associated with a mirror with | 306 * Returns any documentation comments associated with a mirror with |
297 * simple markdown converted to html. | 307 * simple markdown converted to html. |
298 */ | 308 */ |
299 String _commentToHtml(DeclarationMirror mirror) { | 309 String _commentToHtml(DeclarationMirror mirror) { |
300 String commentText; | 310 String commentText; |
301 mirror.metadata.forEach((metadata) { | 311 mirror.metadata.forEach((metadata) { |
302 if (metadata is CommentInstanceMirror) { | 312 if (metadata is CommentInstanceMirror) { |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
716 this.parameters, this.annotations, | 726 this.parameters, this.annotations, |
717 String qualifiedName, bool isPrivate, String owner) : super(name, comment, | 727 String qualifiedName, bool isPrivate, String owner) : super(name, comment, |
718 qualifiedName, isPrivate, owner) {} | 728 qualifiedName, isPrivate, owner) {} |
719 | 729 |
720 Map toMap() => { | 730 Map toMap() => { |
721 'name': name, | 731 'name': name, |
722 'qualifiedname': qualifiedName, | 732 'qualifiedname': qualifiedName, |
723 'comment': comment, | 733 'comment': comment, |
724 'return': returnType, | 734 'return': returnType, |
725 'parameters': recurseMap(parameters), | 735 'parameters': recurseMap(parameters), |
726 'annotations': new List.from(annotations), | 736 'annotations': new List.from(annotations.map((a) => a.toMap())), |
Bob Nystrom
2013/08/02 15:36:04
Instead of new List.from(), use toList():
annotat
janicejl
2013/08/02 22:08:07
Done.
| |
727 'generics': recurseMap(generics) | 737 'generics': recurseMap(generics) |
728 }; | 738 }; |
729 } | 739 } |
730 | 740 |
731 /** | 741 /** |
732 * A class containing properties of a Dart variable. | 742 * A class containing properties of a Dart variable. |
733 */ | 743 */ |
734 class Variable extends Indexable { | 744 class Variable extends Indexable { |
735 | 745 |
736 bool isFinal; | 746 bool isFinal; |
(...skipping 10 matching lines...) Expand all Loading... | |
747 | 757 |
748 /// Generates a map describing the [Variable] object. | 758 /// Generates a map describing the [Variable] object. |
749 Map toMap() => { | 759 Map toMap() => { |
750 'name': name, | 760 'name': name, |
751 'qualifiedname': qualifiedName, | 761 'qualifiedname': qualifiedName, |
752 'comment': comment, | 762 'comment': comment, |
753 'final': isFinal.toString(), | 763 'final': isFinal.toString(), |
754 'static': isStatic.toString(), | 764 'static': isStatic.toString(), |
755 'constant': isConst.toString(), | 765 'constant': isConst.toString(), |
756 'type': new List.filled(1, type.toMap()), | 766 'type': new List.filled(1, type.toMap()), |
757 'annotations': new List.from(annotations) | 767 'annotations': new List.from(annotations.map((a) => a.toMap())) |
758 }; | 768 }; |
759 } | 769 } |
760 | 770 |
761 /** | 771 /** |
762 * A class containing properties of a Dart method. | 772 * A class containing properties of a Dart method. |
763 */ | 773 */ |
764 class Method extends Indexable { | 774 class Method extends Indexable { |
765 | 775 |
766 /// Parameters for this method. | 776 /// Parameters for this method. |
767 Map<String, Parameter> parameters; | 777 Map<String, Parameter> parameters; |
(...skipping 14 matching lines...) Expand all Loading... | |
782 /// Generates a map describing the [Method] object. | 792 /// Generates a map describing the [Method] object. |
783 Map toMap() => { | 793 Map toMap() => { |
784 'name': name, | 794 'name': name, |
785 'qualifiedname': qualifiedName, | 795 'qualifiedname': qualifiedName, |
786 'comment': comment, | 796 'comment': comment, |
787 'static': isStatic.toString(), | 797 'static': isStatic.toString(), |
788 'abstract': isAbstract.toString(), | 798 'abstract': isAbstract.toString(), |
789 'constant': isConst.toString(), | 799 'constant': isConst.toString(), |
790 'return': new List.filled(1, returnType.toMap()), | 800 'return': new List.filled(1, returnType.toMap()), |
791 'parameters': recurseMap(parameters), | 801 'parameters': recurseMap(parameters), |
792 'annotations': new List.from(annotations) | 802 'annotations': new List.from(annotations.map((a) => a.toMap())) |
793 }; | 803 }; |
794 } | 804 } |
795 | 805 |
796 /** | 806 /** |
797 * A container to categorize methods into the following groups: setters, | 807 * A container to categorize methods into the following groups: setters, |
798 * getters, constructors, operators, regular methods. | 808 * getters, constructors, operators, regular methods. |
799 */ | 809 */ |
800 class MethodGroup { | 810 class MethodGroup { |
801 Map<String, Method> setters = {}; | 811 Map<String, Method> setters = {}; |
802 Map<String, Method> getters = {}; | 812 Map<String, Method> getters = {}; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 this.type, this.defaultValue, this.annotations); | 878 this.type, this.defaultValue, this.annotations); |
869 | 879 |
870 /// Generates a map describing the [Parameter] object. | 880 /// Generates a map describing the [Parameter] object. |
871 Map toMap() => { | 881 Map toMap() => { |
872 'name': name, | 882 'name': name, |
873 'optional': isOptional.toString(), | 883 'optional': isOptional.toString(), |
874 'named': isNamed.toString(), | 884 'named': isNamed.toString(), |
875 'default': hasDefaultValue.toString(), | 885 'default': hasDefaultValue.toString(), |
876 'type': new List.filled(1, type.toMap()), | 886 'type': new List.filled(1, type.toMap()), |
877 'value': defaultValue, | 887 'value': defaultValue, |
878 'annotations': new List.from(annotations) | 888 'annotations': new List.from(annotations.map((a) => a.toMap())) |
879 }; | 889 }; |
880 } | 890 } |
881 | 891 |
882 /** | 892 /** |
883 * A class containing properties of a Generic. | 893 * A class containing properties of a Generic. |
884 */ | 894 */ |
885 class Generic { | 895 class Generic { |
886 String name; | 896 String name; |
887 String type; | 897 String type; |
888 | 898 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 class Type { | 937 class Type { |
928 String outer; | 938 String outer; |
929 List<Type> inner; | 939 List<Type> inner; |
930 | 940 |
931 Type(this.outer, this.inner); | 941 Type(this.outer, this.inner); |
932 | 942 |
933 Map toMap() => { | 943 Map toMap() => { |
934 'outer': outer, | 944 'outer': outer, |
935 'inner': new List.from(inner.map((e) => e.toMap())) | 945 'inner': new List.from(inner.map((e) => e.toMap())) |
936 }; | 946 }; |
947 } | |
948 | |
949 /** | |
950 * Holds the name of the annotation, and its parameters. | |
951 */ | |
952 class Annotation { | |
953 String qualifiedName; | |
954 List<String> parameters; | |
955 | |
956 Annotation(this.qualifiedName, this.parameters); | |
957 | |
958 Map toMap() => { | |
959 'name': qualifiedName, | |
960 'metaparameters': new List.from(parameters) | |
Bob Nystrom
2013/08/02 15:36:04
Why "metaparameters" and not just "parameters"?
I
janicejl
2013/08/02 22:08:07
Done.
| |
961 }; | |
937 } | 962 } |
OLD | NEW |