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 | |
14 /** | 13 /** |
15 * [File]s are leaf [Resource]s which contain data. | 14 * [File]s are leaf [Resource]s which contain data. |
16 */ | 15 */ |
17 abstract class File extends Resource { | 16 abstract class File extends Resource { |
18 /** | 17 /** |
19 * Return the last-modified stamp of the file. | 18 * Return the last-modified stamp of the file. |
20 * Throws [FileSystemException] if the file does not exist. | 19 * Throws [FileSystemException] if the file does not exist. |
21 */ | 20 */ |
22 int get modificationStamp; | 21 int get modificationStamp; |
23 | 22 |
24 /** | 23 /** |
25 * Create a new [Source] instance that serves this file. | 24 * Create a new [Source] instance that serves this file. |
26 */ | 25 */ |
27 Source createSource([Uri uri]); | 26 Source createSource([Uri uri]); |
28 } | 27 } |
29 | 28 |
30 | |
31 /** | 29 /** |
32 * Base class for all file system exceptions. | 30 * Base class for all file system exceptions. |
33 */ | 31 */ |
34 class FileSystemException implements Exception { | 32 class FileSystemException implements Exception { |
35 final String path; | 33 final String path; |
36 final String message; | 34 final String message; |
37 | 35 |
38 FileSystemException(this.path, this.message); | 36 FileSystemException(this.path, this.message); |
39 | 37 |
40 String toString() => 'FileSystemException(path=$path; message=$message)'; | 38 String toString() => 'FileSystemException(path=$path; message=$message)'; |
41 } | 39 } |
42 | 40 |
43 | |
44 /** | 41 /** |
45 * [Folder]s are [Resource]s which may contain files and/or other folders. | 42 * [Folder]s are [Resource]s which may contain files and/or other folders. |
46 */ | 43 */ |
47 abstract class Folder extends Resource { | 44 abstract class Folder extends Resource { |
48 /** | 45 /** |
49 * Watch for changes to the files inside this folder (and in any nested | 46 * Watch for changes to the files inside this folder (and in any nested |
50 * folders, including folders reachable via links). | 47 * folders, including folders reachable via links). |
51 */ | 48 */ |
52 Stream<WatchEvent> get changes; | 49 Stream<WatchEvent> get changes; |
53 | 50 |
(...skipping 26 matching lines...) Expand all Loading... |
80 | 77 |
81 /** | 78 /** |
82 * Return a [Folder] representing a child [Resource] with the given | 79 * Return a [Folder] representing a child [Resource] with the given |
83 * [relPath]. This call does not check whether a folder with the given name | 80 * [relPath]. This call does not check whether a folder with the given name |
84 * exists on the filesystem--client must call the [Folder]'s `exists` getter | 81 * exists on the filesystem--client must call the [Folder]'s `exists` getter |
85 * to determine whether the folder actually exists. | 82 * to determine whether the folder actually exists. |
86 */ | 83 */ |
87 Folder getChildAssumingFolder(String relPath); | 84 Folder getChildAssumingFolder(String relPath); |
88 } | 85 } |
89 | 86 |
90 | |
91 /** | 87 /** |
92 * The abstract class [Resource] is an abstraction of file or folder. | 88 * The abstract class [Resource] is an abstraction of file or folder. |
93 */ | 89 */ |
94 abstract class Resource { | 90 abstract class Resource { |
95 /** | 91 /** |
96 * Return `true` if this resource exists. | 92 * Return `true` if this resource exists. |
97 */ | 93 */ |
98 bool get exists; | 94 bool get exists; |
99 | 95 |
100 /** | 96 /** |
(...skipping 13 matching lines...) Expand all Loading... |
114 */ | 110 */ |
115 String get shortName; | 111 String get shortName; |
116 | 112 |
117 /** | 113 /** |
118 * Return `true` if absolute [path] references this resource or a resource in | 114 * Return `true` if absolute [path] references this resource or a resource in |
119 * this folder. | 115 * this folder. |
120 */ | 116 */ |
121 bool isOrContains(String path); | 117 bool isOrContains(String path); |
122 } | 118 } |
123 | 119 |
124 | |
125 /** | 120 /** |
126 * Instances of the class [ResourceProvider] convert [String] paths into | 121 * Instances of the class [ResourceProvider] convert [String] paths into |
127 * [Resource]s. | 122 * [Resource]s. |
128 */ | 123 */ |
129 abstract class ResourceProvider { | 124 abstract class ResourceProvider { |
130 /** | 125 /** |
131 * Get the path context used by this resource provider. | 126 * Get the path context used by this resource provider. |
132 */ | 127 */ |
133 Context get pathContext; | 128 Context get pathContext; |
134 | 129 |
135 /** | 130 /** |
136 * Return the [Resource] that corresponds to the given [path]. | 131 * Return the [Resource] that corresponds to the given [path]. |
137 */ | 132 */ |
138 Resource getResource(String path); | 133 Resource getResource(String path); |
139 | 134 |
140 /** | 135 /** |
141 * Return the folder in which the plugin with the given [pluginId] can store | 136 * Return the folder in which the plugin with the given [pluginId] can store |
142 * state that will persist across sessions. The folder returned for a given id | 137 * state that will persist across sessions. The folder returned for a given id |
143 * will not be returned for a different id, ensuring that plugins do not need | 138 * will not be returned for a different id, ensuring that plugins do not need |
144 * to be concerned with file name collisions with other plugins, assuming that | 139 * to be concerned with file name collisions with other plugins, assuming that |
145 * the plugin ids are unique. The plugin ids must be valid folder names. | 140 * the plugin ids are unique. The plugin ids must be valid folder names. |
146 */ | 141 */ |
147 Folder getStateLocation(String pluginId); | 142 Folder getStateLocation(String pluginId); |
148 } | 143 } |
149 | 144 |
150 | |
151 /** | 145 /** |
152 * A [UriResolver] for [Resource]s. | 146 * A [UriResolver] for [Resource]s. |
153 */ | 147 */ |
154 class ResourceUriResolver extends UriResolver { | 148 class ResourceUriResolver extends UriResolver { |
155 /** | 149 /** |
156 * The name of the `file` scheme. | 150 * The name of the `file` scheme. |
157 */ | 151 */ |
158 static String _FILE_SCHEME = "file"; | 152 static String _FILE_SCHEME = "file"; |
159 | 153 |
160 final ResourceProvider _provider; | 154 final ResourceProvider _provider; |
(...skipping 17 matching lines...) Expand all Loading... |
178 Uri restoreAbsolute(Source source) => source.uri; | 172 Uri restoreAbsolute(Source source) => source.uri; |
179 | 173 |
180 /** | 174 /** |
181 * Return `true` if the given URI is a `file` URI. | 175 * Return `true` if the given URI is a `file` URI. |
182 * | 176 * |
183 * @param uri the URI being tested | 177 * @param uri the URI being tested |
184 * @return `true` if the given URI is a `file` URI | 178 * @return `true` if the given URI is a `file` URI |
185 */ | 179 */ |
186 static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | 180 static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
187 } | 181 } |
OLD | NEW |