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 /** | 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 /** | 243 /** |
244 * Analyzes set of libraries by getting a mirror system and triggers the | 244 * Analyzes set of libraries by getting a mirror system and triggers the |
245 * documentation of the libraries. | 245 * documentation of the libraries. |
246 */ | 246 */ |
247 Future<MirrorSystem> getMirrorSystem(List<String> args, {String packageRoot, | 247 Future<MirrorSystem> getMirrorSystem(List<String> args, {String packageRoot, |
248 bool parseSdk: false}) { | 248 bool parseSdk: false}) { |
249 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); | 249 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); |
250 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 250 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
251 // Finds the root of SDK library based off the location of docgen. | 251 // Finds the root of SDK library based off the location of docgen. |
252 var sdkRoot = path.join(path.dirname(path.dirname(path.dirname(path.dirname( | 252 var sdkRoot = Platform.script.resolve('../../../sdk').toFilePath(); |
253 path.absolute(Platform.script))))), 'sdk'); | |
254 logger.info('SDK Root: ${sdkRoot}'); | 253 logger.info('SDK Root: ${sdkRoot}'); |
255 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); | 254 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); |
256 } | 255 } |
257 | 256 |
258 /** | 257 /** |
259 * Analyzes set of libraries and provides a mirror system which can be used | 258 * Analyzes set of libraries and provides a mirror system which can be used |
260 * for static inspection of the source code. | 259 * for static inspection of the source code. |
261 */ | 260 */ |
262 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, | 261 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, |
263 String libraryRoot, {String packageRoot}) { | 262 String libraryRoot, {String packageRoot}) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return commentText; | 471 return commentText; |
473 } | 472 } |
474 | 473 |
475 /** | 474 /** |
476 * Generates MDN comments from database.json. | 475 * Generates MDN comments from database.json. |
477 */ | 476 */ |
478 void _mdnComment(Indexable item) { | 477 void _mdnComment(Indexable item) { |
479 //Check if MDN is loaded. | 478 //Check if MDN is loaded. |
480 if (_mdn == null) { | 479 if (_mdn == null) { |
481 // Reading in MDN related json file. | 480 // Reading in MDN related json file. |
482 var mdnDir = path.join(path.dirname(path.dirname(path.dirname(path.dirname( | 481 var mdnDatabase = |
483 path.absolute(Platform.script))))), 'utils', 'apidoc', 'mdn'); | 482 Platform.script.resolve('../../../utils/apidoc/mdn/database.json'); |
484 _mdn = JSON.decode(new File(path.join(mdnDir, 'database.json')) | 483 _mdn = JSON.decode(new File(mdnDatabase.toFilePath()).readAsStringSync()); |
485 .readAsStringSync()); | |
486 } | 484 } |
487 if (item.comment.isNotEmpty) return; | 485 if (item.comment.isNotEmpty) return; |
488 var domAnnotation = item.annotations.firstWhere( | 486 var domAnnotation = item.annotations.firstWhere( |
489 (e) => e.qualifiedName == 'metadata.DomName', orElse: () => null); | 487 (e) => e.qualifiedName == 'metadata.DomName', orElse: () => null); |
490 if (domAnnotation == null) return; | 488 if (domAnnotation == null) return; |
491 var domName = domAnnotation.parameters.single; | 489 var domName = domAnnotation.parameters.single; |
492 var parts = domName.split('.'); | 490 var parts = domName.split('.'); |
493 if (parts.length == 2) item.comment = _mdnMemberComment(parts[0], parts[1]); | 491 if (parts.length == 2) item.comment = _mdnMemberComment(parts[0], parts[1]); |
494 if (parts.length == 1) item.comment = _mdnTypeComment(parts[0]); | 492 if (parts.length == 1) item.comment = _mdnTypeComment(parts[0]); |
495 } | 493 } |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 String docName(DeclarationMirror m) { | 1315 String docName(DeclarationMirror m) { |
1318 if (m is LibraryMirror) { | 1316 if (m is LibraryMirror) { |
1319 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); | 1317 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); |
1320 } | 1318 } |
1321 var owner = m.owner; | 1319 var owner = m.owner; |
1322 if (owner == null) return m.qualifiedName; | 1320 if (owner == null) return m.qualifiedName; |
1323 // For the unnamed constructor we just return the class name. | 1321 // For the unnamed constructor we just return the class name. |
1324 if (m.simpleName == '') return docName(owner); | 1322 if (m.simpleName == '') return docName(owner); |
1325 return docName(owner) + '.' + m.simpleName; | 1323 return docName(owner) + '.' + m.simpleName; |
1326 } | 1324 } |
OLD | NEW |