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

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

Issue 179093002: Only find package directory for things underneath lib (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months 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 /// **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 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 /// If no package could be determined, we return an empty string. 1416 /// If no package could be determined, we return an empty string.
1417 String _findPackage(LibraryMirror mirror) { 1417 String _findPackage(LibraryMirror mirror) {
1418 if (mirror == null) return ''; 1418 if (mirror == null) return '';
1419 if (_hasBeenCheckedForPackage) return packageName; 1419 if (_hasBeenCheckedForPackage) return packageName;
1420 _hasBeenCheckedForPackage = true; 1420 _hasBeenCheckedForPackage = true;
1421 if (mirror.uri.scheme != 'file') return ''; 1421 if (mirror.uri.scheme != 'file') return '';
1422 packageName = _packageName(mirror); 1422 packageName = _packageName(mirror);
1423 // Associate the package readme with all the libraries. This is a bit 1423 // Associate the package readme with all the libraries. This is a bit
1424 // wasteful, but easier than trying to figure out which partial match 1424 // wasteful, but easier than trying to figure out which partial match
1425 // is best. 1425 // is best.
1426 packageIntro = _packageIntro(_getRootdir(mirror)); 1426 packageIntro = _packageIntro(_getPackageDirectory(mirror));
1427 return packageName; 1427 return packageName;
1428 } 1428 }
1429 1429
1430 String _packageIntro(packageDir) { 1430 String _packageIntro(packageDir) {
1431 if (packageDir == null) return null; 1431 if (packageDir == null) return null;
1432 var dir = new Directory(packageDir); 1432 var dir = new Directory(packageDir);
1433 var files = dir.listSync(); 1433 var files = dir.listSync();
1434 var readmes = files.where((FileSystemEntity each) => (each is File && 1434 var readmes = files.where((FileSystemEntity each) => (each is File &&
1435 each.path.substring(packageDir.length + 1, each.path.length) 1435 each.path.substring(packageDir.length + 1, each.path.length)
1436 .startsWith('README'))).toList(); 1436 .startsWith('README'))).toList();
1437 if (readmes.isEmpty) return ''; 1437 if (readmes.isEmpty) return '';
1438 // If there are multiples, pick the shortest name. 1438 // If there are multiples, pick the shortest name.
1439 readmes.sort((a, b) => a.path.length.compareTo(b.path.length)); 1439 readmes.sort((a, b) => a.path.length.compareTo(b.path.length));
1440 var readme = readmes.first; 1440 var readme = readmes.first;
1441 var linkResolver = (name) => Indexable.globalFixReference(name); 1441 var linkResolver = (name) => Indexable.globalFixReference(name);
1442 var contents = markdown.markdownToHtml(readme 1442 var contents = markdown.markdownToHtml(readme
1443 .readAsStringSync(), linkResolver: linkResolver, 1443 .readAsStringSync(), linkResolver: linkResolver,
1444 inlineSyntaxes: _MARKDOWN_SYNTAXES); 1444 inlineSyntaxes: _MARKDOWN_SYNTAXES);
1445 return contents; 1445 return contents;
1446 } 1446 }
1447 1447
1448 /// Given a LibraryMirror that is a library, return the name of the directory 1448 /// Given a LibraryMirror that is a library, return the name of the directory
1449 /// holding the package information for that library. If the library is not 1449 /// holding the package information for that library. If the library is not
1450 /// part of a package, return null. 1450 /// part of a package, return null.
1451 static String _getRootdir(LibraryMirror mirror) { 1451 static String _getPackageDirectory(LibraryMirror mirror) {
1452 var file = mirror.uri.toFilePath(); 1452 var file = mirror.uri.toFilePath();
1453 // Any file that's in a package will be in a directory of the form 1453 // Any file that's in a package will be in a directory of the form
1454 // packagename/lib/.../filename.dart, so we know that a possible 1454 // packagename/lib/.../filename.dart, so we know that a possible
1455 // package directory is at least in the directory above the one containing 1455 // package directory is at least in the directory above the one containing
1456 // [file] 1456 // [file]
1457 var directoryAbove = path.dirname(path.dirname(file)); 1457 var directoryAbove = path.dirname(path.dirname(file));
1458 return _packageDirectoryFor(directoryAbove); 1458 var possiblePackage = _packageDirectoryFor(directoryAbove);
1459 // We only want components that are somewhere underneath the lib directory.
1460 var subPath = path.relative(file, from: possiblePackage);
1461 var subPathComponents = path.split(subPath);
1462 if (subPathComponents.isNotEmpty && subPathComponents.first == 'lib') {
1463 return possiblePackage;
1464 } else {
1465 return null;
1466 }
1459 } 1467 }
1460 1468
1461 /// Read a pubspec and return the library name given a [LibraryMirror]. 1469 /// Read a pubspec and return the library name given a [LibraryMirror].
1462 static String _packageName(LibraryMirror mirror) { 1470 static String _packageName(LibraryMirror mirror) {
1463 if (mirror.uri.scheme != 'file') return ''; 1471 if (mirror.uri.scheme != 'file') return '';
1464 var rootdir = _getRootdir(mirror); 1472 var rootdir = _getPackageDirectory(mirror);
1465 if (rootdir == null) return ''; 1473 if (rootdir == null) return '';
1466 return packageNameFor(rootdir); 1474 return packageNameFor(rootdir);
1467 } 1475 }
1468 1476
1469 /// Recursively walk up from directory name looking for a pubspec. Return 1477 /// Recursively walk up from directory name looking for a pubspec. Return
1470 /// the directory that contains it, or null if none is found. 1478 /// the directory that contains it, or null if none is found.
1471 static String _packageDirectoryFor(String directoryName) { 1479 static String _packageDirectoryFor(String directoryName) {
1472 var dir = directoryName; 1480 var dir = directoryName;
1473 while (!_pubspecFor(dir).existsSync()) { 1481 while (!_pubspecFor(dir).existsSync()) {
1474 var newDir = path.dirname(dir); 1482 var newDir = path.dirname(dir);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 .map((e) => originalMirror.getField(e.simpleName).reflectee) 2261 .map((e) => originalMirror.getField(e.simpleName).reflectee)
2254 .where((e) => e != null) 2262 .where((e) => e != null)
2255 .toList(); 2263 .toList();
2256 } 2264 }
2257 2265
2258 Map toMap() => { 2266 Map toMap() => {
2259 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, 2267 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName,
2260 'parameters': parameters 2268 'parameters': parameters
2261 }; 2269 };
2262 } 2270 }
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