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

Unified Diff: pkg/analysis_server/lib/src/resource.dart

Issue 355453005: Add a Resource.parent getter, which gets the parent directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | pkg/analysis_server/test/physical_resource_provider_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/resource.dart
diff --git a/pkg/analysis_server/lib/src/resource.dart b/pkg/analysis_server/lib/src/resource.dart
index 5659eb61c1488bb72736d75285ece5ad97c5479b..c7f41a1c2bd1361996da1c77700b8f29030ba635 100644
--- a/pkg/analysis_server/lib/src/resource.dart
+++ b/pkg/analysis_server/lib/src/resource.dart
@@ -69,6 +69,12 @@ abstract class Resource {
* denote this resource.
*/
String get shortName;
+
+ /**
+ * Return the [Folder] that contains this resource, or null if this resource
scheglov 2014/06/25 21:44:25 `null` ? "is a root folder" ?
Paul Berry 2014/06/26 15:03:08 Done.
+ * is a root directory.
+ */
+ Folder get parent;
}
@@ -114,6 +120,15 @@ abstract class _MemoryResource implements Resource {
@override
String toString() => path;
+
+ @override
+ Folder get parent {
+ String parentPath = posix.dirname(path);
+ if (parentPath == path) {
+ return null;
+ }
+ return _provider.getResource(parentPath);
+ }
}
@@ -290,28 +305,24 @@ class MemoryResourceProvider implements ResourceProvider {
if (!path.startsWith('/')) {
throw new ArgumentError("Path must start with '/'");
}
- _MemoryFolder folder = null;
- String partialPath = "";
- for (String pathPart in path.split('/')) {
- if (pathPart.isEmpty) {
- continue;
- }
- partialPath += '/' + pathPart;
- _MemoryResource resource = _pathToResource[partialPath];
- if (resource == null) {
- folder = new _MemoryFolder(this, partialPath);
- _pathToResource[partialPath] = folder;
- _pathToTimestamp[partialPath] = nextStamp++;
- } else if (resource is _MemoryFolder) {
- folder = resource;
- } else {
- String message = 'Folder expected at '
- "'$partialPath'"
- 'but ${resource.runtimeType} found';
- throw new ArgumentError(message);
+ _MemoryResource resource = _pathToResource[path];
+ if (resource == null) {
+ String parentPath = posix.dirname(path);
+ if (parentPath != path) {
+ newFolder(parentPath);
}
+ _MemoryFolder folder = new _MemoryFolder(this, path);
+ _pathToResource[path] = folder;
+ _pathToTimestamp[path] = nextStamp++;
+ return folder;
+ } else if (resource is _MemoryFolder) {
+ return resource;
+ } else {
+ String message = 'Folder expected at '
+ "'$path'"
+ 'but ${resource.runtimeType} found';
+ throw new ArgumentError(message);
}
- return folder;
}
File newFile(String path, String content) {
@@ -434,6 +445,15 @@ abstract class _PhysicalResource implements Resource {
@override
String toString() => path;
+
+ @override
+ Folder get parent {
+ String parentPath = dirname(path);
+ if (parentPath == path) {
+ return null;
+ }
+ return new _PhysicalFolder(new io.Directory(parentPath));
+ }
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/physical_resource_provider_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698