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

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

Issue 1444943003: Use AbsolutePathContext in Folder.contains(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
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 physical_file_system; 5 library physical_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
11 import 'package:analyzer/src/generated/java_io.dart'; 11 import 'package:analyzer/src/generated/java_io.dart';
12 import 'package:analyzer/src/generated/source_io.dart'; 12 import 'package:analyzer/src/generated/source_io.dart';
13 import 'package:analyzer/src/util/absolute_path.dart';
13 import 'package:path/path.dart'; 14 import 'package:path/path.dart';
14 import 'package:watcher/watcher.dart'; 15 import 'package:watcher/watcher.dart';
15 16
16 import 'file_system.dart'; 17 import 'file_system.dart';
17 18
18 /** 19 /**
19 * A `dart:io` based implementation of [ResourceProvider]. 20 * A `dart:io` based implementation of [ResourceProvider].
20 */ 21 */
21 class PhysicalResourceProvider implements ResourceProvider { 22 class PhysicalResourceProvider implements ResourceProvider {
22 static final NORMALIZE_EOL_ALWAYS = (String string) => 23 static final NORMALIZE_EOL_ALWAYS = (String string) =>
23 string.replaceAll(new RegExp('\r\n?'), '\n'); 24 string.replaceAll(new RegExp('\r\n?'), '\n');
24 25
25 static final PhysicalResourceProvider INSTANCE = 26 static final PhysicalResourceProvider INSTANCE =
26 new PhysicalResourceProvider(null); 27 new PhysicalResourceProvider(null);
27 28
28 /** 29 /**
29 * The name of the directory containing plugin specific subfolders used to 30 * The name of the directory containing plugin specific subfolders used to
30 * store data across sessions. 31 * store data across sessions.
31 */ 32 */
32 static final String SERVER_DIR = ".dartServer"; 33 static final String SERVER_DIR = ".dartServer";
33 34
35 final AbsolutePathContext absolutePathContext =
36 new AbsolutePathContext(io.Platform.pathSeparator);
37
34 PhysicalResourceProvider(String fileReadMode(String s)) { 38 PhysicalResourceProvider(String fileReadMode(String s)) {
35 if (fileReadMode != null) { 39 if (fileReadMode != null) {
36 FileBasedSource.fileReadMode = fileReadMode; 40 FileBasedSource.fileReadMode = fileReadMode;
37 } 41 }
38 } 42 }
39 43
40 @override 44 @override
41 Context get pathContext => io.Platform.isWindows ? windows : posix; 45 Context get pathContext => io.Platform.isWindows ? windows : posix;
42 46
43 @override 47 @override
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 * A `dart:io` based implementation of [Folder]. 126 * A `dart:io` based implementation of [Folder].
123 */ 127 */
124 class _PhysicalFolder extends _PhysicalResource implements Folder { 128 class _PhysicalFolder extends _PhysicalResource implements Folder {
125 _PhysicalFolder(io.Directory directory) : super(directory); 129 _PhysicalFolder(io.Directory directory) : super(directory);
126 130
127 @override 131 @override
128 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events; 132 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events;
129 133
130 @override 134 @override
131 String canonicalizePath(String relPath) { 135 String canonicalizePath(String relPath) {
132 return normalize(join(_entry.absolute.path, relPath)); 136 return normalize(join(path, relPath));
133 } 137 }
134 138
135 @override 139 @override
136 bool contains(String path) { 140 bool contains(String path) {
137 return isWithin(this.path, path); 141 return absolutePathContext.isWithin(this.path, path);
138 } 142 }
139 143
140 @override 144 @override
141 Resource getChild(String relPath) { 145 Resource getChild(String relPath) {
142 String canonicalPath = canonicalizePath(relPath); 146 String canonicalPath = canonicalizePath(relPath);
143 return PhysicalResourceProvider.INSTANCE.getResource(canonicalPath); 147 return PhysicalResourceProvider.INSTANCE.getResource(canonicalPath);
144 } 148 }
145 149
146 @override 150 @override
147 _PhysicalFolder getChildAssumingFolder(String relPath) { 151 _PhysicalFolder getChildAssumingFolder(String relPath) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 185 }
182 186
183 /** 187 /**
184 * A `dart:io` based implementation of [Resource]. 188 * A `dart:io` based implementation of [Resource].
185 */ 189 */
186 abstract class _PhysicalResource implements Resource { 190 abstract class _PhysicalResource implements Resource {
187 final io.FileSystemEntity _entry; 191 final io.FileSystemEntity _entry;
188 192
189 _PhysicalResource(this._entry); 193 _PhysicalResource(this._entry);
190 194
195 AbsolutePathContext get absolutePathContext =>
196 PhysicalResourceProvider.INSTANCE.absolutePathContext;
197
191 @override 198 @override
192 bool get exists => _entry.existsSync(); 199 bool get exists => _entry.existsSync();
193 200
194 @override 201 @override
195 get hashCode => path.hashCode; 202 get hashCode => path.hashCode;
196 203
197 @override 204 @override
198 Folder get parent { 205 Folder get parent {
199 String parentPath = dirname(path); 206 String parentPath = absolutePathContext.dirname(path);
200 if (parentPath == path) { 207 if (parentPath == path) {
201 return null; 208 return null;
202 } 209 }
203 return new _PhysicalFolder(new io.Directory(parentPath)); 210 return new _PhysicalFolder(new io.Directory(parentPath));
204 } 211 }
205 212
206 @override 213 @override
207 String get path => _entry.absolute.path; 214 String get path => _entry.absolute.path;
208 215
209 @override 216 @override
210 String get shortName => basename(path); 217 String get shortName => absolutePathContext.basename(path);
211 218
212 @override 219 @override
213 bool operator ==(other) { 220 bool operator ==(other) {
214 if (runtimeType != other.runtimeType) { 221 if (runtimeType != other.runtimeType) {
215 return false; 222 return false;
216 } 223 }
217 return path == other.path; 224 return path == other.path;
218 } 225 }
219 226
220 @override 227 @override
221 String toString() => path; 228 String toString() => path;
222 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698