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

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

Issue 351813002: A local file-based Index implementation. (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
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 0c8f8021075e00a6baf5dfa81a562f2bb279280d..7cc6469c85899f1a34ce6737a4e0106e67f4aeb0 100644
--- a/pkg/analysis_server/lib/src/resource.dart
+++ b/pkg/analysis_server/lib/src/resource.dart
@@ -459,3 +459,49 @@ class PhysicalResourceProvider implements ResourceProvider {
@override
Context get pathContext => io.Platform.isWindows ? windows : posix;
}
+
+
+/**
+ * A [UriResolver] for [Resource]s.
+ */
+class ResourceUriResolver extends UriResolver {
+ /**
+ * The name of the `file` scheme.
+ */
+ static String _FILE_SCHEME = "file";
+
+ final MemoryResourceProvider _provider;
Paul Berry 2014/06/24 15:49:59 It doesn't look like we're making use of any funct
scheglov 2014/06/24 18:07:46 Done.
+
+ ResourceUriResolver(this._provider);
+
+ @override
+ Source fromEncoding(UriKind kind, Uri uri) {
+ if (kind == UriKind.FILE_URI) {
+ Resource resource = _provider.getResource(uri.path);
+ if (resource is File) {
+ return resource.createSource(kind);
+ }
+ }
+ return null;
+ }
+
+ @override
+ Source resolveAbsolute(Uri uri) {
+ if (!_isFileUri(uri)) {
+ return null;
+ }
+ Resource resource = _provider.getResource(uri.path);
+ if (resource is File) {
+ return resource.createSource(UriKind.FILE_URI);
+ }
+ return null;
+ }
+
+ /**
+ * Return `true` if the given URI is a `file` URI.
+ *
+ * @param uri the URI being tested
+ * @return `true` if the given URI is a `file` URI
+ */
+ static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME;
+}

Powered by Google App Engine
This is Rietveld 408576698