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

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

Powered by Google App Engine
This is Rietveld 408576698