OLD | NEW |
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.test.src.context.mock_sdk; | 5 library analyzer.test.src.context.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/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
10 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 478 |
479 @override | 479 @override |
480 String get sdkVersion => throw new UnimplementedError(); | 480 String get sdkVersion => throw new UnimplementedError(); |
481 | 481 |
482 @override | 482 @override |
483 List<String> get uris => | 483 List<String> get uris => |
484 sdkLibraries.map((SdkLibrary library) => library.shortName).toList(); | 484 sdkLibraries.map((SdkLibrary library) => library.shortName).toList(); |
485 | 485 |
486 @override | 486 @override |
487 Source fromFileUri(Uri uri) { | 487 Source fromFileUri(Uri uri) { |
488 String filePath = uri.path; | 488 String filePath = provider.pathContext.fromUri(uri); |
489 String libPath = '$sdkRoot/lib'; | 489 if (!filePath.startsWith(provider.convertPath('$sdkRoot/lib/'))) { |
490 if (!filePath.startsWith("$libPath/")) { | |
491 return null; | 490 return null; |
492 } | 491 } |
493 for (SdkLibrary library in sdkLibraries) { | 492 for (SdkLibrary library in sdkLibraries) { |
494 String libraryPath = library.path; | 493 String libraryPath = provider.convertPath(library.path); |
495 if (filePath.replaceAll('\\', '/') == libraryPath) { | 494 if (filePath == libraryPath) { |
496 try { | 495 try { |
497 resource.File file = | 496 resource.File file = provider.getResource(filePath); |
498 provider.getResource(provider.convertPath(filePath)); | |
499 Uri dartUri = Uri.parse(library.shortName); | 497 Uri dartUri = Uri.parse(library.shortName); |
500 return file.createSource(dartUri); | 498 return file.createSource(dartUri); |
501 } catch (exception) { | 499 } catch (exception) { |
502 return null; | 500 return null; |
503 } | 501 } |
504 } | 502 } |
505 if (filePath.startsWith("$libraryPath/")) { | 503 String libraryRootPath = provider.pathContext.dirname(libraryPath) + |
506 String pathInLibrary = filePath.substring(libraryPath.length + 1); | 504 provider.pathContext.separator; |
507 String path = '${library.shortName}/$pathInLibrary'; | 505 if (filePath.startsWith(libraryRootPath)) { |
| 506 String pathInLibrary = filePath.substring(libraryRootPath.length); |
| 507 String uriStr = '${library.shortName}/$pathInLibrary'; |
508 try { | 508 try { |
509 resource.File file = | 509 resource.File file = provider.getResource(filePath); |
510 provider.getResource(provider.convertPath(filePath)); | 510 Uri dartUri = Uri.parse(uriStr); |
511 Uri dartUri = new Uri(scheme: 'dart', path: path); | |
512 return file.createSource(dartUri); | 511 return file.createSource(dartUri); |
513 } catch (exception) { | 512 } catch (exception) { |
514 return null; | 513 return null; |
515 } | 514 } |
516 } | 515 } |
517 } | 516 } |
518 return null; | 517 return null; |
519 } | 518 } |
520 | 519 |
521 @override | 520 @override |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 624 |
626 @override | 625 @override |
627 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 626 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
628 if (factory == null) { | 627 if (factory == null) { |
629 return super.createCacheFromSourceFactory(factory); | 628 return super.createCacheFromSourceFactory(factory); |
630 } | 629 } |
631 return new AnalysisCache( | 630 return new AnalysisCache( |
632 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 631 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
633 } | 632 } |
634 } | 633 } |
OLD | NEW |