Chromium Code Reviews| 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 * The docgen tool takes in a library as input and produces documentation | 6 * The docgen tool takes in a library as input and produces documentation |
| 7 * for the library as well as all libraries it imports and uses. The tool can | 7 * for the library as well as all libraries it imports and uses. The tool can |
| 8 * be run by passing in the path to a .dart file like this: | 8 * be run by passing in the path to a .dart file like this: |
| 9 * | 9 * |
| 10 * ./dart docgen.dart path/to/file.dart | 10 * ./dart docgen.dart path/to/file.dart |
| 11 * | 11 * |
| 12 * This outputs information about all classes, variables, functions, and | 12 * This outputs information about all classes, variables, functions, and |
| 13 * methods defined in the library and its imported libraries. | 13 * methods defined in the library and its imported libraries. |
| 14 */ | 14 */ |
| 15 library docgen; | 15 library docgen; |
| 16 | 16 |
| 17 // TODO(tmandel): Use 'package:' references for imports with relative paths. | 17 // TODO(tmandel): Use 'package:' references for imports with relative paths. |
| 18 import 'dart:io'; | 18 import 'dart:io'; |
| 19 import 'dart:json'; | 19 import 'dart:json'; |
| 20 import 'dart:async'; | 20 import 'dart:async'; |
| 21 import '../lib/dart2yaml.dart'; | |
| 22 import '../lib/src/dart2js_mirrors.dart'; | |
| 23 import 'package:markdown/markdown.dart' as markdown; | 21 import 'package:markdown/markdown.dart' as markdown; |
| 24 import '../../args/lib/args.dart'; | 22 import 'package:args/args.dart'; |
| 25 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; | 23 import 'dart2yaml.dart'; |
| 26 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; | 24 import 'package:compiler_unsupported/implementation/mirrors/dart2js_mirror.dart' ; |
| 25 import 'package:compiler_unsupported/implementation/mirrors/mirrors.dart'; | |
| 26 import 'package:compiler_unsupported/implementation/mirrors/mirrors_util.dart'; | |
| 27 | |
| 28 /// Unique ID, will get incremented everytime an ID is requested. | |
| 29 int _uid = 0; | |
| 30 | |
| 31 int getID() => _uid++; | |
| 27 | 32 |
| 28 /** | 33 /** |
| 29 * Entry function to create YAML documentation from Dart files. | 34 * Returns a ArgParser with all the flags and options created. |
| 30 */ | 35 */ |
| 31 void main() { | 36 ArgParser createArgParser(Docgen docgen) { |
| 32 // TODO(tmandel): Use args library once flags are clear. | 37 var parser = new ArgParser(); |
| 33 Options opts = new Options(); | 38 parser.addFlag("help", abbr: "h", help: "Prints help and usage information", |
|
Andrei Mouravski
2013/06/18 02:42:36
Move help text to a new line.
janicejl
2013/06/18 18:42:46
Done.
| |
| 34 Docgen docgen = new Docgen(); | 39 negatable: false, callback: (help) { |
|
Andrei Mouravski
2013/06/18 02:42:36
Move callback to a new line.
janicejl
2013/06/18 18:42:46
Done.
| |
| 40 if (help) print(parser.getUsage()); | |
| 41 }); | |
| 42 parser.addFlag("yaml", abbr: "y", help: "Outputs to YAML", | |
| 43 defaultsTo: true, negatable: true, callback: (yaml) { | |
| 44 docgen.outputToYaml = yaml; | |
| 45 }); | |
| 46 parser.addFlag("json", abbr: "j", help: "Outputs to JSON", | |
| 47 defaultsTo: false, negatable: true, callback: (json) { | |
| 48 docgen.outputToJson = json; | |
| 49 }); | |
| 50 parser.addFlag("hide-private", help: "Hides private declarations" , | |
| 51 defaultsTo: false, negatable: false, callback: (hidePrivate) { | |
| 52 docgen.hidePrivate = hidePrivate; | |
| 53 }); | |
| 54 parser.addFlag("sdk", help: "Flag to parse SDK Library files", | |
| 55 defaultsTo: true, negatable: true, callback: (sdk) { | |
| 56 docgen.sdk = sdk; | |
| 57 }); | |
| 35 | 58 |
| 36 if (opts.arguments.length > 0) { | 59 return parser; |
| 37 List<Path> libraries = [new Path(opts.arguments[0])]; | |
| 38 Path sdkDirectory = new Path("../../../sdk/"); | |
| 39 var workingMirrors = analyze(libraries, sdkDirectory, | |
| 40 options: ['--preserve-comments', '--categories=Client,Server']); | |
| 41 workingMirrors.then( (MirrorSystem mirrorSystem) { | |
| 42 var mirrors = mirrorSystem.libraries.values; | |
| 43 if (mirrors.isEmpty) { | |
| 44 print("no LibraryMirrors"); | |
| 45 } else { | |
| 46 docgen.libraries = mirrors; | |
| 47 docgen.documentLibraries(); | |
| 48 } | |
| 49 }); | |
| 50 } | |
| 51 } | 60 } |
| 52 | 61 |
| 53 /** | 62 /** |
| 54 * This class documents a list of libraries. | 63 * This class documents a list of libraries. |
| 55 */ | 64 */ |
| 56 class Docgen { | 65 class Docgen { |
| 57 | 66 |
| 58 /// Libraries to be documented. | 67 /// Libraries to be documented. |
| 59 List<LibraryMirror> _libraries; | 68 List<LibraryMirror> _libraries; |
| 60 | 69 |
| 61 /// Saves list of libraries for Docgen object. | 70 /// Saves list of libraries for Docgen object. |
| 62 void set libraries(value) => _libraries = value; | 71 void set libraries(value) { |
| 72 _libraries = value; | |
| 73 } | |
| 63 | 74 |
| 64 /// Current library being documented to be used for comment links. | 75 /// Current library being documented to be used for comment links. |
| 65 LibraryMirror _currentLibrary; | 76 LibraryMirror _currentLibrary; |
| 66 | 77 |
| 67 /// Current class being documented to be used for comment links. | 78 /// Current class being documented to be used for comment links. |
| 68 ClassMirror _currentClass; | 79 ClassMirror _currentClass; |
| 69 | 80 |
| 70 /// Current member being documented to be used for comment links. | 81 /// Current member being documented to be used for comment links. |
| 71 MemberMirror _currentMember; | 82 MemberMirror _currentMember; |
| 72 | 83 |
| 73 /// Should the output file type be JSON? | |
| 74 // TODO(tmandel): Add flag to allow for output to JSON. | |
| 75 bool outputToJson = false; | |
| 76 | |
| 77 /// Resolves reference links | 84 /// Resolves reference links |
| 78 markdown.Resolver linkResolver; | 85 markdown.Resolver linkResolver; |
| 79 | 86 |
| 80 /** | 87 /** |
| 81 * Docgen constructor initializes the link resolver for markdown parsing. | 88 * Docgen constructor initializes the link resolver for markdown parsing. |
| 82 */ | 89 */ |
| 83 Docgen() { | 90 Docgen() { |
| 84 this.linkResolver = (name) => | 91 this.linkResolver = (name) => |
| 85 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 92 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 86 } | 93 } |
| 87 | 94 |
| 95 /// Should the output file type be YAML? | |
| 96 bool outputToYaml; | |
| 97 /// Should the output file type be JSON? | |
| 98 bool outputToJson; | |
| 99 /// Should the output file hide private declarations? | |
| 100 bool hidePrivate; | |
| 101 /// Should the output include SDK libraries? | |
| 102 bool sdk; | |
| 103 | |
| 88 /** | 104 /** |
| 89 * Creates documentation for filtered libraries. | 105 * Creates documentation for filtered libraries. |
| 90 */ | 106 */ |
| 91 void documentLibraries() { | 107 void documentLibraries() { |
| 92 //TODO(tmandel): Filter libraries and determine output type using flags. | |
| 93 _libraries.forEach((library) { | 108 _libraries.forEach((library) { |
| 94 _currentLibrary = library; | 109 // Files belong to the SDK have a uri that begins with "dart:". |
| 95 var result = new Library(library.qualifiedName, _getComment(library), | 110 if (sdk || !library.uri.toString().startsWith("dart:")) { |
| 96 _getVariables(library.variables), _getMethods(library.functions), | 111 _currentLibrary = library; |
| 97 _getClasses(library.classes)); | 112 var result = new Library(library.qualifiedName, _getComment(library), |
| 98 if (outputToJson) { | 113 _getVariables(library.variables), _getMethods(library.functions), |
| 99 _writeToFile(stringify(result.toMap()), "${result.name}.json"); | 114 _getClasses(library.classes), getID()); |
| 100 } else { | 115 if (outputToJson) { |
| 101 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml"); | 116 _writeToFile(stringify(result.toMap()), "${result.name}.json"); |
| 102 } | 117 } |
| 118 if (outputToYaml) { | |
| 119 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml"); | |
| 120 } | |
| 121 } | |
| 103 }); | 122 }); |
| 104 } | 123 } |
| 105 | 124 |
| 106 /** | 125 /** |
| 107 * Returns any documentation comments associated with a mirror with | 126 * Returns any documentation comments associated with a mirror with |
| 108 * simple markdown converted to html. | 127 * simple markdown converted to html. |
| 109 */ | 128 */ |
| 110 String _getComment(DeclarationMirror mirror) { | 129 String _getComment(DeclarationMirror mirror) { |
| 111 String commentText; | 130 String commentText; |
| 112 mirror.metadata.forEach((metadata) { | 131 mirror.metadata.forEach((metadata) { |
| 113 if (metadata is CommentInstanceMirror) { | 132 if (metadata is CommentInstanceMirror) { |
| 114 CommentInstanceMirror comment = metadata; | 133 CommentInstanceMirror comment = metadata; |
| 115 if (comment.isDocComment) { | 134 if (comment.isDocComment) { |
| 116 if (commentText == null) { | 135 if (commentText == null) { |
| 117 commentText = comment.trimmedText; | 136 commentText = comment.trimmedText; |
| 118 } else { | 137 } else { |
| 119 commentText = "$commentText ${comment.trimmedText}"; | 138 commentText = "$commentText ${comment.trimmedText}"; |
| 120 } | 139 } |
| 121 } | 140 } |
| 122 } | 141 } |
| 123 }); | 142 }); |
| 124 return commentText == null ? "" : | 143 commentText = commentText == null ? "" : |
| 125 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver); | 144 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver); |
| 145 return commentText.replaceAll("\n", "<br/>"); | |
| 126 } | 146 } |
| 127 | 147 |
| 128 /** | 148 /** |
| 129 * Converts all [_] references in comments to <code>_</code>. | 149 * Converts all [_] references in comments to <code>_</code>. |
| 130 */ | 150 */ |
| 131 // TODO(tmandel): Create proper links for [_] style markdown based | 151 // TODO(tmandel): Create proper links for [_] style markdown based |
| 132 // on scope once layout of viewer is finished. | 152 // on scope once layout of viewer is finished. |
| 133 markdown.Node fixReference(String name, LibraryMirror currentLibrary, | 153 markdown.Node fixReference(String name, LibraryMirror currentLibrary, |
| 134 ClassMirror currentClass, MemberMirror currentMember) { | 154 ClassMirror currentClass, MemberMirror currentMember) { |
| 135 return new markdown.Element.text('code', name); | 155 return new markdown.Element.text('code', name); |
| 136 } | 156 } |
| 137 | 157 |
| 138 /** | 158 /** |
| 139 * Returns a map of [Variable] objects constructed from inputted mirrors. | 159 * Returns a map of [Variable] objects constructed from inputted mirrors. |
| 140 */ | 160 */ |
| 141 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { | 161 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { |
| 142 var data = {}; | 162 var data = {}; |
| 143 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { | 163 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { |
| 144 _currentMember = mirror; | 164 if (!hidePrivate || !mirror.isPrivate) { |
| 145 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, | 165 _currentMember = mirror; |
| 146 mirror.isStatic, mirror.type.toString(), _getComment(mirror)); | 166 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, |
| 167 mirror.isStatic, mirror.type.toString(), _getComment(mirror), | |
| 168 getID()); | |
| 169 } | |
| 147 }); | 170 }); |
| 148 return data; | 171 return data; |
| 149 } | 172 } |
| 150 | 173 |
| 151 /** | 174 /** |
| 152 * Returns a map of [Method] objects constructed from inputted mirrors. | 175 * Returns a map of [Method] objects constructed from inputted mirrors. |
| 153 */ | 176 */ |
| 154 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { | 177 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { |
| 155 var data = {}; | 178 var data = {}; |
| 156 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { | 179 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { |
| 157 _currentMember = mirror; | 180 if (!hidePrivate || !mirror.isPrivate) { |
| 158 data[mirrorName] = new Method(mirrorName, mirror.isSetter, | 181 _currentMember = mirror; |
| 159 mirror.isGetter, mirror.isConstructor, mirror.isOperator, | 182 data[mirrorName] = new Method(mirrorName, mirror.isSetter, |
| 160 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror), | 183 mirror.isGetter, mirror.isConstructor, mirror.isOperator, |
| 161 _getParameters(mirror.parameters)); | 184 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror), |
| 185 _getParameters(mirror.parameters), getID()); | |
| 186 } | |
| 162 }); | 187 }); |
| 163 return data; | 188 return data; |
| 164 } | 189 } |
| 165 | 190 |
| 166 /** | 191 /** |
| 167 * Returns a map of [Class] objects constructed from inputted mirrors. | 192 * Returns a map of [Class] objects constructed from inputted mirrors. |
| 168 */ | 193 */ |
| 169 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { | 194 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { |
| 170 var data = {}; | 195 var data = {}; |
| 171 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { | 196 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
| 172 _currentClass = mirror; | 197 if (!hidePrivate || !mirror.isPrivate) { |
| 173 var superclass; | 198 _currentClass = mirror; |
| 174 if (mirror.superclass != null) { | 199 var superclass = (mirror.superclass != null) ? |
| 175 superclass = mirror.superclass.qualifiedName; | 200 mirror.superclass.qualifiedName : ""; |
| 201 var interfaces = | |
| 202 mirror.superinterfaces.map((interface) => interface.qualifiedName); | |
| 203 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, | |
| 204 mirror.isTypedef, _getComment(mirror), interfaces.toList(), | |
| 205 _getVariables(mirror.variables), _getMethods(mirror.methods), | |
| 206 getID()); | |
| 176 } | 207 } |
| 177 var interfaces = | |
| 178 mirror.superinterfaces.map((interface) => interface.qualifiedName); | |
| 179 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, | |
| 180 mirror.isTypedef, _getComment(mirror), interfaces, | |
| 181 _getVariables(mirror.variables), _getMethods(mirror.methods)); | |
| 182 }); | 208 }); |
| 183 return data; | 209 return data; |
| 184 } | 210 } |
| 185 | 211 |
| 186 /** | 212 /** |
| 187 * Returns a map of [Parameter] objects constructed from inputted mirrors. | 213 * Returns a map of [Parameter] objects constructed from inputted mirrors. |
| 188 */ | 214 */ |
| 189 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { | 215 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { |
| 190 var data = {}; | 216 var data = {}; |
| 191 mirrorList.forEach((ParameterMirror mirror) { | 217 mirrorList.forEach((ParameterMirror mirror) { |
| 192 _currentMember = mirror; | 218 _currentMember = mirror; |
| 193 data[mirror.simpleName] = new Parameter(mirror.simpleName, | 219 data[mirror.simpleName] = new Parameter(mirror.simpleName, |
| 194 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, | 220 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, |
| 195 mirror.type.toString(), mirror.defaultValue); | 221 mirror.type.toString(), mirror.defaultValue, getID()); |
| 196 }); | 222 }); |
| 197 return data; | 223 return data; |
| 198 } | 224 } |
| 199 } | 225 } |
| 200 | 226 |
| 201 /** | 227 /** |
| 202 * Transforms the map by calling toMap on each value in it. | 228 * Transforms the map by calling toMap on each value in it. |
| 203 */ | 229 */ |
| 204 Map recurseMap(Map inputMap) { | 230 Map recurseMap(Map inputMap) { |
| 205 var outputMap = {}; | 231 var outputMap = {}; |
| 206 inputMap.forEach((key, value) { | 232 inputMap.forEach((key, value) { |
| 207 outputMap[key] = value.toMap(); | 233 outputMap[key] = value.toMap(); |
| 208 }); | 234 }); |
| 209 return outputMap; | 235 return outputMap; |
| 210 } | 236 } |
| 211 | 237 |
| 212 /** | 238 /** |
| 213 * A class containing contents of a Dart library. | 239 * A class containing contents of a Dart library. |
| 214 */ | 240 */ |
| 215 class Library { | 241 class Library { |
| 216 | 242 |
| 243 /// Unique ID number for resolving links. | |
| 244 int id; | |
| 245 | |
| 217 /// Documentation comment with converted markdown. | 246 /// Documentation comment with converted markdown. |
| 218 String comment; | 247 String comment; |
| 219 | 248 |
| 220 /// Top-level variables in the library. | 249 /// Top-level variables in the library. |
| 221 Map<String, Variable> variables; | 250 Map<String, Variable> variables; |
| 222 | 251 |
| 223 /// Top-level functions in the library. | 252 /// Top-level functions in the library. |
| 224 Map<String, Method> functions; | 253 Map<String, Method> functions; |
| 225 | 254 |
| 226 /// Classes defined within the library | 255 /// Classes defined within the library |
| 227 Map<String, Class> classes; | 256 Map<String, Class> classes; |
| 228 | 257 |
| 229 String name; | 258 String name; |
| 230 | 259 |
| 231 Library(this.name, this.comment, this.variables, | 260 Library(this.name, this.comment, this.variables, |
| 232 this.functions, this.classes); | 261 this.functions, this.classes, this.id); |
| 233 | 262 |
| 234 /// Generates a map describing the [Library] object. | 263 /// Generates a map describing the [Library] object. |
| 235 Map toMap() { | 264 Map toMap() { |
| 236 var libraryMap = {}; | 265 var libraryMap = {}; |
| 266 libraryMap["id"] = id; | |
| 237 libraryMap["name"] = name; | 267 libraryMap["name"] = name; |
| 238 libraryMap["comment"] = comment; | 268 libraryMap["comment"] = comment; |
| 239 libraryMap["variables"] = recurseMap(variables); | 269 libraryMap["variables"] = recurseMap(variables); |
| 240 libraryMap["functions"] = recurseMap(functions); | 270 libraryMap["functions"] = recurseMap(functions); |
| 241 libraryMap["classes"] = recurseMap(classes); | 271 libraryMap["classes"] = recurseMap(classes); |
| 242 return libraryMap; | 272 return libraryMap; |
| 243 } | 273 } |
| 244 } | 274 } |
| 245 | 275 |
| 246 /** | 276 /** |
| 247 * A class containing contents of a Dart class. | 277 * A class containing contents of a Dart class. |
| 248 */ | 278 */ |
| 249 // TODO(tmandel): Figure out how to do typedefs (what is needed) | 279 // TODO(tmandel): Figure out how to do typedefs (what is needed) |
| 250 class Class { | 280 class Class { |
| 251 | 281 |
| 282 /// Unique ID number for resolving links. | |
| 283 int id; | |
| 284 | |
| 252 /// Documentation comment with converted markdown. | 285 /// Documentation comment with converted markdown. |
| 253 String comment; | 286 String comment; |
| 254 | 287 |
| 255 /// List of the names of interfaces that this class implements. | 288 /// List of the names of interfaces that this class implements. |
| 256 List<String> interfaces; | 289 List<String> interfaces; |
| 257 | 290 |
| 258 /// Top-level variables in the class. | 291 /// Top-level variables in the class. |
| 259 Map<String, Variable> variables; | 292 Map<String, Variable> variables; |
| 260 | 293 |
| 261 /// Methods in the class. | 294 /// Methods in the class. |
| 262 Map<String, Method> methods; | 295 Map<String, Method> methods; |
| 263 | 296 |
| 264 String name; | 297 String name; |
| 265 String superclass; | 298 String superclass; |
| 266 bool isAbstract; | 299 bool isAbstract; |
| 267 bool isTypedef; | 300 bool isTypedef; |
| 268 | 301 |
| 269 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, | 302 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, |
| 270 this.comment, this.interfaces, this.variables, this.methods); | 303 this.comment, this.interfaces, this.variables, this.methods, this.id); |
| 271 | 304 |
| 272 /// Generates a map describing the [Class] object. | 305 /// Generates a map describing the [Class] object. |
| 273 Map toMap() { | 306 Map toMap() { |
| 274 var classMap = {}; | 307 var classMap = {}; |
| 308 classMap["id"] = id; | |
| 275 classMap["name"] = name; | 309 classMap["name"] = name; |
| 276 classMap["comment"] = comment; | 310 classMap["comment"] = comment; |
| 277 classMap["superclass"] = superclass; | 311 classMap["superclass"] = superclass; |
| 278 classMap["abstract"] = isAbstract.toString(); | 312 classMap["abstract"] = isAbstract.toString(); |
| 279 classMap["typedef"] = isTypedef.toString(); | 313 classMap["typedef"] = isTypedef.toString(); |
| 280 classMap["implements"] = new List.from(interfaces); | 314 classMap["implements"] = new List.from(interfaces); |
| 281 classMap["variables"] = recurseMap(variables); | 315 classMap["variables"] = recurseMap(variables); |
| 282 classMap["methods"] = recurseMap(methods); | 316 classMap["methods"] = recurseMap(methods); |
| 283 return classMap; | 317 return classMap; |
| 284 } | 318 } |
| 285 } | 319 } |
| 286 | 320 |
| 287 /** | 321 /** |
| 288 * A class containing properties of a Dart variable. | 322 * A class containing properties of a Dart variable. |
| 289 */ | 323 */ |
| 290 class Variable { | 324 class Variable { |
| 291 | 325 |
| 326 /// Unique ID number for resolving links. | |
| 327 int id; | |
| 328 | |
| 292 /// Documentation comment with converted markdown. | 329 /// Documentation comment with converted markdown. |
| 293 String comment; | 330 String comment; |
| 294 | 331 |
| 295 String name; | 332 String name; |
| 296 bool isFinal; | 333 bool isFinal; |
| 297 bool isStatic; | 334 bool isStatic; |
| 298 String type; | 335 String type; |
| 299 | 336 |
| 300 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment); | 337 Variable(this.name, this.isFinal, this.isStatic, this.type, |
| 338 this.comment, this.id); | |
| 301 | 339 |
| 302 /// Generates a map describing the [Variable] object. | 340 /// Generates a map describing the [Variable] object. |
| 303 Map toMap() { | 341 Map toMap() { |
| 304 var variableMap = {}; | 342 var variableMap = {}; |
| 343 variableMap["id"] = id; | |
| 305 variableMap["name"] = name; | 344 variableMap["name"] = name; |
| 306 variableMap["comment"] = comment; | 345 variableMap["comment"] = comment; |
| 307 variableMap["final"] = isFinal.toString(); | 346 variableMap["final"] = isFinal.toString(); |
| 308 variableMap["static"] = isStatic.toString(); | 347 variableMap["static"] = isStatic.toString(); |
| 309 variableMap["type"] = type; | 348 variableMap["type"] = type; |
| 310 return variableMap; | 349 return variableMap; |
| 311 } | 350 } |
| 312 } | 351 } |
| 313 | 352 |
| 314 /** | 353 /** |
| 315 * A class containing properties of a Dart method. | 354 * A class containing properties of a Dart method. |
| 316 */ | 355 */ |
| 317 class Method { | 356 class Method { |
| 318 | 357 |
| 358 /// Unique ID number for resolving links. | |
| 359 int id; | |
| 360 | |
| 319 /// Documentation comment with converted markdown. | 361 /// Documentation comment with converted markdown. |
| 320 String comment; | 362 String comment; |
| 321 | 363 |
| 322 /// Parameters for this method. | 364 /// Parameters for this method. |
| 323 Map<String, Parameter> parameters; | 365 Map<String, Parameter> parameters; |
| 324 | 366 |
| 325 String name; | 367 String name; |
| 326 bool isSetter; | 368 bool isSetter; |
| 327 bool isGetter; | 369 bool isGetter; |
| 328 bool isConstructor; | 370 bool isConstructor; |
| 329 bool isOperator; | 371 bool isOperator; |
| 330 bool isStatic; | 372 bool isStatic; |
| 331 String returnType; | 373 String returnType; |
| 332 | 374 |
| 333 Method(this.name, this.isSetter, this.isGetter, this.isConstructor, | 375 Method(this.name, this.isSetter, this.isGetter, this.isConstructor, |
| 334 this.isOperator, this.isStatic, this.returnType, this.comment, | 376 this.isOperator, this.isStatic, this.returnType, this.comment, |
| 335 this.parameters); | 377 this.parameters, this.id); |
| 336 | 378 |
| 337 /// Generates a map describing the [Method] object. | 379 /// Generates a map describing the [Method] object. |
| 338 Map toMap() { | 380 Map toMap() { |
| 339 var methodMap = {}; | 381 var methodMap = {}; |
| 382 methodMap["id"] = id; | |
| 340 methodMap["name"] = name; | 383 methodMap["name"] = name; |
| 341 methodMap["comment"] = comment; | 384 methodMap["comment"] = comment; |
| 342 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" : | 385 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" : |
| 343 isOperator ? "operator" : isConstructor ? "constructor" : "method"; | 386 isOperator ? "operator" : isConstructor ? "constructor" : "method"; |
| 344 methodMap["static"] = isStatic.toString(); | 387 methodMap["static"] = isStatic.toString(); |
| 345 methodMap["return"] = returnType; | 388 methodMap["return"] = returnType; |
| 346 methodMap["parameters"] = recurseMap(parameters); | 389 methodMap["parameters"] = recurseMap(parameters); |
| 347 return methodMap; | 390 return methodMap; |
| 348 } | 391 } |
| 349 } | 392 } |
| 350 | 393 |
| 351 /** | 394 /** |
| 352 * A class containing properties of a Dart method/function parameter. | 395 * A class containing properties of a Dart method/function parameter. |
| 353 */ | 396 */ |
| 354 class Parameter { | 397 class Parameter { |
| 355 | 398 |
| 399 /// Unique ID number for resolving links. | |
| 400 int id; | |
| 401 | |
| 356 String name; | 402 String name; |
| 357 bool isOptional; | 403 bool isOptional; |
| 358 bool isNamed; | 404 bool isNamed; |
| 359 bool hasDefaultValue; | 405 bool hasDefaultValue; |
| 360 String type; | 406 String type; |
| 361 String defaultValue; | 407 String defaultValue; |
| 362 | 408 |
| 363 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, | 409 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, |
| 364 this.type, this.defaultValue); | 410 this.type, this.defaultValue, this.id); |
| 365 | 411 |
| 366 /// Generates a map describing the [Parameter] object. | 412 /// Generates a map describing the [Parameter] object. |
| 367 Map toMap() { | 413 Map toMap() { |
| 368 var parameterMap = {}; | 414 var parameterMap = {}; |
| 415 parameterMap["id"] = id; | |
| 369 parameterMap["name"] = name; | 416 parameterMap["name"] = name; |
| 370 parameterMap["optional"] = isOptional.toString(); | 417 parameterMap["optional"] = isOptional.toString(); |
| 371 parameterMap["named"] = isNamed.toString(); | 418 parameterMap["named"] = isNamed.toString(); |
| 372 parameterMap["default"] = hasDefaultValue.toString(); | 419 parameterMap["default"] = hasDefaultValue.toString(); |
| 373 parameterMap["type"] = type; | 420 parameterMap["type"] = type; |
| 374 parameterMap["value"] = defaultValue; | 421 parameterMap["value"] = defaultValue; |
| 375 return parameterMap; | 422 return parameterMap; |
| 376 } | 423 } |
| 377 } | 424 } |
| 378 | 425 |
| 379 /** | 426 /** |
| 380 * Writes text to a file in the 'docs' directory. | 427 * Writes text to a file in the 'docs' directory. |
| 381 */ | 428 */ |
| 382 void _writeToFile(String text, String filename) { | 429 void _writeToFile(String text, String filename) { |
| 383 Directory dir = new Directory('docs'); | 430 Directory dir = new Directory('docs'); |
| 384 if (!dir.existsSync()) { | 431 if (!dir.existsSync()) { |
| 385 dir.createSync(); | 432 dir.createSync(); |
| 386 } | 433 } |
| 387 File file = new File('docs/$filename'); | 434 File file = new File('docs/$filename'); |
| 388 if (!file.exists()) { | 435 if (!file.existsSync()) { |
| 389 file.createSync(); | 436 file.createSync(); |
| 390 } | 437 } |
| 391 file.openSync(); | 438 file.openSync(); |
| 392 file.writeAsString(text); | 439 file.writeAsString(text); |
| 393 } | 440 } |
| OLD | NEW |