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

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

Issue 2391883002: MemoryResourceProvider always uses the current platform (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/test/embedder_tests.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.file_system.memory_file_system; 5 library analyzer.file_system.memory_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:core'; 10 import 'dart:core';
11 11
12 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/src/generated/source_io.dart'; 13 import 'package:analyzer/src/generated/source_io.dart';
14 import 'package:analyzer/src/source/source_resource.dart'; 14 import 'package:analyzer/src/source/source_resource.dart';
15 import 'package:analyzer/src/util/absolute_path.dart'; 15 import 'package:analyzer/src/util/absolute_path.dart';
16 import 'package:path/path.dart'; 16 import 'package:path/path.dart' as pathos;
17 import 'package:watcher/watcher.dart'; 17 import 'package:watcher/watcher.dart';
18 18
19 /** 19 /**
20 * An in-memory implementation of [ResourceProvider]. 20 * An in-memory implementation of [ResourceProvider].
21 * Use `/` as a path separator. 21 * Use `/` as a path separator.
22 */ 22 */
23 class MemoryResourceProvider implements ResourceProvider { 23 class MemoryResourceProvider implements ResourceProvider {
24 final Map<String, _MemoryResource> _pathToResource = 24 final Map<String, _MemoryResource> _pathToResource =
25 new HashMap<String, _MemoryResource>(); 25 new HashMap<String, _MemoryResource>();
26 final Map<String, List<int>> _pathToBytes = new HashMap<String, List<int>>(); 26 final Map<String, List<int>> _pathToBytes = new HashMap<String, List<int>>();
27 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); 27 final Map<String, int> _pathToTimestamp = new HashMap<String, int>();
28 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = 28 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers =
29 new HashMap<String, List<StreamController<WatchEvent>>>(); 29 new HashMap<String, List<StreamController<WatchEvent>>>();
30 int nextStamp = 0; 30 int nextStamp = 0;
31 31
32 final Context _pathContext; 32 final pathos.Context _pathContext;
33 33
34 @override 34 @override
35 final AbsolutePathContext absolutePathContext; 35 final AbsolutePathContext absolutePathContext;
36 36
37 MemoryResourceProvider({bool isWindows: false}) 37 MemoryResourceProvider({pathos.Context context})
38 : _pathContext = isWindows ? windows : posix, 38 : _pathContext = context ?? pathos.context,
39 absolutePathContext = new AbsolutePathContext(isWindows); 39 absolutePathContext = new AbsolutePathContext(
40 pathos.Style.platform == pathos.Style.windows);
40 41
41 @override 42 @override
42 Context get pathContext => _pathContext; 43 pathos.Context get pathContext => _pathContext;
43 44
44 /** 45 /**
45 * Delete the file with the given path. 46 * Delete the file with the given path.
46 */ 47 */
47 void deleteFile(String path) { 48 void deleteFile(String path) {
48 _checkFileAtPath(path); 49 _checkFileAtPath(path);
49 _pathToResource.remove(path); 50 _pathToResource.remove(path);
50 _pathToBytes.remove(path); 51 _pathToBytes.remove(path);
51 _pathToTimestamp.remove(path); 52 _pathToTimestamp.remove(path);
52 _notifyWatchers(path, ChangeType.REMOVE); 53 _notifyWatchers(path, ChangeType.REMOVE);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 File renameSync(String newPath) { 318 File renameSync(String newPath) {
318 throw new FileSystemException(path, 'File could not be renamed'); 319 throw new FileSystemException(path, 'File could not be renamed');
319 } 320 }
320 321
321 @override 322 @override
322 File resolveSymbolicLinksSync() { 323 File resolveSymbolicLinksSync() {
323 return throw new FileSystemException(path, "File does not exist"); 324 return throw new FileSystemException(path, "File does not exist");
324 } 325 }
325 326
326 @override 327 @override
327 Uri toUri() => new Uri.file(path, windows: _provider.pathContext == windows); 328 Uri toUri() =>
329 new Uri.file(path, windows: _provider.pathContext == pathos.windows);
328 330
329 @override 331 @override
330 void writeAsBytesSync(List<int> bytes) { 332 void writeAsBytesSync(List<int> bytes) {
331 throw new FileSystemException(path, 'File could not be written'); 333 throw new FileSystemException(path, 'File could not be written');
332 } 334 }
333 335
334 @override 336 @override
335 void writeAsStringSync(String content) { 337 void writeAsStringSync(String content) {
336 throw new FileSystemException(path, 'File could not be written'); 338 throw new FileSystemException(path, 'File could not be written');
337 } 339 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 394
393 @override 395 @override
394 File renameSync(String newPath) { 396 File renameSync(String newPath) {
395 return _provider.renameFileSync(this, newPath); 397 return _provider.renameFileSync(this, newPath);
396 } 398 }
397 399
398 @override 400 @override
399 File resolveSymbolicLinksSync() => this; 401 File resolveSymbolicLinksSync() => this;
400 402
401 @override 403 @override
402 Uri toUri() => new Uri.file(path, windows: _provider.pathContext == windows); 404 Uri toUri() =>
405 new Uri.file(path, windows: _provider.pathContext == pathos.windows);
403 406
404 @override 407 @override
405 void writeAsBytesSync(List<int> bytes) { 408 void writeAsBytesSync(List<int> bytes) {
406 _provider._setFileContent(this, bytes); 409 _provider._setFileContent(this, bytes);
407 } 410 }
408 411
409 @override 412 @override
410 void writeAsStringSync(String content) { 413 void writeAsStringSync(String content) {
411 _provider._setFileContent(this, UTF8.encode(content)); 414 _provider._setFileContent(this, UTF8.encode(content));
412 } 415 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return true; 493 return true;
491 } 494 }
492 return contains(path); 495 return contains(path);
493 } 496 }
494 497
495 @override 498 @override
496 Folder resolveSymbolicLinksSync() => this; 499 Folder resolveSymbolicLinksSync() => this;
497 500
498 @override 501 @override
499 Uri toUri() => 502 Uri toUri() =>
500 new Uri.directory(path, windows: _provider.pathContext == windows); 503 new Uri.directory(path, windows: _provider.pathContext == pathos.windows);
501 } 504 }
502 505
503 /** 506 /**
504 * An in-memory implementation of [Resource]. 507 * An in-memory implementation of [Resource].
505 */ 508 */
506 abstract class _MemoryResource implements Resource { 509 abstract class _MemoryResource implements Resource {
507 final MemoryResourceProvider _provider; 510 final MemoryResourceProvider _provider;
508 @override 511 @override
509 final String path; 512 final String path;
510 513
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 bool operator ==(other) { 548 bool operator ==(other) {
546 if (runtimeType != other.runtimeType) { 549 if (runtimeType != other.runtimeType) {
547 return false; 550 return false;
548 } 551 }
549 return path == other.path; 552 return path == other.path;
550 } 553 }
551 554
552 @override 555 @override
553 String toString() => path; 556 String toString() => path;
554 } 557 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/embedder_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698