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

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

Issue 17611006: Change to use Pathos (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
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 /** 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 *
11 * $ dart docgen.dart [OPTIONS] [FILE/DIR] 11 * $ dart docgen.dart [OPTIONS] [FILE/DIR]
12 * 12 *
13 * This creates files called `docs/<library_name>.yaml` in your current 13 * This creates files called `docs/<library_name>.yaml` in your current
14 * working directory. 14 * working directory.
15 */ 15 */
16
16 library docgen; 17 library docgen;
17 18
18 import 'dart:io'; 19 import 'dart:io';
19 import 'dart:json'; 20 import 'dart:json';
20 import 'dart:async'; 21 import 'dart:async';
21 22
22 import 'package:args/args.dart'; 23 import 'package:args/args.dart';
23 import 'package:logging/logging.dart'; 24 import 'package:logging/logging.dart';
24 import 'package:markdown/markdown.dart' as markdown; 25 import 'package:markdown/markdown.dart' as markdown;
26 import 'package:pathos/path.dart' as path;
25 27
26 import 'dart2yaml.dart'; 28 import 'dart2yaml.dart';
29 import 'io.dart';
27 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; 30 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
28 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; 31 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
29 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart' 32 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart'
30 as dart2js; 33 as dart2js;
31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; 34 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ;
32 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; 35 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart';
33 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider. dart'; 36 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider. dart';
34 37
35 var logger = new Logger("Docgen"); 38 var logger = new Logger("Docgen");
36 39
37 /// Counter used to provide unique IDs for each distinct item.
38 int _nextID = 0;
39
40 int get nextID => _nextID++;
41
42 const String usage = "Usage: dart docgen.dart [OPTIONS] [fooDir/barFile]"; 40 const String usage = "Usage: dart docgen.dart [OPTIONS] [fooDir/barFile]";
43 41
44 List<Path> listLibraries(List<String> args) {
45 if (args.length != 1) {
46 throw new UnsupportedError(usage);
47 }
48 var libraries = new List<Path>();
49 var type = FileSystemEntity.typeSync(args[0]);
50
51 if (type == FileSystemEntityType.NOT_FOUND) {
52 throw new UnsupportedError("File does not exist. $usage");
53 } else if (type == FileSystemEntityType.LINK) {
54 libraries.addAll(listLibrariesFromDir(new Link(args[0]).targetSync()));
55 } else if (type == FileSystemEntityType.FILE) {
56 libraries.add(new Path(args[0]));
57 logger.info("Added to libraries: ${libraries.last.toString()}");
58 } else if (type == FileSystemEntityType.DIRECTORY) {
59 libraries.addAll(listLibrariesFromDir(args[0]));
60 }
61 return libraries;
62 }
63
64 List<Path> listLibrariesFromDir(String path) {
65 var libraries = new List<Path>();
66 new Directory(path).listSync(recursive: true,
67 followLinks: true).forEach((file) {
68 if (new Path(file.path).extension == "dart") {
69 if (!file.path.contains("/packages/")) {
70 libraries.add(new Path(file.path));
71 logger.info("Added to libraries: ${libraries.last.toString()}");
72 }
73 }
74 });
75 return libraries;
76 }
77
78 /** 42 /**
79 * This class documents a list of libraries. 43 * This class documents a list of libraries.
80 */ 44 */
81 class Docgen { 45 class Docgen {
82 46
83 /// Libraries to be documented. 47 /// Libraries to be documented.
84 List<LibraryMirror> _libraries; 48 List<LibraryMirror> _libraries;
85 49
86 /// Current library being documented to be used for comment links. 50 /// Current library being documented to be used for comment links.
87 LibraryMirror _currentLibrary; 51 LibraryMirror _currentLibrary;
88 52
89 /// Current class being documented to be used for comment links. 53 /// Current class being documented to be used for comment links.
90 ClassMirror _currentClass; 54 ClassMirror _currentClass;
91 55
92 /// Current member being documented to be used for comment links. 56 /// Current member being documented to be used for comment links.
93 MemberMirror _currentMember; 57 MemberMirror _currentMember;
94 58
95 /// Resolves reference links 59 /// Resolves reference links
96 markdown.Resolver linkResolver; 60 markdown.Resolver linkResolver;
97 61
62 /// Package Directory of
Andrei Mouravski 2013/06/25 18:37:41 Of what? don't leave me in suspense! Also, commen
janicejl 2013/06/25 19:47:50 Done.
63 String packageDir;
64
98 bool outputToYaml; 65 bool outputToYaml;
99 bool outputToJson; 66 bool outputToJson;
100 bool includePrivate; 67 bool includePrivate;
101 /// State for whether or not the SDK libraries should also be outputted. 68 /// State for whether or not the SDK libraries should also be outputted.
102 bool includeSdk; 69 bool includeSdk;
103 70
104 /** 71 /**
105 * Docgen constructor initializes the link resolver for markdown parsing. 72 * Docgen constructor initializes the link resolver for markdown parsing.
106 * Also initializes the command line arguments. 73 * Also initializes the command line arguments.
107 */ 74 */
(...skipping 10 matching lines...) Expand all
118 throw new UnsupportedError("Cannot have contradictory output flags."); 85 throw new UnsupportedError("Cannot have contradictory output flags.");
119 } 86 }
120 outputToYaml = argResults["output-format"] == "yaml" ? true : false; 87 outputToYaml = argResults["output-format"] == "yaml" ? true : false;
121 } 88 }
122 outputToJson = !outputToYaml; 89 outputToJson = !outputToYaml;
123 includePrivate = argResults["include-private"]; 90 includePrivate = argResults["include-private"];
124 includeSdk = argResults["include-sdk"]; 91 includeSdk = argResults["include-sdk"];
125 92
126 this.linkResolver = (name) => 93 this.linkResolver = (name) =>
127 fixReference(name, _currentLibrary, _currentClass, _currentMember); 94 fixReference(name, _currentLibrary, _currentClass, _currentMember);
95
96 analyze(argResults.rest);
97 }
98
99 List<String> listLibraries(List<String> args) {
100 if (args.length != 1) {
Andrei Mouravski 2013/06/25 18:37:41 Remove the curlies and put this on one line.
janicejl 2013/06/25 19:47:50 Done.
101 throw new UnsupportedError(usage);
102 }
103 var libraries = new List<String>();
104 var type = FileSystemEntity.typeSync(args[0]);
105
106 if (type == FileSystemEntityType.NOT_FOUND) {
Andrei Mouravski 2013/06/25 18:37:41 How about you create an "else" for this whole big
janicejl 2013/06/25 19:47:50 Done.
107 throw new UnsupportedError("File does not exist. $usage");
108 } else if (type == FileSystemEntityType.LINK) {
109 var files = listDir(resolveLink(args[0]), recursive: true);
Andrei Mouravski 2013/06/25 18:37:41 Split the first else if block into a separate func
janicejl 2013/06/25 19:47:50 Done.
110 libraries.addAll(files.where((f) =>
111 f.endsWith(".dart") && !f.contains("/packages")));
112 packageDir = files.firstWhere((f) =>
113 f.endsWith("/pubspec.yaml"), orElse: () => "");
114 packageDir = packageDir == "" ?
Andrei Mouravski 2013/06/25 18:37:41 Rewrite this as: if (packageDir != '') packageDir
janicejl 2013/06/25 19:47:50 Done.
115 "" : path.dirname(packageDir) + "/packages";
Andrei Mouravski 2013/06/25 18:37:41 Change all " to '
janicejl 2013/06/25 19:47:50 Done.
116 } else if (type == FileSystemEntityType.FILE) {
117 libraries.add(path.absolute(args[0]));
118 packageDir = "";
119 } else if (type == FileSystemEntityType.DIRECTORY) {
120 var files = listDir(args[0], recursive: true);
Andrei Mouravski 2013/06/25 18:37:41 This is copypasta from above. Another good reason
janicejl 2013/06/25 19:47:50 Done.
121 libraries.addAll(files.where((f) =>
122 f.endsWith(".dart") && !f.contains("/packages")));
123 packageDir = files.firstWhere((f) =>
124 f.endsWith("/pubspec.yaml"), orElse: () => "");
125 packageDir = packageDir == "" ?
126 "" : path.dirname(packageDir) + "/packages";
127 }
128 logger.info("Package Directory: $packageDir");
129 libraries.forEach((lib) => logger.info("Added to libraries: $lib"));
Andrei Mouravski 2013/06/25 18:37:41 You should be logging this as you add each library
janicejl 2013/06/25 19:47:50 Done.
130 return libraries;
128 } 131 }
129 132
130 /** 133 /**
131 * Analyzes set of libraries by getting a mirror system and triggers the 134 * Analyzes set of libraries by getting a mirror system and triggers the
132 * documentation of the libraries. 135 * documentation of the libraries.
133 */ 136 */
134 void analyze(List<Path> libraries) { 137 void analyze(List<String> args) {
138 var libraries = listLibraries(args);
139 if (libraries.isEmpty) throw new UnsupportedError("No Libraries. ");
Andrei Mouravski 2013/06/25 18:37:41 Why is there a space after the period? Also, make
janicejl 2013/06/25 19:47:50 Done.
135 // DART_SDK should be set to the root of the SDK library. 140 // DART_SDK should be set to the root of the SDK library.
136 var sdkRoot = Platform.environment["DART_SDK"]; 141 var sdkRoot = Platform.environment["DART_SDK"];
137 if (sdkRoot != null) { 142 if (sdkRoot != null) {
138 logger.info("Using DART_SDK to find SDK at $sdkRoot"); 143 logger.info("Using DART_SDK to find SDK at $sdkRoot");
139 sdkRoot = new Path(sdkRoot);
140 } else { 144 } else {
141 // If DART_SDK is not defined in the environment, 145 // If DART_SDK is not defined in the environment,
142 // assuming the dart executable is from the Dart SDK folder inside bin. 146 // assuming the dart executable is from the Dart SDK folder inside bin.
143 sdkRoot = new Path(new Options().executable).directoryPath 147 sdkRoot = path.dirname(path.dirname(new Options().executable));
144 .directoryPath; 148 logger.info("SDK Root: ${sdkRoot}");
145 logger.info("SDK Root: ${sdkRoot.toString()}");
146 } 149 }
147 150
148 Path packageDir = libraries.last.directoryPath.append("packages"); 151 getMirrorSystem(libraries, new Path(sdkRoot),
149 logger.info("Package Root: ${packageDir.toString()}"); 152 packageRoot: new Path(packageDir)).then((MirrorSystem mirrorSystem) {
Andrei Mouravski 2013/06/25 18:37:41 Put the ".then" on the next line. Also, don't call
janicejl 2013/06/25 19:47:50 Done.
150 getMirrorSystem(libraries, sdkRoot,
151 packageRoot: packageDir).then((MirrorSystem mirrorSystem) {
152 if (mirrorSystem.libraries.values.isEmpty) { 153 if (mirrorSystem.libraries.values.isEmpty) {
153 throw new UnsupportedError("No Library Mirrors."); 154 throw new UnsupportedError("No Library Mirrors.");
154 } 155 }
155 this.libraries = mirrorSystem.libraries.values; 156 this.libraries = mirrorSystem.libraries.values;
156 documentLibraries(); 157 documentLibraries();
157 }); 158 });
158 } 159 }
159 160
160 /** 161 /**
161 * Analyzes set of libraries and provides a mirror system which can be used 162 * Analyzes set of libraries and provides a mirror system which can be used
162 * for static inspection of the source code. 163 * for static inspection of the source code.
163 */ 164 */
164 Future<MirrorSystem> getMirrorSystem(List<Path> libraries, 165 Future<MirrorSystem> getMirrorSystem(List<String> libraries,
165 Path libraryRoot, {Path packageRoot}) { 166 Path libraryRoot, {Path packageRoot}) {
Andrei Mouravski 2013/06/25 18:37:41 Take strings instead of Paths.
janicejl 2013/06/25 19:47:50 Done.
166 SourceFileProvider provider = new SourceFileProvider(); 167 SourceFileProvider provider = new SourceFileProvider();
167 api.DiagnosticHandler diagnosticHandler = 168 api.DiagnosticHandler diagnosticHandler =
168 new FormattingDiagnosticHandler(provider).diagnosticHandler; 169 new FormattingDiagnosticHandler(provider).diagnosticHandler;
169 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); 170 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot'));
170 Uri packageUri = null; 171 Uri packageUri = null;
171 if (packageRoot != null) { 172 if (packageRoot != null) {
172 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); 173 packageUri = currentDirectory.resolve(appendSlash('$packageRoot'));
173 } 174 }
174 List<Uri> librariesUri = <Uri>[]; 175 List<Uri> librariesUri = <Uri>[];
175 libraries.forEach((library) { 176 libraries.forEach((library) {
176 librariesUri.add(currentDirectory.resolve(library.toString())); 177 librariesUri.add(currentDirectory.resolve(library));
177 }); 178 });
178 return dart2js.analyze(librariesUri, libraryUri, packageUri, 179 return dart2js.analyze(librariesUri, libraryUri, packageUri,
179 provider.readStringFromUri, diagnosticHandler, 180 provider.readStringFromUri, diagnosticHandler,
180 ['--preserve-comments', '--categories=Client,Server']); 181 ['--preserve-comments', '--categories=Client,Server']);
181 } 182 }
182 183
183 /** 184 /**
184 * Creates documentation for filtered libraries. 185 * Creates documentation for filtered libraries.
185 */ 186 */
186 void documentLibraries() { 187 void documentLibraries() {
187 _libraries.forEach((library) { 188 _libraries.forEach((library) {
188 // Files belonging to the SDK have a uri that begins with "dart:". 189 // Files belonging to the SDK have a uri that begins with "dart:".
189 if (includeSdk || !library.uri.toString().startsWith("dart:")) { 190 if (includeSdk || !library.uri.toString().startsWith("dart:")) {
190 _currentLibrary = library; 191 _currentLibrary = library;
191 var result = new Library(library.qualifiedName, _getComment(library), 192 var result = new Library(library.qualifiedName, _getComment(library),
192 _getVariables(library.variables), _getMethods(library.functions), 193 _getVariables(library.variables), _getMethods(library.functions),
193 _getClasses(library.classes), nextID); 194 _getClasses(library.classes));
194 if (outputToJson) { 195 if (outputToJson) {
195 _writeToFile(stringify(result.toMap()), "${result.name}.json"); 196 _writeToFile(stringify(result.toMap()), "${result.name}.json");
196 } 197 }
197 if (outputToYaml) { 198 if (outputToYaml) {
198 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml"); 199 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
199 } 200 }
200 } 201 }
201 }); 202 });
202 } 203 }
203 204
204 /// Saves list of libraries for Docgen object. 205 /// Saves list of libraries for Docgen object.
205 void set libraries(value){ 206 void set libraries(value){
206 _libraries = value; 207 _libraries = value;
207 } 208 }
208 209
209 /** 210 /**
210 * Returns any documentation comments associated with a mirror with 211 * Returns any documentation comments associated with a mirror with
211 * simple markdown converted to html. 212 * simple markdown converted to html.
212 */ 213 */
213 String _getComment(DeclarationMirror mirror) { 214 String _getComment(DeclarationMirror mirror) {
214 String commentText; 215 String commentText;
215 mirror.metadata.forEach((metadata) { 216 mirror.metadata.forEach((metadata) {
216 if (metadata is CommentInstanceMirror) { 217 if (metadata is CommentInstanceMirror) {
217 CommentInstanceMirror comment = metadata; 218 CommentInstanceMirror comment = metadata;
218 if (comment.isDocComment) { 219 if (comment.isDocComment) {
(...skipping 22 matching lines...) Expand all
241 } 242 }
242 243
243 /** 244 /**
244 * Returns a map of [Variable] objects constructed from inputted mirrors. 245 * Returns a map of [Variable] objects constructed from inputted mirrors.
245 */ 246 */
246 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { 247 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) {
247 var data = {}; 248 var data = {};
248 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 249 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
249 if (includePrivate || !mirror.isPrivate) { 250 if (includePrivate || !mirror.isPrivate) {
250 _currentMember = mirror; 251 _currentMember = mirror;
251 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 252 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName,
252 mirror.isStatic, mirror.type.toString(), _getComment(mirror), 253 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName,
253 nextID); 254 _getComment(mirror));
254 } 255 }
255 }); 256 });
256 return data; 257 return data;
257 } 258 }
258 259
259 /** 260 /**
260 * Returns a map of [Method] objects constructed from inputted mirrors. 261 * Returns a map of [Method] objects constructed from inputted mirrors.
261 */ 262 */
262 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { 263 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) {
263 var data = {}; 264 var data = {};
264 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 265 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
265 if (includePrivate || !mirror.isPrivate) { 266 if (includePrivate || !mirror.isPrivate) {
266 _currentMember = mirror; 267 _currentMember = mirror;
267 data[mirrorName] = new Method(mirrorName, mirror.isSetter, 268 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName,
268 mirror.isGetter, mirror.isConstructor, mirror.isOperator, 269 mirror.isSetter, mirror.isGetter, mirror.isConstructor,
269 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror), 270 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName,
270 _getParameters(mirror.parameters), nextID); 271 _getComment(mirror), _getParameters(mirror.parameters));
271 } 272 }
272 }); 273 });
273 return data; 274 return data;
274 } 275 }
275 276
276 /** 277 /**
277 * Returns a map of [Class] objects constructed from inputted mirrors. 278 * Returns a map of [Class] objects constructed from inputted mirrors.
278 */ 279 */
279 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { 280 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) {
280 var data = {}; 281 var data = {};
281 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 282 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
282 if (includePrivate || !mirror.isPrivate) { 283 if (includePrivate || !mirror.isPrivate) {
283 _currentClass = mirror; 284 _currentClass = mirror;
284 var superclass = (mirror.superclass != null) ? 285 var superclass = (mirror.superclass != null) ?
285 mirror.superclass.qualifiedName : ""; 286 mirror.superclass.qualifiedName : "";
286 var interfaces = 287 var interfaces =
287 mirror.superinterfaces.map((interface) => interface.qualifiedName); 288 mirror.superinterfaces.map((interface) => interface.qualifiedName);
288 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, 289 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName,
289 mirror.isTypedef, _getComment(mirror), interfaces.toList(), 290 superclass, mirror.isAbstract, mirror.isTypedef,
290 _getVariables(mirror.variables), _getMethods(mirror.methods), 291 _getComment(mirror), interfaces.toList(),
291 nextID); 292 _getVariables(mirror.variables), _getMethods(mirror.methods));
292 } 293 }
293 }); 294 });
294 return data; 295 return data;
295 } 296 }
296 297
297 /** 298 /**
298 * Returns a map of [Parameter] objects constructed from inputted mirrors. 299 * Returns a map of [Parameter] objects constructed from inputted mirrors.
299 */ 300 */
300 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 301 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
301 var data = {}; 302 var data = {};
302 mirrorList.forEach((ParameterMirror mirror) { 303 mirrorList.forEach((ParameterMirror mirror) {
303 _currentMember = mirror; 304 _currentMember = mirror;
304 data[mirror.simpleName] = new Parameter(mirror.simpleName, 305 data[mirror.simpleName] = new Parameter(mirror.simpleName,
305 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, 306 mirror.qualifiedName, mirror.isOptional, mirror.isNamed,
306 mirror.type.toString(), mirror.defaultValue, nextID); 307 mirror.hasDefaultValue, mirror.type.qualifiedName,
308 mirror.defaultValue);
307 }); 309 });
308 return data; 310 return data;
309 } 311 }
310 } 312 }
311 313
312 /** 314 /**
313 * Transforms the map by calling toMap on each value in it. 315 * Transforms the map by calling toMap on each value in it.
314 */ 316 */
315 Map recurseMap(Map inputMap) { 317 Map recurseMap(Map inputMap) {
316 var outputMap = {}; 318 var outputMap = {};
317 inputMap.forEach((key, value) { 319 inputMap.forEach((key, value) {
318 outputMap[key] = value.toMap(); 320 outputMap[key] = value.toMap();
319 }); 321 });
320 return outputMap; 322 return outputMap;
321 } 323 }
322 324
323 /** 325 /**
324 * A class containing contents of a Dart library. 326 * A class containing contents of a Dart library.
325 */ 327 */
326 class Library { 328 class Library {
327 329
328 /// Unique ID number for resolving links.
329 int id;
330
331 /// Documentation comment with converted markdown. 330 /// Documentation comment with converted markdown.
332 String comment; 331 String comment;
333 332
334 /// Top-level variables in the library. 333 /// Top-level variables in the library.
335 Map<String, Variable> variables; 334 Map<String, Variable> variables;
336 335
337 /// Top-level functions in the library. 336 /// Top-level functions in the library.
338 Map<String, Method> functions; 337 Map<String, Method> functions;
339 338
340 /// Classes defined within the library 339 /// Classes defined within the library
341 Map<String, Class> classes; 340 Map<String, Class> classes;
342 341
343 String name; 342 String name;
344 343
345 Library(this.name, this.comment, this.variables, 344 Library(this.name, this.comment, this.variables,
346 this.functions, this.classes, this.id); 345 this.functions, this.classes);
347 346
348 /// Generates a map describing the [Library] object. 347 /// Generates a map describing the [Library] object.
349 Map toMap() { 348 Map toMap() {
350 var libraryMap = {}; 349 var libraryMap = {};
351 libraryMap["id"] = id;
352 libraryMap["name"] = name; 350 libraryMap["name"] = name;
353 libraryMap["comment"] = comment; 351 libraryMap["comment"] = comment;
354 libraryMap["variables"] = recurseMap(variables); 352 libraryMap["variables"] = recurseMap(variables);
355 libraryMap["functions"] = recurseMap(functions); 353 libraryMap["functions"] = recurseMap(functions);
356 libraryMap["classes"] = recurseMap(classes); 354 libraryMap["classes"] = recurseMap(classes);
357 return libraryMap; 355 return libraryMap;
358 } 356 }
359 } 357 }
360 358
361 /** 359 /**
362 * A class containing contents of a Dart class. 360 * A class containing contents of a Dart class.
363 */ 361 */
364 // TODO(tmandel): Figure out how to do typedefs (what is needed) 362 // TODO(tmandel): Figure out how to do typedefs (what is needed)
365 class Class { 363 class Class {
366 364
367 /// Unique ID number for resolving links.
368 int id;
369
370 /// Documentation comment with converted markdown. 365 /// Documentation comment with converted markdown.
371 String comment; 366 String comment;
372 367
373 /// List of the names of interfaces that this class implements. 368 /// List of the names of interfaces that this class implements.
374 List<String> interfaces; 369 List<String> interfaces;
375 370
376 /// Top-level variables in the class. 371 /// Top-level variables in the class.
377 Map<String, Variable> variables; 372 Map<String, Variable> variables;
378 373
379 /// Methods in the class. 374 /// Methods in the class.
380 Map<String, Method> methods; 375 Map<String, Method> methods;
381 376
382 String name; 377 String name;
378 String qualifiedName;
383 String superclass; 379 String superclass;
384 bool isAbstract; 380 bool isAbstract;
385 bool isTypedef; 381 bool isTypedef;
386 382
387 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, 383 Class(this.name, this.qualifiedName, this.superclass, this.isAbstract, this.is Typedef,
388 this.comment, this.interfaces, this.variables, this.methods, this.id); 384 this.comment, this.interfaces, this.variables, this.methods);
389 385
390 /// Generates a map describing the [Class] object. 386 /// Generates a map describing the [Class] object.
391 Map toMap() { 387 Map toMap() {
392 var classMap = {}; 388 var classMap = {};
393 classMap["id"] = id;
394 classMap["name"] = name; 389 classMap["name"] = name;
390 classMap["qualifiedname"] = qualifiedName;
395 classMap["comment"] = comment; 391 classMap["comment"] = comment;
396 classMap["superclass"] = superclass; 392 classMap["superclass"] = superclass;
397 classMap["abstract"] = isAbstract.toString(); 393 classMap["abstract"] = isAbstract.toString();
398 classMap["typedef"] = isTypedef.toString(); 394 classMap["typedef"] = isTypedef.toString();
399 classMap["implements"] = new List.from(interfaces); 395 classMap["implements"] = new List.from(interfaces);
400 classMap["variables"] = recurseMap(variables); 396 classMap["variables"] = recurseMap(variables);
401 classMap["methods"] = recurseMap(methods); 397 classMap["methods"] = recurseMap(methods);
402 return classMap; 398 return classMap;
403 } 399 }
404 } 400 }
405 401
406 /** 402 /**
407 * A class containing properties of a Dart variable. 403 * A class containing properties of a Dart variable.
408 */ 404 */
409 class Variable { 405 class Variable {
410 406
411 /// Unique ID number for resolving links.
412 int id;
413
414 /// Documentation comment with converted markdown. 407 /// Documentation comment with converted markdown.
415 String comment; 408 String comment;
416 409
417 String name; 410 String name;
411 String qualifiedName;
418 bool isFinal; 412 bool isFinal;
419 bool isStatic; 413 bool isStatic;
420 String type; 414 String type;
421 415
422 Variable(this.name, this.isFinal, this.isStatic, this.type, 416 Variable(this.name, this.qualifiedName, this.isFinal, this.isStatic,
423 this.comment, this.id); 417 this.type, this.comment);
424 418
425 /// Generates a map describing the [Variable] object. 419 /// Generates a map describing the [Variable] object.
426 Map toMap() { 420 Map toMap() {
427 var variableMap = {}; 421 var variableMap = {};
428 variableMap["id"] = id;
429 variableMap["name"] = name; 422 variableMap["name"] = name;
423 variableMap["qualifiedname"] = qualifiedName;
430 variableMap["comment"] = comment; 424 variableMap["comment"] = comment;
431 variableMap["final"] = isFinal.toString(); 425 variableMap["final"] = isFinal.toString();
432 variableMap["static"] = isStatic.toString(); 426 variableMap["static"] = isStatic.toString();
433 variableMap["type"] = type; 427 variableMap["type"] = type;
434 return variableMap; 428 return variableMap;
435 } 429 }
436 } 430 }
437 431
438 /** 432 /**
439 * A class containing properties of a Dart method. 433 * A class containing properties of a Dart method.
440 */ 434 */
441 class Method { 435 class Method {
442 436
443 /// Unique ID number for resolving links.
444 int id;
445
446 /// Documentation comment with converted markdown. 437 /// Documentation comment with converted markdown.
447 String comment; 438 String comment;
448 439
449 /// Parameters for this method. 440 /// Parameters for this method.
450 Map<String, Parameter> parameters; 441 Map<String, Parameter> parameters;
451 442
452 String name; 443 String name;
444 String qualifiedName;
453 bool isSetter; 445 bool isSetter;
454 bool isGetter; 446 bool isGetter;
455 bool isConstructor; 447 bool isConstructor;
456 bool isOperator; 448 bool isOperator;
457 bool isStatic; 449 bool isStatic;
458 String returnType; 450 String returnType;
459 451
460 Method(this.name, this.isSetter, this.isGetter, this.isConstructor, 452 Method(this.name, this.qualifiedName, this.isSetter, this.isGetter,
461 this.isOperator, this.isStatic, this.returnType, this.comment, 453 this.isConstructor, this.isOperator, this.isStatic, this.returnType,
462 this.parameters, this.id); 454 this.comment, this.parameters);
463 455
464 /// Generates a map describing the [Method] object. 456 /// Generates a map describing the [Method] object.
465 Map toMap() { 457 Map toMap() {
466 var methodMap = {}; 458 var methodMap = {};
467 methodMap["id"] = id;
468 methodMap["name"] = name; 459 methodMap["name"] = name;
460 methodMap["qualifiedname"] = qualifiedName;
469 methodMap["comment"] = comment; 461 methodMap["comment"] = comment;
470 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" : 462 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" :
471 isOperator ? "operator" : isConstructor ? "constructor" : "method"; 463 isOperator ? "operator" : isConstructor ? "constructor" : "method";
472 methodMap["static"] = isStatic.toString(); 464 methodMap["static"] = isStatic.toString();
473 methodMap["return"] = returnType; 465 methodMap["return"] = returnType;
474 methodMap["parameters"] = recurseMap(parameters); 466 methodMap["parameters"] = recurseMap(parameters);
475 return methodMap; 467 return methodMap;
476 } 468 }
477 } 469 }
478 470
479 /** 471 /**
480 * A class containing properties of a Dart method/function parameter. 472 * A class containing properties of a Dart method/function parameter.
481 */ 473 */
482 class Parameter { 474 class Parameter {
483 475
484 /// Unique ID number for resolving links.
485 int id;
486
487 String name; 476 String name;
477 String qualifiedName;
488 bool isOptional; 478 bool isOptional;
489 bool isNamed; 479 bool isNamed;
490 bool hasDefaultValue; 480 bool hasDefaultValue;
491 String type; 481 String type;
492 String defaultValue; 482 String defaultValue;
493 483
494 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, 484 Parameter(this.name, this.qualifiedName, this.isOptional, this.isNamed, this.h asDefaultValue,
495 this.type, this.defaultValue, this.id); 485 this.type, this.defaultValue);
496 486
497 /// Generates a map describing the [Parameter] object. 487 /// Generates a map describing the [Parameter] object.
498 Map toMap() { 488 Map toMap() {
499 var parameterMap = {}; 489 var parameterMap = {};
500 parameterMap["id"] = id;
501 parameterMap["name"] = name; 490 parameterMap["name"] = name;
491 parameterMap["qualifiedname"] = qualifiedName;
502 parameterMap["optional"] = isOptional.toString(); 492 parameterMap["optional"] = isOptional.toString();
503 parameterMap["named"] = isNamed.toString(); 493 parameterMap["named"] = isNamed.toString();
504 parameterMap["default"] = hasDefaultValue.toString(); 494 parameterMap["default"] = hasDefaultValue.toString();
505 parameterMap["type"] = type; 495 parameterMap["type"] = type;
506 parameterMap["value"] = defaultValue; 496 parameterMap["value"] = defaultValue;
507 return parameterMap; 497 return parameterMap;
508 } 498 }
509 } 499 }
510 500
511 /** 501 /**
512 * Writes text to a file in the 'docs' directory. 502 * Writes text to a file in the 'docs' directory.
513 */ 503 */
514 void _writeToFile(String text, String filename) { 504 void _writeToFile(String text, String filename) {
515 Directory dir = new Directory('docs'); 505 Directory dir = new Directory('docs');
516 if (!dir.existsSync()) { 506 if (!dir.existsSync()) {
517 dir.createSync(); 507 dir.createSync();
518 } 508 }
519 File file = new File('docs/$filename'); 509 File file = new File('docs/$filename');
520 if (!file.existsSync()) { 510 if (!file.existsSync()) {
521 file.createSync(); 511 file.createSync();
522 } 512 }
523 file.openSync(); 513 file.openSync();
524 file.writeAsString(text); 514 file.writeAsString(text);
525 } 515 }
OLDNEW
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/lib/io.dart » ('j') | pkg/docgen/lib/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698