| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library file_system; | 5 library file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:path/path.dart'; | 10 import 'package:path/path.dart'; |
| 11 import 'package:watcher/watcher.dart'; | 11 import 'package:watcher/watcher.dart'; |
| 12 | 12 |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * [File]s are leaf [Resource]s which contain data. | 15 * [File]s are leaf [Resource]s which contain data. |
| 16 */ | 16 */ |
| 17 abstract class File extends Resource { | 17 abstract class File extends Resource { |
| 18 /** | 18 /** |
| 19 * Create a new [Source] instance that serves this file. | 19 * Create a new [Source] instance that serves this file. |
| 20 */ | 20 */ |
| 21 Source createSource(UriKind uriKind); | 21 Source createSource([Uri uri]); |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * [Folder]s are [Resource]s which may contain files and/or other folders. | 26 * [Folder]s are [Resource]s which may contain files and/or other folders. |
| 27 */ | 27 */ |
| 28 abstract class Folder extends Resource { | 28 abstract class Folder extends Resource { |
| 29 /** | 29 /** |
| 30 * Watch for changes to the files inside this folder (and in any nested | 30 * Watch for changes to the files inside this folder (and in any nested |
| 31 * folders, including folders reachable via links). | 31 * folders, including folders reachable via links). |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 /** | 108 /** |
| 109 * The name of the `file` scheme. | 109 * The name of the `file` scheme. |
| 110 */ | 110 */ |
| 111 static String _FILE_SCHEME = "file"; | 111 static String _FILE_SCHEME = "file"; |
| 112 | 112 |
| 113 final ResourceProvider _provider; | 113 final ResourceProvider _provider; |
| 114 | 114 |
| 115 ResourceUriResolver(this._provider); | 115 ResourceUriResolver(this._provider); |
| 116 | 116 |
| 117 @override | 117 @override |
| 118 Source fromEncoding(UriKind kind, Uri uri) { | |
| 119 if (kind == UriKind.FILE_URI) { | |
| 120 Resource resource = _provider.getResource(uri.path); | |
| 121 if (resource is File) { | |
| 122 return resource.createSource(kind); | |
| 123 } | |
| 124 } | |
| 125 return null; | |
| 126 } | |
| 127 | |
| 128 @override | |
| 129 Source resolveAbsolute(Uri uri) { | 118 Source resolveAbsolute(Uri uri) { |
| 130 if (!_isFileUri(uri)) { | 119 if (!_isFileUri(uri)) { |
| 131 return null; | 120 return null; |
| 132 } | 121 } |
| 133 Resource resource = _provider.getResource(uri.path); | 122 Resource resource = _provider.getResource(uri.path); |
| 134 if (resource is File) { | 123 if (resource is File) { |
| 135 return resource.createSource(UriKind.FILE_URI); | 124 return resource.createSource(uri); |
| 136 } | 125 } |
| 137 return null; | 126 return null; |
| 138 } | 127 } |
| 139 | 128 |
| 140 /** | 129 /** |
| 141 * Return `true` if the given URI is a `file` URI. | 130 * Return `true` if the given URI is a `file` URI. |
| 142 * | 131 * |
| 143 * @param uri the URI being tested | 132 * @param uri the URI being tested |
| 144 * @return `true` if the given URI is a `file` URI | 133 * @return `true` if the given URI is a `file` URI |
| 145 */ | 134 */ |
| 146 static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | 135 static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
| 147 } | 136 } |
| OLD | NEW |