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 /// **docgen** is a tool for creating machine readable representations of Dart | 5 /// **docgen** is a tool for creating machine readable representations of Dart |
| 6 /// code metadata, including: classes, members, comments and annotations. | 6 /// code metadata, including: classes, members, comments and annotations. |
| 7 /// | 7 /// |
| 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. | 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 9 /// | 9 /// |
| 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] | 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 if (append) { | 360 if (append) { |
| 361 var previousIndex = | 361 var previousIndex = |
| 362 JSON.decode(new File('docs/index.json').readAsStringSync()); | 362 JSON.decode(new File('docs/index.json').readAsStringSync()); |
| 363 index.addAll(previousIndex); | 363 index.addAll(previousIndex); |
| 364 } | 364 } |
| 365 _writeToFile(JSON.encode(index), 'index.json'); | 365 _writeToFile(JSON.encode(index), 'index.json'); |
| 366 } | 366 } |
| 367 | 367 |
| 368 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 368 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| 369 _currentLibrary = library; | 369 _currentLibrary = library; |
| 370 var result = new Library(docName(library), _commentToHtml(library), | 370 |
| 371 _variables(library.variables), | 371 filterMap(map, predicate) { |
| 372 _methods(library.functions), | 372 var result = new Map(); |
| 373 _classes(library.classes), _isHidden(library)); | 373 map.forEach((key, value) { |
| 374 if (predicate(value)) result[key] = value; | |
| 375 }); | |
| 376 return result; | |
| 377 } | |
| 378 | |
| 379 var result = new Library( | |
| 380 docName(library), | |
| 381 _commentToHtml(library), | |
| 382 _variables(filterMap(library.declarations, (d) => d is VariableMirror)), | |
| 383 _methods(filterMap(library.declarations, (d) => d is MethodMirror)), | |
| 384 _classes(filterMap(library.declarations, (d) => d is ClassMirror)), | |
| 385 _isHidden(library)); | |
| 374 _findPackage(result, library); | 386 _findPackage(result, library); |
| 375 logger.fine('Generated library for ${result.name}'); | 387 logger.fine('Generated library for ${result.name}'); |
| 376 return result; | 388 return result; |
| 377 } | 389 } |
| 378 | 390 |
| 379 void _writeIndexableToFile(Indexable result, bool outputToYaml) { | 391 void _writeIndexableToFile(Indexable result, bool outputToYaml) { |
| 380 var outputFile = result.fileName; | 392 var outputFile = result.fileName; |
| 381 var output; | 393 var output; |
| 382 if (outputToYaml) { | 394 if (outputToYaml) { |
| 383 output = getYamlString(result.toMap()); | 395 output = getYamlString(result.toMap()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 if (_includePrivate || !mirror.isPrivate) { | 568 if (_includePrivate || !mirror.isPrivate) { |
| 557 group.addMethod(mirror); | 569 group.addMethod(mirror); |
| 558 } | 570 } |
| 559 }); | 571 }); |
| 560 return group; | 572 return group; |
| 561 } | 573 } |
| 562 | 574 |
| 563 /// Returns the [Class] for the given [mirror] has already been created, and if | 575 /// Returns the [Class] for the given [mirror] has already been created, and if |
| 564 /// it does not exist, creates it. | 576 /// it does not exist, creates it. |
| 565 Class _class(ClassMirror mirror) { | 577 Class _class(ClassMirror mirror) { |
| 578 filterMap(map, predicate) { | |
| 579 var result = new Map(); | |
| 580 map.forEach((key, value) { | |
| 581 if (predicate(value)) result[key] = value; | |
| 582 }); | |
| 583 return result; | |
| 584 } | |
|
gbracha
2013/11/07 00:09:11
Could we make this function shared library-wide (p
rmacnak
2013/11/07 00:18:29
Done.
| |
| 585 | |
| 566 var clazz = entityMap[docName(mirror)]; | 586 var clazz = entityMap[docName(mirror)]; |
| 567 if (clazz == null) { | 587 if (clazz == null) { |
| 568 var superclass = mirror.superclass != null ? | 588 var superclass = mirror.superclass != null ? |
| 569 _class(mirror.superclass) : null; | 589 _class(mirror.superclass) : null; |
| 570 var interfaces = | 590 var interfaces = |
| 571 mirror.superinterfaces.map((interface) => _class(interface)); | 591 mirror.superinterfaces.map((interface) => _class(interface)); |
| 572 clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror), | 592 clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror), |
| 573 interfaces.toList(), _variables(mirror.variables), | 593 interfaces.toList(), |
| 574 _methods(mirror.methods), _annotations(mirror), _generics(mirror), | 594 _variables(filterMap(mirror.declarations, (d) => d is VariableMirror)), |
| 595 _methods(filterMap(mirror.declarations, (d) => d is MethodMirror)), | |
|
gbracha
2013/11/07 00:09:11
This now gets you constructors that were not in th
rmacnak
2013/11/07 00:18:29
Fixed.
| |
| 596 _annotations(mirror), _generics(mirror), | |
| 575 docName(mirror), _isHidden(mirror), docName(mirror.owner), | 597 docName(mirror), _isHidden(mirror), docName(mirror.owner), |
| 576 mirror.isAbstract); | 598 mirror.isAbstract); |
| 577 if (superclass != null) clazz.addInherited(superclass); | 599 if (superclass != null) clazz.addInherited(superclass); |
| 578 interfaces.forEach((interface) => clazz.addInherited(interface)); | 600 interfaces.forEach((interface) => clazz.addInherited(interface)); |
| 579 entityMap[docName(mirror)] = clazz; | 601 entityMap[docName(mirror)] = clazz; |
| 580 } | 602 } |
| 581 return clazz; | 603 return clazz; |
| 582 } | 604 } |
| 583 | 605 |
| 584 /// Returns a map of [Class] objects constructed from [mirrorMap]. | 606 /// Returns a map of [Class] objects constructed from [mirrorMap]. |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1238 String docName(DeclarationMirror m) { | 1260 String docName(DeclarationMirror m) { |
| 1239 if (m is LibraryMirror) { | 1261 if (m is LibraryMirror) { |
| 1240 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); | 1262 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); |
| 1241 } | 1263 } |
| 1242 var owner = m.owner; | 1264 var owner = m.owner; |
| 1243 if (owner == null) return m.qualifiedName; | 1265 if (owner == null) return m.qualifiedName; |
| 1244 // For the unnamed constructor we just return the class name. | 1266 // For the unnamed constructor we just return the class name. |
| 1245 if (m.simpleName == '') return docName(owner); | 1267 if (m.simpleName == '') return docName(owner); |
| 1246 return docName(owner) + '.' + m.simpleName; | 1268 return docName(owner) + '.' + m.simpleName; |
| 1247 } | 1269 } |
| OLD | NEW |