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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index de033962e63e15cd642110f03fa24582ffea722a..efe5ce589eac2cf814731596d5e4cc8406d7a2ff 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -1423,7 +1423,7 @@ class Library extends Indexable {
// Associate the package readme with all the libraries. This is a bit
// wasteful, but easier than trying to figure out which partial match
// is best.
- packageIntro = _packageIntro(_getRootdir(mirror));
+ packageIntro = _packageIntro(_getPackageDirectory(mirror));
return packageName;
}
@@ -1446,22 +1446,30 @@ class Library extends Indexable {
}
/// Given a LibraryMirror that is a library, return the name of the directory
- /// holding the package information for that library. If the library is not
+ /// holding the package information for that library. If the library is not
/// part of a package, return null.
- static String _getRootdir(LibraryMirror mirror) {
+ static String _getPackageDirectory(LibraryMirror mirror) {
var file = mirror.uri.toFilePath();
- // Any file that's in a package will be in a directory of the form
+ // Any file that's in a package will be in a directory of the form
// packagename/lib/.../filename.dart, so we know that a possible
// package directory is at least in the directory above the one containing
// [file]
var directoryAbove = path.dirname(path.dirname(file));
- return _packageDirectoryFor(directoryAbove);
+ var possiblePackage = _packageDirectoryFor(directoryAbove);
+ // We only want components that are somewhere underneath the lib directory.
+ var subPath = path.relative(file, from: possiblePackage);
+ var subPathComponents = path.split(subPath);
+ if (subPathComponents.isNotEmpty && subPathComponents.first == 'lib') {
+ return possiblePackage;
+ } else {
+ return null;
+ }
}
/// Read a pubspec and return the library name given a [LibraryMirror].
static String _packageName(LibraryMirror mirror) {
if (mirror.uri.scheme != 'file') return '';
- var rootdir = _getRootdir(mirror);
+ var rootdir = _getPackageDirectory(mirror);
if (rootdir == null) return '';
return packageNameFor(rootdir);
}
« 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