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

Side by Side Diff: pkg/front_end/lib/physical_file_system.dart

Issue 2622423003: Simplify PhysicalFileSystem implementation. (Closed)
Patch Set: Created 3 years, 11 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/front_end/test/physical_file_system_test.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 front_end.physical_file_system; 5 library front_end.physical_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 10 matching lines...) Expand all
21 PhysicalFileSystem._(); 21 PhysicalFileSystem._();
22 22
23 @override 23 @override
24 p.Context get context => p.context; 24 p.Context get context => p.context;
25 25
26 @override 26 @override
27 FileSystemEntity entityForUri(Uri uri) { 27 FileSystemEntity entityForUri(Uri uri) {
28 if (uri.scheme != 'file' && uri.scheme != '') { 28 if (uri.scheme != 'file' && uri.scheme != '') {
29 throw new ArgumentError('File URI expected'); 29 throw new ArgumentError('File URI expected');
30 } 30 }
31 // Note: we don't have to verify that the URI's path is absolute, because 31 return new _PhysicalFileSystemEntity(Uri.base.resolveUri(uri));
32 // URIs with non-empty schemes always have absolute paths.
33 var path = context.fromUri(uri);
34 return new _PhysicalFileSystemEntity(
35 context.normalize(context.absolute(path)));
36 } 32 }
37 } 33 }
38 34
39 /// Concrete implementation of [FileSystemEntity] for use by 35 /// Concrete implementation of [FileSystemEntity] for use by
40 /// [PhysicalFileSystem]. 36 /// [PhysicalFileSystem].
41 class _PhysicalFileSystemEntity implements FileSystemEntity { 37 class _PhysicalFileSystemEntity implements FileSystemEntity {
42 final String _path; 38 @override
39 final Uri uri;
43 40
44 _PhysicalFileSystemEntity(this._path); 41 _PhysicalFileSystemEntity(this.uri);
45 42
46 @override 43 @override
47 int get hashCode => _path.hashCode; 44 int get hashCode => uri.hashCode;
48
49 @override
50 Uri get uri => p.toUri(_path);
51 45
52 @override 46 @override
53 bool operator ==(Object other) => 47 bool operator ==(Object other) =>
54 other is _PhysicalFileSystemEntity && other._path == _path; 48 other is _PhysicalFileSystemEntity && other.uri == uri;
55 49
56 @override 50 @override
57 Future<List<int>> readAsBytes() => new io.File(_path).readAsBytes(); 51 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes();
58 52
59 @override 53 @override
60 Future<String> readAsString() => new io.File(_path).readAsString(); 54 Future<String> readAsString() => new io.File.fromUri(uri).readAsString();
61 } 55 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/test/physical_file_system_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698