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

Side by Side Diff: pkg/analysis_server/test/mock_sdk.dart

Issue 2653753006: Fix MockSdk.fromFileUri() implementations. (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/analyzer/test/src/context/mock_sdk.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 testing.mock_sdk; 5 library testing.mock_sdk;
6 6
7 import 'package:analyzer/file_system/file_system.dart' as resource; 7 import 'package:analyzer/file_system/file_system.dart' as resource;
8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; 8 import 'package:analyzer/file_system/memory_file_system.dart' as resource;
9 import 'package:analyzer/src/context/context.dart'; 9 import 'package:analyzer/src/context/context.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 List<String> get uris { 327 List<String> get uris {
328 List<String> uris = <String>[]; 328 List<String> uris = <String>[];
329 for (SdkLibrary library in LIBRARIES) { 329 for (SdkLibrary library in LIBRARIES) {
330 uris.add(library.shortName); 330 uris.add(library.shortName);
331 } 331 }
332 return uris; 332 return uris;
333 } 333 }
334 334
335 @override 335 @override
336 Source fromFileUri(Uri uri) { 336 Source fromFileUri(Uri uri) {
337 String filePath = uri.path; 337 String filePath = provider.pathContext.fromUri(uri);
338 String libPath = '/lib'; 338 for (SdkLibrary library in sdkLibraries) {
339 if (!filePath.startsWith("$libPath/")) { 339 String libraryPath = provider.convertPath(library.path);
340 return null; 340 if (filePath == libraryPath) {
341 }
342 for (SdkLibrary library in LIBRARIES) {
343 String libraryPath = library.path;
344 if (filePath.replaceAll('\\', '/') == libraryPath) {
345 try { 341 try {
346 resource.File file = provider.getResource(uri.path); 342 resource.File file = provider.getResource(filePath);
347 Uri dartUri = Uri.parse(library.shortName); 343 Uri dartUri = Uri.parse(library.shortName);
348 return file.createSource(dartUri); 344 return file.createSource(dartUri);
349 } catch (exception) { 345 } catch (exception) {
350 return null; 346 return null;
351 } 347 }
352 } 348 }
353 if (filePath.startsWith("$libraryPath/")) { 349 String libraryRootPath = provider.pathContext.dirname(libraryPath) +
354 String pathInLibrary = filePath.substring(libraryPath.length + 1); 350 provider.pathContext.separator;
355 String path = '${library.shortName}/$pathInLibrary'; 351 if (filePath.startsWith(libraryRootPath)) {
352 String pathInLibrary = filePath.substring(libraryRootPath.length);
353 String uriStr = '${library.shortName}/$pathInLibrary';
356 try { 354 try {
357 resource.File file = provider.getResource(uri.path); 355 resource.File file = provider.getResource(filePath);
358 Uri dartUri = new Uri(scheme: 'dart', path: path); 356 Uri dartUri = Uri.parse(uriStr);
359 return file.createSource(dartUri); 357 return file.createSource(dartUri);
360 } catch (exception) { 358 } catch (exception) {
361 return null; 359 return null;
362 } 360 }
363 } 361 }
364 } 362 }
365 return null; 363 return null;
366 } 364 }
367 365
368 @override 366 @override
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 bool get isInternal => shortName.startsWith('dart:_'); 447 bool get isInternal => shortName.startsWith('dart:_');
450 448
451 @override 449 @override
452 bool get isShared => throw unimplemented; 450 bool get isShared => throw unimplemented;
453 451
454 @override 452 @override
455 bool get isVmLibrary => throw unimplemented; 453 bool get isVmLibrary => throw unimplemented;
456 454
457 UnimplementedError get unimplemented => new UnimplementedError(); 455 UnimplementedError get unimplemented => new UnimplementedError();
458 } 456 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/mock_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698