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

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

Issue 170783009: pkg/docgen: updated min dependencies of args and unittest (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | pkg/docgen/pubspec.yaml » ('j') | pkg/docgen/pubspec.yaml » ('J')
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 } 218 }
219 219
220 /// Docgen representation of an item to be documented, that wraps around a 220 /// Docgen representation of an item to be documented, that wraps around a
221 /// dart2js mirror. 221 /// dart2js mirror.
222 abstract class MirrorBased { 222 abstract class MirrorBased {
223 /// The original dart2js mirror around which this object wraps. 223 /// The original dart2js mirror around which this object wraps.
224 DeclarationMirror get mirror; 224 DeclarationMirror get mirror;
225 225
226 /// Returns a list of meta annotations assocated with a mirror. 226 /// Returns a list of meta annotations assocated with a mirror.
227 List<Annotation> _createAnnotations(DeclarationMirror mirror, 227 static List<Annotation> _createAnnotations(DeclarationMirror mirror,
228 Library owningLibrary) { 228 Library owningLibrary) {
229 var annotationMirrors = mirror.metadata.where((e) => 229 var annotationMirrors = mirror.metadata.where((e) =>
230 e is dart2js_mirrors.Dart2JsConstructedConstantMirror); 230 e is dart2js_mirrors.Dart2JsConstructedConstantMirror);
231 var annotations = []; 231 var annotations = [];
232 annotationMirrors.forEach((annotation) { 232 annotationMirrors.forEach((annotation) {
233 var docgenAnnotation = new Annotation(annotation, owningLibrary); 233 var docgenAnnotation = new Annotation(annotation, owningLibrary);
234 if (!_SKIPPED_ANNOTATIONS.contains( 234 if (!_SKIPPED_ANNOTATIONS.contains(
235 dart2js_util.qualifiedNameOf(docgenAnnotation.mirror))) { 235 dart2js_util.qualifiedNameOf(docgenAnnotation.mirror))) {
236 annotations.add(docgenAnnotation); 236 annotations.add(docgenAnnotation);
237 } 237 }
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 var superinterfaces = classMirror.superinterfaces.map( 1662 var superinterfaces = classMirror.superinterfaces.map(
1663 (interface) => new Class._possiblyDifferentOwner(interface, owner)); 1663 (interface) => new Class._possiblyDifferentOwner(interface, owner));
1664 this.superclass = classMirror.superclass == null? null : 1664 this.superclass = classMirror.superclass == null? null :
1665 new Class._possiblyDifferentOwner(classMirror.superclass, owner); 1665 new Class._possiblyDifferentOwner(classMirror.superclass, owner);
1666 1666
1667 interfaces = superinterfaces.toList(); 1667 interfaces = superinterfaces.toList();
1668 variables = _createVariables( 1668 variables = _createVariables(
1669 dart2js_util.variablesOf(classMirror.declarations), this); 1669 dart2js_util.variablesOf(classMirror.declarations), this);
1670 methods = _createMethods(classMirror.declarations.values.where( 1670 methods = _createMethods(classMirror.declarations.values.where(
1671 (mirror) => mirror is MethodMirror), this); 1671 (mirror) => mirror is MethodMirror), this);
1672 annotations = _createAnnotations(classMirror, _getOwningLibrary(owner)); 1672 annotations = MirrorBased._createAnnotations(classMirror, _getOwningLibrary( owner));
1673 generics = _createGenerics(classMirror); 1673 generics = _createGenerics(classMirror);
1674 isAbstract = classMirror.isAbstract; 1674 isAbstract = classMirror.isAbstract;
1675 inheritedMethods = new Map<String, Method>(); 1675 inheritedMethods = new Map<String, Method>();
1676 1676
1677 // Tell superclass that you are a subclass, unless you are not 1677 // Tell superclass that you are a subclass, unless you are not
1678 // visible or an intermediary mixin class. 1678 // visible or an intermediary mixin class.
1679 if (!classMirror.isNameSynthetic && _isVisible && superclass != null) { 1679 if (!classMirror.isNameSynthetic && _isVisible && superclass != null) {
1680 superclass.addSubclass(this); 1680 superclass.addSubclass(this);
1681 } 1681 }
1682 1682
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 aTypedef = new Typedef._(mirror, owningLibrary); 1845 aTypedef = new Typedef._(mirror, owningLibrary);
1846 } 1846 }
1847 return aTypedef; 1847 return aTypedef;
1848 } 1848 }
1849 1849
1850 Typedef._(TypedefMirror mirror, Library owningLibrary) : 1850 Typedef._(TypedefMirror mirror, Library owningLibrary) :
1851 super(mirror, owningLibrary) { 1851 super(mirror, owningLibrary) {
1852 returnType = Indexable.getDocgenObject(mirror.referent.returnType).docName; 1852 returnType = Indexable.getDocgenObject(mirror.referent.returnType).docName;
1853 generics = _createGenerics(mirror); 1853 generics = _createGenerics(mirror);
1854 parameters = _createParameters(mirror.referent.parameters, owningLibrary); 1854 parameters = _createParameters(mirror.referent.parameters, owningLibrary);
1855 annotations = _createAnnotations(mirror, owningLibrary); 1855 annotations = MirrorBased._createAnnotations(mirror, owningLibrary);
1856 } 1856 }
1857 1857
1858 Map toMap() => { 1858 Map toMap() => {
1859 'name': name, 1859 'name': name,
1860 'qualifiedName': qualifiedName, 1860 'qualifiedName': qualifiedName,
1861 'comment': comment, 1861 'comment': comment,
1862 'return': returnType, 1862 'return': returnType,
1863 'parameters': recurseMap(parameters), 1863 'parameters': recurseMap(parameters),
1864 'annotations': annotations.map((a) => a.toMap()).toList(), 1864 'annotations': annotations.map((a) => a.toMap()).toList(),
1865 'generics': recurseMap(generics) 1865 'generics': recurseMap(generics)
(...skipping 23 matching lines...) Expand all
1889 } 1889 }
1890 return variable; 1890 return variable;
1891 } 1891 }
1892 1892
1893 Variable._(this._variableName, VariableMirror mirror, Indexable owner) : 1893 Variable._(this._variableName, VariableMirror mirror, Indexable owner) :
1894 super(mirror, owner) { 1894 super(mirror, owner) {
1895 isFinal = mirror.isFinal; 1895 isFinal = mirror.isFinal;
1896 isStatic = mirror.isStatic; 1896 isStatic = mirror.isStatic;
1897 isConst = mirror.isConst; 1897 isConst = mirror.isConst;
1898 type = new Type(mirror.type, _getOwningLibrary(owner)); 1898 type = new Type(mirror.type, _getOwningLibrary(owner));
1899 annotations = _createAnnotations(mirror, _getOwningLibrary(owner)); 1899 annotations = MirrorBased._createAnnotations(mirror, _getOwningLibrary(owner ));
1900 } 1900 }
1901 1901
1902 String get name => _variableName; 1902 String get name => _variableName;
1903 1903
1904 /// Generates a map describing the [Variable] object. 1904 /// Generates a map describing the [Variable] object.
1905 Map toMap() => { 1905 Map toMap() => {
1906 'name': name, 1906 'name': name,
1907 'qualifiedName': qualifiedName, 1907 'qualifiedName': qualifiedName,
1908 'comment': comment, 1908 'comment': comment,
1909 'final': isFinal.toString(), 1909 'final': isFinal,
Alan Knight 2014/02/19 19:00:46 Have we tested how the viewer deals with this?
1910 'static': isStatic.toString(), 1910 'static': isStatic,
1911 'constant': isConst.toString(), 1911 'constant': isConst,
1912 'type': new List.filled(1, type.toMap()), 1912 'type': new List.filled(1, type.toMap()),
1913 'annotations': annotations.map((a) => a.toMap()).toList() 1913 'annotations': annotations.map((a) => a.toMap()).toList()
1914 }; 1914 };
1915 1915
1916 String get typeName => 'property'; 1916 String get typeName => 'property';
1917 1917
1918 get comment { 1918 get comment {
1919 if (_comment != null) return _comment; 1919 if (_comment != null) return _comment;
1920 if (owner is Class) { 1920 if (owner is Class) {
1921 (owner as Class).ensureComments(); 1921 (owner as Class).ensureComments();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 return method; 1968 return method;
1969 } 1969 }
1970 1970
1971 Method._(MethodMirror mirror, Indexable owner, this.methodInheritedFrom) 1971 Method._(MethodMirror mirror, Indexable owner, this.methodInheritedFrom)
1972 : super(mirror, owner) { 1972 : super(mirror, owner) {
1973 isStatic = mirror.isStatic; 1973 isStatic = mirror.isStatic;
1974 isAbstract = mirror.isAbstract; 1974 isAbstract = mirror.isAbstract;
1975 isConst = mirror.isConstConstructor; 1975 isConst = mirror.isConstConstructor;
1976 returnType = new Type(mirror.returnType, _getOwningLibrary(owner)); 1976 returnType = new Type(mirror.returnType, _getOwningLibrary(owner));
1977 parameters = _createParameters(mirror.parameters, owner); 1977 parameters = _createParameters(mirror.parameters, owner);
1978 annotations = _createAnnotations(mirror, _getOwningLibrary(owner)); 1978 annotations = MirrorBased._createAnnotations(mirror, _getOwningLibrary(owner ));
1979 } 1979 }
1980 1980
1981 Method get originallyInheritedFrom => methodInheritedFrom == null ? 1981 Method get originallyInheritedFrom => methodInheritedFrom == null ?
1982 this : methodInheritedFrom.originallyInheritedFrom; 1982 this : methodInheritedFrom.originallyInheritedFrom;
1983 1983
1984 /// Look for the specified name starting with the current member, and 1984 /// Look for the specified name starting with the current member, and
1985 /// progressively working outward to the current library scope. 1985 /// progressively working outward to the current library scope.
1986 String findElementInScope(String name) { 1986 String findElementInScope(String name) {
1987 var lookupFunc = Indexable.determineLookupFunc(name); 1987 var lookupFunc = Indexable.determineLookupFunc(name);
1988 1988
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 /// Generates a map describing the [Method] object. 2034 /// Generates a map describing the [Method] object.
2035 Map toMap() => { 2035 Map toMap() => {
2036 'name': name, 2036 'name': name,
2037 'qualifiedName': qualifiedName, 2037 'qualifiedName': qualifiedName,
2038 'comment': comment, 2038 'comment': comment,
2039 'commentFrom': (methodInheritedFrom != null && 2039 'commentFrom': (methodInheritedFrom != null &&
2040 commentInheritedFrom == methodInheritedFrom.docName ? '' 2040 commentInheritedFrom == methodInheritedFrom.docName ? ''
2041 : commentInheritedFrom), 2041 : commentInheritedFrom),
2042 'inheritedFrom': (methodInheritedFrom == null? '' : 2042 'inheritedFrom': (methodInheritedFrom == null? '' :
2043 originallyInheritedFrom.docName), 2043 originallyInheritedFrom.docName),
2044 'static': isStatic.toString(), 2044 'static': isStatic,
2045 'abstract': isAbstract.toString(), 2045 'abstract': isAbstract,
2046 'constant': isConst.toString(), 2046 'constant': isConst,
2047 'return': new List.filled(1, returnType.toMap()), 2047 'return': new List.filled(1, returnType.toMap()),
2048 'parameters': recurseMap(parameters), 2048 'parameters': recurseMap(parameters),
2049 'annotations': annotations.map((a) => a.toMap()).toList() 2049 'annotations': annotations.map((a) => a.toMap()).toList()
2050 }; 2050 };
2051 2051
2052 String get typeName { 2052 String get typeName {
2053 MethodMirror theMirror = mirror; 2053 MethodMirror theMirror = mirror;
2054 if (theMirror.isConstructor) return 'constructor'; 2054 if (theMirror.isConstructor) return 'constructor';
2055 if (theMirror.isGetter) return 'getter'; 2055 if (theMirror.isGetter) return 'getter';
2056 if (theMirror.isSetter) return'setter'; 2056 if (theMirror.isSetter) return'setter';
(...skipping 22 matching lines...) Expand all
2079 } 2079 }
2080 return result; 2080 return result;
2081 } 2081 }
2082 2082
2083 bool _isValidMirror(DeclarationMirror mirror) => mirror is MethodMirror; 2083 bool _isValidMirror(DeclarationMirror mirror) => mirror is MethodMirror;
2084 } 2084 }
2085 2085
2086 /// Docgen wrapper around the dart2js mirror for a Dart 2086 /// Docgen wrapper around the dart2js mirror for a Dart
2087 /// method/function parameter. 2087 /// method/function parameter.
2088 class Parameter extends MirrorBased { 2088 class Parameter extends MirrorBased {
2089 ParameterMirror mirror; 2089 final ParameterMirror mirror;
2090 String name; 2090 final String name;
2091 bool isOptional; 2091 final bool isOptional;
2092 bool isNamed; 2092 final bool isNamed;
2093 bool hasDefaultValue; 2093 final bool hasDefaultValue;
2094 Type type; 2094 final Type type;
2095 String defaultValue; 2095 final String defaultValue;
2096 /// List of the meta annotations on the parameter. 2096 /// List of the meta annotations on the parameter.
2097 List<Annotation> annotations; 2097 final List<Annotation> annotations;
2098 2098
2099 Parameter(this.mirror, Library owningLibrary) { 2099 Parameter(ParameterMirror mirror, Library owningLibrary)
Emily Fortuna 2014/02/19 17:11:21 is this change really worth it?
kevmoo 2014/02/19 17:13:23 It's tough for me to read through a class that cou
2100 name = dart2js_util.nameOf(mirror); 2100 : this.mirror = mirror,
2101 isOptional = mirror.isOptional; 2101 name = dart2js_util.nameOf(mirror),
2102 isNamed = mirror.isNamed; 2102 isOptional = mirror.isOptional,
2103 hasDefaultValue = mirror.hasDefaultValue; 2103 isNamed = mirror.isNamed,
2104 defaultValue = '${mirror.defaultValue}'; 2104 hasDefaultValue = mirror.hasDefaultValue,
2105 type = new Type(mirror.type, owningLibrary); 2105 defaultValue = '${mirror.defaultValue}',
2106 annotations = _createAnnotations(mirror, owningLibrary); 2106 type = new Type(mirror.type, owningLibrary),
Emily Fortuna 2014/02/19 17:11:21 can this be done here?
kevmoo 2014/02/19 17:13:23 Can what be done where? :-)
2107 } 2107 annotations = MirrorBased._createAnnotations(mirror, owningLibrary);
2108 2108
2109 /// Generates a map describing the [Parameter] object. 2109 /// Generates a map describing the [Parameter] object.
2110 Map toMap() => { 2110 Map toMap() => {
2111 'name': name, 2111 'name': name,
2112 'optional': isOptional.toString(), 2112 'optional': isOptional,
2113 'named': isNamed.toString(), 2113 'named': isNamed,
2114 'default': hasDefaultValue.toString(), 2114 'default': hasDefaultValue,
2115 'type': new List.filled(1, type.toMap()), 2115 'type': new List.filled(1, type.toMap()),
2116 'value': defaultValue, 2116 'value': defaultValue,
2117 'annotations': annotations.map((a) => a.toMap()).toList() 2117 'annotations': annotations.map((a) => a.toMap()).toList()
2118 }; 2118 };
2119 } 2119 }
2120 2120
2121 /// A Docgen wrapper around the dart2js mirror for a generic type. 2121 /// A Docgen wrapper around the dart2js mirror for a generic type.
2122 class Generic extends MirrorBased { 2122 class Generic extends MirrorBased {
2123 TypeVariableMirror mirror; 2123 final TypeVariableMirror mirror;
2124 Generic(this.mirror); 2124 Generic(this.mirror);
2125 Map toMap() => { 2125 Map toMap() => {
2126 'name': dart2js_util.nameOf(mirror), 2126 'name': dart2js_util.nameOf(mirror),
2127 'type': dart2js_util.qualifiedNameOf(mirror.upperBound) 2127 'type': dart2js_util.qualifiedNameOf(mirror.upperBound)
2128 }; 2128 };
2129 } 2129 }
2130 2130
2131 /// Docgen wrapper around the mirror for a return type, and/or its generic 2131 /// Docgen wrapper around the mirror for a return type, and/or its generic
2132 /// type parameters. 2132 /// type parameters.
2133 /// 2133 ///
(...skipping 17 matching lines...) Expand all
2151 /// "return" : 2151 /// "return" :
2152 /// - "outer" : "dart-core.Map" 2152 /// - "outer" : "dart-core.Map"
2153 /// "inner" : 2153 /// "inner" :
2154 /// - "outer" : "dart-core.String" 2154 /// - "outer" : "dart-core.String"
2155 /// "inner" : 2155 /// "inner" :
2156 /// - "outer" : "dart-core.List" 2156 /// - "outer" : "dart-core.List"
2157 /// "inner" : 2157 /// "inner" :
2158 /// - "outer" : "dart-core.int" 2158 /// - "outer" : "dart-core.int"
2159 /// "inner" : 2159 /// "inner" :
2160 class Type extends MirrorBased { 2160 class Type extends MirrorBased {
2161 TypeMirror mirror; 2161 final TypeMirror mirror;
2162 Library owningLibrary; 2162 final Library owningLibrary;
2163 2163
2164 Type(this.mirror, this.owningLibrary); 2164 Type(this.mirror, this.owningLibrary);
2165 2165
2166 /// Returns a list of [Type] objects constructed from TypeMirrors. 2166 /// Returns a list of [Type] objects constructed from TypeMirrors.
2167 List<Type> _createTypeGenerics(TypeMirror mirror) { 2167 List<Type> _createTypeGenerics(TypeMirror mirror) {
2168 if (mirror is ClassMirror) { 2168 if (mirror is ClassMirror) {
2169 var innerList = []; 2169 var innerList = [];
2170 mirror.typeArguments.forEach((e) { 2170 mirror.typeArguments.forEach((e) {
2171 innerList.add(new Type(e, owningLibrary)); 2171 innerList.add(new Type(e, owningLibrary));
2172 }); 2172 });
2173 return innerList; 2173 return innerList;
2174 } 2174 }
2175 return []; 2175 return [];
2176 } 2176 }
2177 2177
2178 Map toMap() { 2178 Map toMap() {
2179 var result = Indexable.getDocgenObject(mirror, owningLibrary); 2179 var result = Indexable.getDocgenObject(mirror, owningLibrary);
2180 return { 2180 return {
2181 // We may encounter types whose corresponding library has not been 2181 // We may encounter types whose corresponding library has not been
2182 // processed yet, so look up with the owningLibrary at the last moment. 2182 // processed yet, so look up with the owningLibrary at the last moment.
2183 'outer': result.packagePrefix + result.docName, 2183 'outer': result.packagePrefix + result.docName,
2184 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), 2184 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(),
2185 }; 2185 };
2186 } 2186 }
2187 } 2187 }
2188 2188
2189 /// Holds the name of the annotation, and its parameters. 2189 /// Holds the name of the annotation, and its parameters.
2190 class Annotation extends MirrorBased { 2190 class Annotation extends MirrorBased {
2191 /// The class of this annotation.
2192 final ClassMirror mirror;
2193 final Library owningLibrary;
2191 List<String> parameters; 2194 List<String> parameters;
2192 /// The class of this annotation.
2193 ClassMirror mirror;
2194 Library owningLibrary;
2195 2195
2196 Annotation(InstanceMirror originalMirror, this.owningLibrary) { 2196 Annotation(InstanceMirror originalMirror, this.owningLibrary)
2197 mirror = originalMirror.type; 2197 : mirror = originalMirror.type {
2198 parameters = dart2js_util.variablesOf(originalMirror.type.declarations) 2198 parameters = dart2js_util.variablesOf(originalMirror.type.declarations)
2199 .where((e) => e.isFinal) 2199 .where((e) => e.isFinal)
2200 .map((e) => originalMirror.getField(e.simpleName).reflectee) 2200 .map((e) => originalMirror.getField(e.simpleName).reflectee)
2201 .where((e) => e != null) 2201 .where((e) => e != null)
2202 .toList(); 2202 .toList();
2203 } 2203 }
2204 2204
2205 Map toMap() => { 2205 Map toMap() => {
2206 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, 2206 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName,
2207 'parameters': parameters 2207 'parameters': parameters
2208 }; 2208 };
2209 } 2209 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/pubspec.yaml » ('j') | pkg/docgen/pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698