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

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

Issue 19704003: Created an index of qualified names for libraries, classes, methods, and variables. (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 | « no previous file | no next file » | 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 *
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 /// Current class being documented to be used for comment links. 44 /// Current class being documented to be used for comment links.
45 ClassMirror _currentClass; 45 ClassMirror _currentClass;
46 46
47 /// Current member being documented to be used for comment links. 47 /// Current member being documented to be used for comment links.
48 MemberMirror _currentMember; 48 MemberMirror _currentMember;
49 49
50 /// Resolves reference links in doc comments. 50 /// Resolves reference links in doc comments.
51 markdown.Resolver linkResolver; 51 markdown.Resolver linkResolver;
52 52
53 /// Index of all the qualified names documented.
54 Set<String> qualifiedNameIndex = new Set<String>();
55
53 /** 56 /**
54 * Docgen constructor initializes the link resolver for markdown parsing. 57 * Docgen constructor initializes the link resolver for markdown parsing.
55 * Also initializes the command line arguments. 58 * Also initializes the command line arguments.
56 * 59 *
57 * [packageRoot] is the packages directory of the directory being analyzed. 60 * [packageRoot] is the packages directory of the directory being analyzed.
58 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will 61 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will
59 * also be documented. 62 * also be documented.
60 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. 63 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented.
61 * This option is useful when only the SDK libraries are needed. 64 * This option is useful when only the SDK libraries are needed.
62 * 65 *
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { 213 if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
211 var library = generateLibrary(lib, includePrivate: includePrivate); 214 var library = generateLibrary(lib, includePrivate: includePrivate);
212 _writeLibraryToFile(library, outputToYaml); 215 _writeLibraryToFile(library, outputToYaml);
213 } 216 }
214 }); 217 });
215 // Outputs a text file with a list of files available after creating all 218 // Outputs a text file with a list of files available after creating all
216 // the libraries. This will help the viewer know what files are available 219 // the libraries. This will help the viewer know what files are available
217 // to read in. 220 // to read in.
218 _writeToFile(listDir('docs').join('\n').replaceAll('docs/', ''), 221 _writeToFile(listDir('docs').join('\n').replaceAll('docs/', ''),
219 'library_list.txt'); 222 'library_list.txt');
223 // Outputs all the qualified names documented. This will help generate search
224 // results.
225 _writeToFile(qualifiedNameIndex.join('\n'), 'index.txt');
220 } 226 }
221 227
222 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, 228 Library generateLibrary(dart2js.Dart2JsLibraryMirror library,
223 {bool includePrivate:false}) { 229 {bool includePrivate:false}) {
224 _currentLibrary = library; 230 _currentLibrary = library;
225 var result = new Library(library.qualifiedName, _getComment(library), 231 var result = new Library(library.qualifiedName, _getComment(library),
226 _getVariables(library.variables, includePrivate), 232 _getVariables(library.variables, includePrivate),
227 _getMethods(library.functions, includePrivate), 233 _getMethods(library.functions, includePrivate),
228 _getClasses(library.classes, includePrivate)); 234 _getClasses(library.classes, includePrivate));
229 logger.fine('Generated library for ${result.name}'); 235 logger.fine('Generated library for ${result.name}');
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, 301 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap,
296 bool includePrivate) { 302 bool includePrivate) {
297 var data = {}; 303 var data = {};
298 // TODO(janicejl): When map to map feature is created, replace the below with 304 // TODO(janicejl): When map to map feature is created, replace the below with
299 // a filter. Issue(#9590). 305 // a filter. Issue(#9590).
300 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 306 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
301 if (includePrivate || !mirror.isPrivate) { 307 if (includePrivate || !mirror.isPrivate) {
302 _currentMember = mirror; 308 _currentMember = mirror;
303 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 309 data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
304 mirror.isStatic, mirror.type.qualifiedName, _getComment(mirror), 310 mirror.isStatic, mirror.type.qualifiedName, _getComment(mirror),
305 _getAnnotations(mirror)); 311 _getAnnotations(mirror), mirror.qualifiedName);
306 } 312 }
307 }); 313 });
308 return data; 314 return data;
309 } 315 }
310 316
311 /** 317 /**
312 * Returns a map of [Method] objects constructed from inputted mirrors. 318 * Returns a map of [Method] objects constructed from inputted mirrors.
313 */ 319 */
314 Map<String, Map<String, Method>> _getMethods 320 Map<String, Map<String, Method>> _getMethods
315 (Map<String, MethodMirror> mirrorMap, bool includePrivate) { 321 (Map<String, MethodMirror> mirrorMap, bool includePrivate) {
316 322
317 var setters = {}; 323 var setters = {};
318 var getters = {}; 324 var getters = {};
319 var constructors = {}; 325 var constructors = {};
320 var operators = {}; 326 var operators = {};
321 var methods = {}; 327 var methods = {};
322 328
323 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 329 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
324 if (includePrivate || !mirror.isPrivate) { 330 if (includePrivate || !mirror.isPrivate) {
325 var method = new Method(mirrorName, mirror.isStatic, 331 var method = new Method(mirrorName, mirror.isStatic,
326 mirror.returnType.qualifiedName, _getComment(mirror), 332 mirror.returnType.qualifiedName, _getComment(mirror),
327 _getParameters(mirror.parameters), _getAnnotations(mirror)); 333 _getParameters(mirror.parameters), _getAnnotations(mirror),
334 mirror.qualifiedName);
328 _currentMember = mirror; 335 _currentMember = mirror;
329 if (mirror.isSetter) { 336 if (mirror.isSetter) {
330 setters[mirrorName] = method; 337 setters[mirrorName] = method;
331 } else if (mirror.isGetter) { 338 } else if (mirror.isGetter) {
332 getters[mirrorName] = method; 339 getters[mirrorName] = method;
333 } else if (mirror.isConstructor) { 340 } else if (mirror.isConstructor) {
334 constructors[mirrorName] = method; 341 constructors[mirrorName] = method;
335 } else if (mirror.isOperator) { 342 } else if (mirror.isOperator) {
336 operators[mirrorName] = method; 343 operators[mirrorName] = method;
337 } else if (mirror.isRegularMethod) { 344 } else if (mirror.isRegularMethod) {
(...skipping 20 matching lines...) Expand all
358 if (includePrivate || !mirror.isPrivate) { 365 if (includePrivate || !mirror.isPrivate) {
359 _currentClass = mirror; 366 _currentClass = mirror;
360 var superclass = (mirror.superclass != null) ? 367 var superclass = (mirror.superclass != null) ?
361 mirror.superclass.qualifiedName : ''; 368 mirror.superclass.qualifiedName : '';
362 var interfaces = 369 var interfaces =
363 mirror.superinterfaces.map((interface) => interface.qualifiedName); 370 mirror.superinterfaces.map((interface) => interface.qualifiedName);
364 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract, 371 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
365 mirror.isTypedef, _getComment(mirror), interfaces.toList(), 372 mirror.isTypedef, _getComment(mirror), interfaces.toList(),
366 _getVariables(mirror.variables, includePrivate), 373 _getVariables(mirror.variables, includePrivate),
367 _getMethods(mirror.methods, includePrivate), 374 _getMethods(mirror.methods, includePrivate),
368 _getAnnotations(mirror)); 375 _getAnnotations(mirror), mirror.qualifiedName);
369 } 376 }
370 }); 377 });
371 return data; 378 return data;
372 } 379 }
373 380
374 /** 381 /**
375 * Returns a map of [Parameter] objects constructed from inputted mirrors. 382 * Returns a map of [Parameter] objects constructed from inputted mirrors.
376 */ 383 */
377 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 384 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
378 var data = {}; 385 var data = {};
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (value is Map) { 418 if (value is Map) {
412 outputMap[key] = recurseMap(value); 419 outputMap[key] = recurseMap(value);
413 } else { 420 } else {
414 outputMap[key] = value.toMap(); 421 outputMap[key] = value.toMap();
415 } 422 }
416 }); 423 });
417 return outputMap; 424 return outputMap;
418 } 425 }
419 426
420 /** 427 /**
428 * A class representing all programming constructs, like library or class.
429 */
430 class Indexable {
431 Indexable(String qualifiedName) {
432 qualifiedNameIndex.add(qualifiedName);
433 }
434 }
435
436 /**
421 * A class containing contents of a Dart library. 437 * A class containing contents of a Dart library.
422 */ 438 */
423 class Library { 439 class Library extends Indexable {
424 440
425 /// Documentation comment with converted markdown. 441 /// Documentation comment with converted markdown.
426 String comment; 442 String comment;
427 443
428 /// Top-level variables in the library. 444 /// Top-level variables in the library.
429 Map<String, Variable> variables; 445 Map<String, Variable> variables;
430 446
431 /// Top-level functions in the library. 447 /// Top-level functions in the library.
432 Map<String, Map<String, Method>> functions; 448 Map<String, Map<String, Method>> functions;
433 449
434 /// Classes defined within the library 450 /// Classes defined within the library
435 Map<String, Class> classes; 451 Map<String, Class> classes;
436 452
437 String name; 453 String name;
438 454
439 Library(this.name, this.comment, this.variables, 455 Library(name, this.comment, this.variables,
440 this.functions, this.classes); 456 this.functions, this.classes) : super(name) {
457 this.name = name;
458 }
441 459
442 /// Generates a map describing the [Library] object. 460 /// Generates a map describing the [Library] object.
443 Map toMap() { 461 Map toMap() {
444 var libraryMap = {}; 462 var libraryMap = {};
445 libraryMap['name'] = name; 463 libraryMap['name'] = name;
446 libraryMap['comment'] = comment; 464 libraryMap['comment'] = comment;
447 libraryMap['variables'] = recurseMap(variables); 465 libraryMap['variables'] = recurseMap(variables);
448 libraryMap['functions'] = recurseMap(functions); 466 libraryMap['functions'] = recurseMap(functions);
449 libraryMap['classes'] = recurseMap(classes); 467 libraryMap['classes'] = recurseMap(classes);
450 return libraryMap; 468 return libraryMap;
451 } 469 }
452 } 470 }
453 471
454 /** 472 /**
455 * A class containing contents of a Dart class. 473 * A class containing contents of a Dart class.
456 */ 474 */
457 // TODO(tmandel): Figure out how to do typedefs (what is needed) 475 // TODO(tmandel): Figure out how to do typedefs (what is needed)
458 class Class { 476 class Class extends Indexable {
459 477
460 /// Documentation comment with converted markdown. 478 /// Documentation comment with converted markdown.
461 String comment; 479 String comment;
462 480
463 /// List of the names of interfaces that this class implements. 481 /// List of the names of interfaces that this class implements.
464 List<String> interfaces; 482 List<String> interfaces;
465 483
466 /// Top-level variables in the class. 484 /// Top-level variables in the class.
467 Map<String, Variable> variables; 485 Map<String, Variable> variables;
468 486
469 /// Methods in the class. 487 /// Methods in the class.
470 Map<String, Map<String, Method>> methods; 488 Map<String, Map<String, Method>> methods;
471 489
472 String name; 490 String name;
473 String superclass; 491 String superclass;
474 bool isAbstract; 492 bool isAbstract;
475 bool isTypedef; 493 bool isTypedef;
476 494
477 /// List of the meta annotations on the class. 495 /// List of the meta annotations on the class.
478 List<String> annotations; 496 List<String> annotations;
479 497
480 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, 498 Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
481 this.comment, this.interfaces, this.variables, this.methods, 499 this.comment, this.interfaces, this.variables, this.methods,
482 this.annotations); 500 this.annotations, String qualifiedName) : super(qualifiedName) {}
483 501
484 /// Generates a map describing the [Class] object. 502 /// Generates a map describing the [Class] object.
485 Map toMap() { 503 Map toMap() {
486 var classMap = {}; 504 var classMap = {};
487 classMap['name'] = name; 505 classMap['name'] = name;
488 classMap['comment'] = comment; 506 classMap['comment'] = comment;
489 classMap['superclass'] = superclass; 507 classMap['superclass'] = superclass;
490 classMap['abstract'] = isAbstract.toString(); 508 classMap['abstract'] = isAbstract.toString();
491 classMap['typedef'] = isTypedef.toString(); 509 classMap['typedef'] = isTypedef.toString();
492 classMap['implements'] = new List.from(interfaces); 510 classMap['implements'] = new List.from(interfaces);
493 classMap['variables'] = recurseMap(variables); 511 classMap['variables'] = recurseMap(variables);
494 classMap['methods'] = recurseMap(methods); 512 classMap['methods'] = recurseMap(methods);
495 classMap['annotations'] = new List.from(annotations); 513 classMap['annotations'] = new List.from(annotations);
496 return classMap; 514 return classMap;
497 } 515 }
498 } 516 }
499 517
500 /** 518 /**
501 * A class containing properties of a Dart variable. 519 * A class containing properties of a Dart variable.
502 */ 520 */
503 class Variable { 521 class Variable extends Indexable {
504 522
505 /// Documentation comment with converted markdown. 523 /// Documentation comment with converted markdown.
506 String comment; 524 String comment;
507 525
508 String name; 526 String name;
509 bool isFinal; 527 bool isFinal;
510 bool isStatic; 528 bool isStatic;
511 String type; 529 String type;
512 530
513 /// List of the meta annotations on the variable. 531 /// List of the meta annotations on the variable.
514 List<String> annotations; 532 List<String> annotations;
515 533
516 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment, 534 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment,
517 this.annotations); 535 this.annotations, String qualifiedName) : super(qualifiedName);
518 536
519 /// Generates a map describing the [Variable] object. 537 /// Generates a map describing the [Variable] object.
520 Map toMap() { 538 Map toMap() {
521 var variableMap = {}; 539 var variableMap = {};
522 variableMap['name'] = name; 540 variableMap['name'] = name;
523 variableMap['comment'] = comment; 541 variableMap['comment'] = comment;
524 variableMap['final'] = isFinal.toString(); 542 variableMap['final'] = isFinal.toString();
525 variableMap['static'] = isStatic.toString(); 543 variableMap['static'] = isStatic.toString();
526 variableMap['type'] = type; 544 variableMap['type'] = type;
527 variableMap['annotations'] = new List.from(annotations); 545 variableMap['annotations'] = new List.from(annotations);
528 return variableMap; 546 return variableMap;
529 } 547 }
530 } 548 }
531 549
532 /** 550 /**
533 * A class containing properties of a Dart method. 551 * A class containing properties of a Dart method.
534 */ 552 */
535 class Method { 553 class Method extends Indexable {
536 554
537 /// Documentation comment with converted markdown. 555 /// Documentation comment with converted markdown.
538 String comment; 556 String comment;
539 557
540 /// Parameters for this method. 558 /// Parameters for this method.
541 Map<String, Parameter> parameters; 559 Map<String, Parameter> parameters;
542 560
543 String name; 561 String name;
544 bool isStatic; 562 bool isStatic;
545 String returnType; 563 String returnType;
546 564
547 /// List of the meta annotations on the method. 565 /// List of the meta annotations on the method.
548 List<String> annotations; 566 List<String> annotations;
549 567
550 Method(this.name, this.isStatic, this.returnType, this.comment, 568 Method(this.name, this.isStatic, this.returnType, this.comment,
551 this.parameters, this.annotations); 569 this.parameters, this.annotations, String qualifiedName)
570 : super(qualifiedName);
552 571
553 /// Generates a map describing the [Method] object. 572 /// Generates a map describing the [Method] object.
554 Map toMap() { 573 Map toMap() {
555 var methodMap = {}; 574 var methodMap = {};
556 methodMap['name'] = name; 575 methodMap['name'] = name;
557 methodMap['comment'] = comment; 576 methodMap['comment'] = comment;
558 methodMap['static'] = isStatic.toString(); 577 methodMap['static'] = isStatic.toString();
559 methodMap['return'] = returnType; 578 methodMap['return'] = returnType;
560 methodMap['parameters'] = recurseMap(parameters); 579 methodMap['parameters'] = recurseMap(parameters);
561 methodMap['annotations'] = new List.from(annotations); 580 methodMap['annotations'] = new List.from(annotations);
(...skipping 25 matching lines...) Expand all
587 parameterMap['name'] = name; 606 parameterMap['name'] = name;
588 parameterMap['optional'] = isOptional.toString(); 607 parameterMap['optional'] = isOptional.toString();
589 parameterMap['named'] = isNamed.toString(); 608 parameterMap['named'] = isNamed.toString();
590 parameterMap['default'] = hasDefaultValue.toString(); 609 parameterMap['default'] = hasDefaultValue.toString();
591 parameterMap['type'] = type; 610 parameterMap['type'] = type;
592 parameterMap['value'] = defaultValue; 611 parameterMap['value'] = defaultValue;
593 parameterMap['annotations'] = new List.from(annotations); 612 parameterMap['annotations'] = new List.from(annotations);
594 return parameterMap; 613 return parameterMap;
595 } 614 }
596 } 615 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698