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

Side by Side Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 428303004: Breaking changes in 'analyzer' package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename Source.resolveRelative to resolveRelativeUri, soften version constraints Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 memory_file_system; 5 library memory_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 @override 153 @override
154 bool get exists => false; 154 bool get exists => false;
155 155
156 String get _content { 156 String get _content {
157 throw new MemoryResourceException(path, "File '$path' could not be read"); 157 throw new MemoryResourceException(path, "File '$path' could not be read");
158 } 158 }
159 159
160 int get _timestamp => _provider._pathToTimestamp[path]; 160 int get _timestamp => _provider._pathToTimestamp[path];
161 161
162 @override 162 @override
163 Source createSource(UriKind uriKind) { 163 Source createSource([Uri uri]) {
164 throw new MemoryResourceException(path, "File '$path' could not be read"); 164 throw new MemoryResourceException(path, "File '$path' could not be read");
165 } 165 }
166 } 166 }
167 167
168 168
169 /** 169 /**
170 * An in-memory implementation of [File]. 170 * An in-memory implementation of [File].
171 */ 171 */
172 class _MemoryFile extends _MemoryResource implements File { 172 class _MemoryFile extends _MemoryResource implements File {
173 _MemoryFile(MemoryResourceProvider provider, String path) : 173 _MemoryFile(MemoryResourceProvider provider, String path) :
174 super(provider, path); 174 super(provider, path);
175 175
176 String get _content { 176 String get _content {
177 String content = _provider._pathToContent[path]; 177 String content = _provider._pathToContent[path];
178 if (content == null) { 178 if (content == null) {
179 throw new MemoryResourceException(path, "File '$path' does not exist"); 179 throw new MemoryResourceException(path, "File '$path' does not exist");
180 } 180 }
181 return content; 181 return content;
182 } 182 }
183 183
184 int get _timestamp => _provider._pathToTimestamp[path]; 184 int get _timestamp => _provider._pathToTimestamp[path];
185 185
186 @override 186 @override
187 Source createSource(UriKind uriKind) { 187 Source createSource([Uri uri]) {
188 return new _MemoryFileSource(this, uriKind); 188 if (uri == null) {
189 uri = toUri(path);
190 }
191 return new _MemoryFileSource(this, uri);
189 } 192 }
190 } 193 }
191 194
192 195
193 /** 196 /**
194 * An in-memory implementation of [Source]. 197 * An in-memory implementation of [Source].
195 */ 198 */
196 class _MemoryFileSource implements Source { 199 class _MemoryFileSource implements Source {
197 final _MemoryFile _file; 200 final _MemoryFile _file;
198 201
199 final UriKind uriKind; 202 final Uri uri;
200 203
201 _MemoryFileSource(this._file, this.uriKind); 204 _MemoryFileSource(this._file, this.uri);
202 205
203 @override 206 @override
204 TimestampedData<String> get contents { 207 TimestampedData<String> get contents {
205 return new TimestampedData<String>(modificationStamp, _file._content); 208 return new TimestampedData<String>(modificationStamp, _file._content);
206 } 209 }
207 210
208 @override 211 @override
209 String get encoding { 212 String get encoding {
210 return '${new String.fromCharCode(uriKind.encoding)}${_file.path}'; 213 return uri.toString();
211 } 214 }
212 215
213 @override 216 @override
214 String get fullName => _file.path; 217 String get fullName => _file.path;
215 218
216 @override 219 @override
217 int get hashCode => _file.hashCode; 220 int get hashCode => _file.hashCode;
218 221
219 @override 222 @override
220 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; 223 bool get isInSystemLibrary => uriKind == UriKind.DART_URI;
221 224
222 @override 225 @override
223 int get modificationStamp => _file._timestamp; 226 int get modificationStamp => _file._timestamp;
224 227
225 @override 228 @override
226 String get shortName => _file.shortName; 229 String get shortName => _file.shortName;
227 230
228 @override 231 @override
232 UriKind get uriKind {
233 String scheme = uri.scheme;
234 if (scheme == PackageUriResolver.PACKAGE_SCHEME) {
235 return UriKind.PACKAGE_URI;
236 } else if (scheme == DartUriResolver.DART_SCHEME) {
237 return UriKind.DART_URI;
238 } else if (scheme == FileUriResolver.FILE_SCHEME) {
239 return UriKind.FILE_URI;
240 }
241 return UriKind.FILE_URI;
242 }
243
244 @override
229 bool operator ==(other) { 245 bool operator ==(other) {
230 if (other is _MemoryFileSource) { 246 if (other is _MemoryFileSource) {
231 return other._file == _file; 247 return other._file == _file;
232 } 248 }
233 return false; 249 return false;
234 } 250 }
235 251
236 @override 252 @override
237 bool exists() => _file.exists; 253 bool exists() => _file.exists;
238 254
239 @override 255 @override
240 Source resolveRelative(Uri relativeUri) { 256 Uri resolveRelativeUri(Uri relativeUri) {
241 String relativePath = posix.fromUri(relativeUri); 257 return uri.resolveUri(relativeUri);
242 String folderPath = posix.dirname(_file.path);
243 String path = posix.join(folderPath, relativePath);
244 path = posix.normalize(path);
245 _MemoryFile file = new _MemoryFile(_file._provider, path);
246 return new _MemoryFileSource(file, uriKind);
247 } 258 }
248 } 259 }
249 260
250 261
251 /** 262 /**
252 * An in-memory implementation of [Folder]. 263 * An in-memory implementation of [Folder].
253 */ 264 */
254 class _MemoryFolder extends _MemoryResource implements Folder { 265 class _MemoryFolder extends _MemoryResource implements Folder {
255 _MemoryFolder(MemoryResourceProvider provider, String path) : 266 _MemoryFolder(MemoryResourceProvider provider, String path) :
256 super(provider, path); 267 super(provider, path);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 bool operator ==(other) { 343 bool operator ==(other) {
333 if (runtimeType != other.runtimeType) { 344 if (runtimeType != other.runtimeType) {
334 return false; 345 return false;
335 } 346 }
336 return path == other.path; 347 return path == other.path;
337 } 348 }
338 349
339 @override 350 @override
340 String toString() => path; 351 String toString() => path;
341 } 352 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/file_system.dart ('k') | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698