Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 55453002: Fixes to find the path after changes to Platform, but now working reliably (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Pulled out into a function Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 scriptDir = path.absolute(path.dirname(Platform.script.toFilePath())); 252
253 var sdkRoot = path.relative('../../../sdk', from: scriptDir); 253 var root = findRootDirectory();
254 sdkRoot = path.normalize(path.absolute(sdkRoot)); 254 var sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk')));
255 logger.info('SDK Root: ${sdkRoot}'); 255 logger.info('SDK Root: ${sdkRoot}');
256 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); 256 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot);
257 } 257 }
258 258
259 String findRootDirectory() {
260 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath()));
261 var root = scriptDir;
262 while(path.basename(root) != 'dart') {
263 root = path.dirname(root);
264 }
265 return root;
266 }
267
259 /** 268 /**
260 * Analyzes set of libraries and provides a mirror system which can be used 269 * Analyzes set of libraries and provides a mirror system which can be used
261 * for static inspection of the source code. 270 * for static inspection of the source code.
262 */ 271 */
263 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, 272 Future<MirrorSystem> _analyzeLibraries(List<String> libraries,
264 String libraryRoot, {String packageRoot}) { 273 String libraryRoot, {String packageRoot}) {
265 SourceFileProvider provider = new CompilerSourceFileProvider(); 274 SourceFileProvider provider = new CompilerSourceFileProvider();
266 api.DiagnosticHandler diagnosticHandler = 275 api.DiagnosticHandler diagnosticHandler =
267 (new FormattingDiagnosticHandler(provider) 276 (new FormattingDiagnosticHandler(provider)
268 ..showHints = false 277 ..showHints = false
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return commentText; 482 return commentText;
474 } 483 }
475 484
476 /** 485 /**
477 * Generates MDN comments from database.json. 486 * Generates MDN comments from database.json.
478 */ 487 */
479 void _mdnComment(Indexable item) { 488 void _mdnComment(Indexable item) {
480 //Check if MDN is loaded. 489 //Check if MDN is loaded.
481 if (_mdn == null) { 490 if (_mdn == null) {
482 // Reading in MDN related json file. 491 // Reading in MDN related json file.
483 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath())); 492 var root = findRootDirectory();
484 var mdnPath = path.relative('../../../utils/apidoc/mdn/database.json', 493 var mdnPath = path.join(root, 'utils/apidoc/mdn/database.json');
485 from: scriptDir);
486 _mdn = JSON.decode(new File(mdnPath).readAsStringSync()); 494 _mdn = JSON.decode(new File(mdnPath).readAsStringSync());
487 } 495 }
488 if (item.comment.isNotEmpty) return; 496 if (item.comment.isNotEmpty) return;
489 var domAnnotation = item.annotations.firstWhere( 497 var domAnnotation = item.annotations.firstWhere(
490 (e) => e.qualifiedName == 'metadata.DomName', orElse: () => null); 498 (e) => e.qualifiedName == 'metadata.DomName', orElse: () => null);
491 if (domAnnotation == null) return; 499 if (domAnnotation == null) return;
492 var domName = domAnnotation.parameters.single; 500 var domName = domAnnotation.parameters.single;
493 var parts = domName.split('.'); 501 var parts = domName.split('.');
494 if (parts.length == 2) item.comment = _mdnMemberComment(parts[0], parts[1]); 502 if (parts.length == 2) item.comment = _mdnMemberComment(parts[0], parts[1]);
495 if (parts.length == 1) item.comment = _mdnTypeComment(parts[0]); 503 if (parts.length == 1) item.comment = _mdnTypeComment(parts[0]);
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 String docName(DeclarationMirror m) { 1326 String docName(DeclarationMirror m) {
1319 if (m is LibraryMirror) { 1327 if (m is LibraryMirror) {
1320 return (m as LibraryMirror).qualifiedName.replaceAll('.','-'); 1328 return (m as LibraryMirror).qualifiedName.replaceAll('.','-');
1321 } 1329 }
1322 var owner = m.owner; 1330 var owner = m.owner;
1323 if (owner == null) return m.qualifiedName; 1331 if (owner == null) return m.qualifiedName;
1324 // For the unnamed constructor we just return the class name. 1332 // For the unnamed constructor we just return the class name.
1325 if (m.simpleName == '') return docName(owner); 1333 if (m.simpleName == '') return docName(owner);
1326 return docName(owner) + '.' + m.simpleName; 1334 return docName(owner) + '.' + m.simpleName;
1327 } 1335 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698