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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 /// viewer with dart2js. | 110 /// viewer with dart2js. |
| 111 /// If [serve] is `true`, then after generating the documents we fire up a | 111 /// If [serve] is `true`, then after generating the documents we fire up a |
| 112 /// simple server to view the documentation. | 112 /// simple server to view the documentation. |
| 113 /// | 113 /// |
| 114 /// Returned Future completes with true if document generation is successful. | 114 /// Returned Future completes with true if document generation is successful. |
| 115 Future<bool> docgen(List<String> files, {String packageRoot, | 115 Future<bool> docgen(List<String> files, {String packageRoot, |
| 116 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 116 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 117 bool parseSdk: false, bool append: false, String introFileName: '', | 117 bool parseSdk: false, bool append: false, String introFileName: '', |
| 118 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], | 118 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], |
| 119 bool includeDependentPackages: false, bool compile: false, bool serve: false , | 119 bool includeDependentPackages: false, bool compile: false, bool serve: false , |
| 120 bool noDocs: false, String startPage, | 120 bool noDocs: false, String startPage, |
| 121 String pubScript, String dartBinary}) { | 121 String pubScript, String dartBinary}) { |
| 122 var result; | 122 var result; |
| 123 if (!noDocs) { | 123 if (!noDocs) { |
| 124 _Viewer.ensureMovedViewerCode(); | 124 _Viewer.ensureMovedViewerCode(); |
| 125 result = _Generator.generateDocumentation(files, packageRoot: packageRoot, | 125 result = _Generator.generateDocumentation(files, packageRoot: packageRoot, |
| 126 outputToYaml: outputToYaml, includePrivate: includePrivate, | 126 outputToYaml: outputToYaml, includePrivate: includePrivate, |
| 127 includeSdk: includeSdk, parseSdk: parseSdk, append: append, | 127 includeSdk: includeSdk, parseSdk: parseSdk, append: append, |
| 128 introFileName: introFileName, out: out, | 128 introFileName: introFileName, out: out, |
| 129 excludeLibraries: excludeLibraries, | 129 excludeLibraries: excludeLibraries, |
| 130 includeDependentPackages: includeDependentPackages, | 130 includeDependentPackages: includeDependentPackages, |
| 131 startPage: startPage, pubScript: pubScript, dartBinary: dartBinary); | 131 startPage: startPage, pubScript: pubScript, dartBinary: dartBinary); |
| 132 _Viewer.addBackViewerCode(); | 132 _Viewer.addBackViewerCode(); |
| 133 if (compile || serve) { | 133 if (compile || serve) { |
| 134 result.then((success) { | 134 result.then((success) { |
| 135 if (success) { | 135 if (success) { |
| 136 _createViewer(serve); | 136 _createViewer(serve); |
| 137 } | 137 } |
| 138 }); | 138 }); |
| 139 } | 139 } |
| 140 } else if (compile || serve) { | 140 } else if (compile || serve) { |
| 141 _createViewer(serve); | 141 _createViewer(serve); |
| 142 } | 142 } |
| 143 return result; | 143 return result; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void _createViewer(bool serve) { | 146 void _createViewer(bool serve) { |
| 147 _Viewer._clone(); | 147 _Viewer._clone(); |
| 148 _Viewer._compile(); | 148 _Viewer._compile(); |
| 149 if (serve) { | 149 if (serve) { |
| 150 _Viewer._runServer(); | 150 _Viewer._runServer(); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 /// Analyzes set of libraries by getting a mirror system and triggers the | 154 /// Analyzes set of libraries by getting a mirror system and triggers the |
| 155 /// documentation of the libraries. | 155 /// documentation of the libraries. |
| 156 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, | 156 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, |
| 157 {String packageRoot, bool parseSdk: false}) { | 157 {String packageRoot, bool parseSdk: false}) { |
| 158 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 158 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 159 | 159 |
| 160 // Finds the root of SDK library based off the location of docgen. | 160 // Finds the root of SDK library based off the location of docgen. |
| 161 // We have two different places to look, depending if we're in a development | 161 // We have two different places to look, depending if we're in a development |
| 162 // repo or in a built SDK, either sdk or dart-sdk respectively | 162 // repo or in a built SDK, either sdk or dart-sdk respectively |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 } | 689 } |
| 690 else { | 690 else { |
| 691 var processResult = Process.runSync('git', ['clone', '-b', 'master', | 691 var processResult = Process.runSync('git', ['clone', '-b', 'master', |
| 692 'git://github.com/dart-lang/dartdoc-viewer.git'], | 692 'git://github.com/dart-lang/dartdoc-viewer.git'], |
| 693 runInShell: true); | 693 runInShell: true); |
| 694 | 694 |
| 695 if (processResult.exitCode == 0) { | 695 if (processResult.exitCode == 0) { |
| 696 /// Move the generated json/yaml docs directory to the dartdoc-viewer | 696 /// Move the generated json/yaml docs directory to the dartdoc-viewer |
| 697 /// directory, to run as a webpage. | 697 /// directory, to run as a webpage. |
| 698 var processResult = Process.runSync(_Generator._pubScript, | 698 var processResult = Process.runSync(_Generator._pubScript, |
| 699 ['upgrade'], runInShell: true, | 699 ['upgrade'], runInShell: true, |
| 700 workingDirectory: path.join(_dartdocViewerDir.path, 'client')); | 700 workingDirectory: path.join(_dartdocViewerDir.path, 'client')); |
| 701 print('process output: ${processResult.stdout}'); | 701 print('process output: ${processResult.stdout}'); |
| 702 print('process stderr: ${processResult.stderr}'); | 702 print('process stderr: ${processResult.stderr}'); |
| 703 | 703 |
| 704 var dir = new Directory(_Generator._outputDirectory == null? 'docs' : | 704 var dir = new Directory(_Generator._outputDirectory == null? 'docs' : |
| 705 _Generator._outputDirectory); | 705 _Generator._outputDirectory); |
| 706 _webDocsDir = new Directory(path.join(_dartdocViewerDir.path, 'client', | 706 _webDocsDir = new Directory(path.join(_dartdocViewerDir.path, 'client', |
| 707 'web', 'docs')); | 707 'web', 'docs')); |
| 708 if (dir.existsSync()) { | 708 if (dir.existsSync()) { |
| 709 // Move the docs folder to dartdoc-viewer/client/web/docs | 709 // Move the docs folder to dartdoc-viewer/client/web/docs |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1582 } | 1582 } |
| 1583 } | 1583 } |
| 1584 var domAnnotation = this.annotations.firstWhere( | 1584 var domAnnotation = this.annotations.firstWhere( |
| 1585 (e) => e.mirror.qualifiedName == #metadata.DomName, | 1585 (e) => e.mirror.qualifiedName == #metadata.DomName, |
| 1586 orElse: () => null); | 1586 orElse: () => null); |
| 1587 if (domAnnotation == null) return ''; | 1587 if (domAnnotation == null) return ''; |
| 1588 var domName = domAnnotation.parameters.single; | 1588 var domName = domAnnotation.parameters.single; |
| 1589 var parts = domName.split('.'); | 1589 var parts = domName.split('.'); |
| 1590 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); | 1590 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); |
| 1591 if (parts.length == 1) return _mdnTypeComment(parts[0]); | 1591 if (parts.length == 1) return _mdnTypeComment(parts[0]); |
| 1592 | |
| 1593 throw new StateError('More than two items is not supported: $parts'); | |
|
kevmoo
2014/02/17 20:27:21
Going with being strict. If the code isn't designe
| |
| 1592 } | 1594 } |
| 1593 | 1595 |
| 1594 String get packagePrefix => owner.packagePrefix; | 1596 String get packagePrefix => owner.packagePrefix; |
| 1595 } | 1597 } |
| 1596 | 1598 |
| 1597 /// A class containing contents of a Dart class. | 1599 /// A class containing contents of a Dart class. |
| 1598 class Class extends OwnedIndexable implements Comparable { | 1600 class Class extends OwnedIndexable implements Comparable { |
| 1599 | 1601 |
| 1600 /// List of the names of interfaces that this class implements. | 1602 /// List of the names of interfaces that this class implements. |
| 1601 List<Class> interfaces = []; | 1603 List<Class> interfaces = []; |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2198 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 2200 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 2199 .where((e) => e != null) | 2201 .where((e) => e != null) |
| 2200 .toList(); | 2202 .toList(); |
| 2201 } | 2203 } |
| 2202 | 2204 |
| 2203 Map toMap() => { | 2205 Map toMap() => { |
| 2204 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, | 2206 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, |
| 2205 'parameters': parameters | 2207 'parameters': parameters |
| 2206 }; | 2208 }; |
| 2207 } | 2209 } |
| OLD | NEW |