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

Side by Side Diff: pkg/analysis_server/lib/src/resource.dart

Issue 300043009: Use Posix style for memory resources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove casting 'posix' to Context Created 6 years, 7 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
« no previous file with comments | « no previous file | pkg/pkg.status » ('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 resource; 5 library resource;
6 6
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 8
9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
10 import 'package:analyzer/src/generated/java_io.dart'; 10 import 'package:analyzer/src/generated/java_io.dart';
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 @override 93 @override
94 bool get exists => _provider._pathToResource.containsKey(_path); 94 bool get exists => _provider._pathToResource.containsKey(_path);
95 95
96 @override 96 @override
97 String get fullName => _path; 97 String get fullName => _path;
98 98
99 @override 99 @override
100 get hashCode => _path.hashCode; 100 get hashCode => _path.hashCode;
101 101
102 @override 102 @override
103 String get shortName => basename(_path); 103 String get shortName => posix.basename(_path);
104 104
105 @override 105 @override
106 String toString() => fullName; 106 String toString() => fullName;
107 } 107 }
108 108
109 109
110 /** 110 /**
111 * An in-memory implementation of [File]. 111 * An in-memory implementation of [File].
112 */ 112 */
113 class _MemoryFile extends _MemoryResource implements File { 113 class _MemoryFile extends _MemoryResource implements File {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 String get fullName => _file.fullName; 174 String get fullName => _file.fullName;
175 175
176 @override 176 @override
177 bool get isInSystemLibrary => false; 177 bool get isInSystemLibrary => false;
178 178
179 @override 179 @override
180 int get modificationStamp => _file._timestamp; 180 int get modificationStamp => _file._timestamp;
181 181
182 @override 182 @override
183 Source resolveRelative(Uri relativeUri) { 183 Source resolveRelative(Uri relativeUri) {
184 String relativePath = fromUri(relativeUri); 184 String relativePath = posix.fromUri(relativeUri);
185 String folderPath = dirname(_file._path); 185 String folderPath = posix.dirname(_file._path);
186 String path = join(folderPath, relativePath); 186 String path = posix.join(folderPath, relativePath);
187 path = normalize(path); 187 path = posix.normalize(path);
188 _MemoryFile file = new _MemoryFile(_file._provider, path); 188 _MemoryFile file = new _MemoryFile(_file._provider, path);
189 return new _MemoryFileSource(file, uriKind); 189 return new _MemoryFileSource(file, uriKind);
190 } 190 }
191 191
192 @override 192 @override
193 String get shortName => _file.shortName; 193 String get shortName => _file.shortName;
194 } 194 }
195 195
196 196
197 /** 197 /**
198 * An in-memory implementation of [Folder]. 198 * An in-memory implementation of [Folder].
199 */ 199 */
200 class _MemoryFolder extends _MemoryResource implements Folder { 200 class _MemoryFolder extends _MemoryResource implements Folder {
201 _MemoryFolder(MemoryResourceProvider provider, String path) : 201 _MemoryFolder(MemoryResourceProvider provider, String path) :
202 super(provider, path); 202 super(provider, path);
203 @override 203 @override
204 Resource getChild(String relPath) { 204 Resource getChild(String relPath) {
205 relPath = normalize(relPath); 205 relPath = posix.normalize(relPath);
206 String childPath = join(_path, relPath); 206 String childPath = posix.join(_path, relPath);
207 childPath = normalize(childPath); 207 childPath = posix.normalize(childPath);
208 _MemoryResource resource = _provider._pathToResource[childPath]; 208 _MemoryResource resource = _provider._pathToResource[childPath];
209 if (resource == null) { 209 if (resource == null) {
210 resource = new _MemoryFile(_provider, childPath); 210 resource = new _MemoryFile(_provider, childPath);
211 } 211 }
212 return resource; 212 return resource;
213 } 213 }
214 214
215 @override 215 @override
216 List<Resource> getChildren() { 216 List<Resource> getChildren() {
217 List<Resource> children = <Resource>[]; 217 List<Resource> children = <Resource>[];
218 _provider._pathToResource.forEach((path, resource) { 218 _provider._pathToResource.forEach((path, resource) {
219 if (dirname(path) == _path) { 219 if (posix.dirname(path) == _path) {
220 children.add(resource); 220 children.add(resource);
221 } 221 }
222 }); 222 });
223 return children; 223 return children;
224 } 224 }
225 } 225 }
226 226
227 227
228 /** 228 /**
229 * An in-memory implementation of [ResourceProvider]. 229 * An in-memory implementation of [ResourceProvider].
230 * Use `/` as a path separator. 230 * Use `/` as a path separator.
231 */ 231 */
232 class MemoryResourceProvider implements ResourceProvider { 232 class MemoryResourceProvider implements ResourceProvider {
233 final Map<String, _MemoryResource> _pathToResource = <String, _MemoryResource> {}; 233 final Map<String, _MemoryResource> _pathToResource = <String, _MemoryResource> {};
234 final Map<String, String> _pathToContent = <String, String>{}; 234 final Map<String, String> _pathToContent = <String, String>{};
235 final Map<String, int> _pathToTimestamp = <String, int>{}; 235 final Map<String, int> _pathToTimestamp = <String, int>{};
236 int nextStamp = 0; 236 int nextStamp = 0;
237 237
238 @override 238 @override
239 Resource getResource(String path) { 239 Resource getResource(String path) {
240 path = normalize(path); 240 path = posix.normalize(path);
241 Resource resource = _pathToResource[path]; 241 Resource resource = _pathToResource[path];
242 if (resource == null) { 242 if (resource == null) {
243 resource = new _MemoryFile(this, path); 243 resource = new _MemoryFile(this, path);
244 } 244 }
245 return resource; 245 return resource;
246 } 246 }
247 247
248 Folder newFolder(String path) { 248 Folder newFolder(String path) {
249 path = normalize(path); 249 path = posix.normalize(path);
250 if (path.isEmpty) { 250 if (path.isEmpty) {
251 throw new ArgumentError('Empty paths are not supported'); 251 throw new ArgumentError('Empty paths are not supported');
252 } 252 }
253 if (!path.startsWith('/')) { 253 if (!path.startsWith('/')) {
254 throw new ArgumentError("Path must start with '/'"); 254 throw new ArgumentError("Path must start with '/'");
255 } 255 }
256 _MemoryFolder folder = null; 256 _MemoryFolder folder = null;
257 String partialPath = ""; 257 String partialPath = "";
258 for (String pathPart in path.split('/')) { 258 for (String pathPart in path.split('/')) {
259 if (pathPart.isEmpty) { 259 if (pathPart.isEmpty) {
(...skipping 11 matching lines...) Expand all
271 String message = 'Folder expected at ' 271 String message = 'Folder expected at '
272 "'$partialPath'" 272 "'$partialPath'"
273 'but ${resource.runtimeType} found'; 273 'but ${resource.runtimeType} found';
274 throw new ArgumentError(message); 274 throw new ArgumentError(message);
275 } 275 }
276 } 276 }
277 return folder; 277 return folder;
278 } 278 }
279 279
280 File newFile(String path, String content) { 280 File newFile(String path, String content) {
281 path = normalize(path); 281 path = posix.normalize(path);
282 newFolder(dirname(path)); 282 newFolder(posix.dirname(path));
283 _MemoryFile file = new _MemoryFile(this, path); 283 _MemoryFile file = new _MemoryFile(this, path);
284 _pathToResource[path] = file; 284 _pathToResource[path] = file;
285 _pathToContent[path] = content; 285 _pathToContent[path] = content;
286 _pathToTimestamp[path] = nextStamp++; 286 _pathToTimestamp[path] = nextStamp++;
287 return file; 287 return file;
288 } 288 }
289 } 289 }
290 290
291 291
292 /** 292 /**
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Resource getResource(String path) { 372 Resource getResource(String path) {
373 if (io.FileSystemEntity.isDirectorySync(path)) { 373 if (io.FileSystemEntity.isDirectorySync(path)) {
374 io.Directory directory = new io.Directory(path); 374 io.Directory directory = new io.Directory(path);
375 return new _PhysicalFolder(directory); 375 return new _PhysicalFolder(directory);
376 } else { 376 } else {
377 io.File file = new io.File(path); 377 io.File file = new io.File(path);
378 return new _PhysicalFile(file); 378 return new _PhysicalFile(file);
379 } 379 }
380 } 380 }
381 } 381 }
OLDNEW
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698