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