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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 filteredEntities.map((e) => e.qualifiedName), | 358 filteredEntities.map((e) => e.qualifiedName), |
359 filteredEntities.map((e) => e.typeName)); | 359 filteredEntities.map((e) => e.typeName)); |
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 _filterMap(map, predicate) { | |
369 var result = new Map(); | |
370 map.forEach((key, value) { | |
371 if (predicate(value)) result[key] = value; | |
372 }); | |
373 return result; | |
374 } | |
375 | |
376 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 368 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
377 _currentLibrary = library; | 369 _currentLibrary = library; |
378 var result = new Library( | 370 var result = new Library(docName(library), _commentToHtml(library), |
379 docName(library), | 371 _variables(library.variables), |
380 _commentToHtml(library), | 372 _methods(library.functions), |
381 _variables(_filterMap(library.declarations, (d) => d is VariableMirror)), | 373 _classes(library.classes), _isHidden(library)); |
382 _methods(_filterMap(library.declarations, (d) => d is MethodMirror)), | |
383 _classes(_filterMap(library.declarations, (d) => d is ClassMirror)), | |
384 _isHidden(library)); | |
385 _findPackage(result, library); | 374 _findPackage(result, library); |
386 logger.fine('Generated library for ${result.name}'); | 375 logger.fine('Generated library for ${result.name}'); |
387 return result; | 376 return result; |
388 } | 377 } |
389 | 378 |
390 void _writeIndexableToFile(Indexable result, bool outputToYaml) { | 379 void _writeIndexableToFile(Indexable result, bool outputToYaml) { |
391 var outputFile = result.fileName; | 380 var outputFile = result.fileName; |
392 var output; | 381 var output; |
393 if (outputToYaml) { | 382 if (outputToYaml) { |
394 output = getYamlString(result.toMap()); | 383 output = getYamlString(result.toMap()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 /// Returns the [Class] for the given [mirror] has already been created, and if | 563 /// Returns the [Class] for the given [mirror] has already been created, and if |
575 /// it does not exist, creates it. | 564 /// it does not exist, creates it. |
576 Class _class(ClassMirror mirror) { | 565 Class _class(ClassMirror mirror) { |
577 var clazz = entityMap[docName(mirror)]; | 566 var clazz = entityMap[docName(mirror)]; |
578 if (clazz == null) { | 567 if (clazz == null) { |
579 var superclass = mirror.superclass != null ? | 568 var superclass = mirror.superclass != null ? |
580 _class(mirror.superclass) : null; | 569 _class(mirror.superclass) : null; |
581 var interfaces = | 570 var interfaces = |
582 mirror.superinterfaces.map((interface) => _class(interface)); | 571 mirror.superinterfaces.map((interface) => _class(interface)); |
583 clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror), | 572 clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror), |
584 interfaces.toList(), | 573 interfaces.toList(), _variables(mirror.variables), |
585 _variables(_filterMap(mirror.declarations, (d) => d is VariableMirror)), | 574 _methods(mirror.methods), _annotations(mirror), _generics(mirror), |
586 _methods(_filterMap(mirror.declarations, | |
587 (d) => d is MethodMirror && !d.isConstructor)), | |
588 _annotations(mirror), _generics(mirror), | |
589 docName(mirror), _isHidden(mirror), docName(mirror.owner), | 575 docName(mirror), _isHidden(mirror), docName(mirror.owner), |
590 mirror.isAbstract); | 576 mirror.isAbstract); |
591 if (superclass != null) clazz.addInherited(superclass); | 577 if (superclass != null) clazz.addInherited(superclass); |
592 interfaces.forEach((interface) => clazz.addInherited(interface)); | 578 interfaces.forEach((interface) => clazz.addInherited(interface)); |
593 entityMap[docName(mirror)] = clazz; | 579 entityMap[docName(mirror)] = clazz; |
594 } | 580 } |
595 return clazz; | 581 return clazz; |
596 } | 582 } |
597 | 583 |
598 /// Returns a map of [Class] objects constructed from [mirrorMap]. | 584 /// Returns a map of [Class] objects constructed from [mirrorMap]. |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 String docName(DeclarationMirror m) { | 1238 String docName(DeclarationMirror m) { |
1253 if (m is LibraryMirror) { | 1239 if (m is LibraryMirror) { |
1254 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); | 1240 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); |
1255 } | 1241 } |
1256 var owner = m.owner; | 1242 var owner = m.owner; |
1257 if (owner == null) return m.qualifiedName; | 1243 if (owner == null) return m.qualifiedName; |
1258 // For the unnamed constructor we just return the class name. | 1244 // For the unnamed constructor we just return the class name. |
1259 if (m.simpleName == '') return docName(owner); | 1245 if (m.simpleName == '') return docName(owner); |
1260 return docName(owner) + '.' + m.simpleName; | 1246 return docName(owner) + '.' + m.simpleName; |
1261 } | 1247 } |
OLD | NEW |