Chromium Code Reviews| 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; |
| +} |