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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 @override | 345 @override |
346 final List<SdkLibrary> sdkLibraries; | 346 final List<SdkLibrary> sdkLibraries; |
347 | 347 |
348 /** | 348 /** |
349 * The cached linked bundle of the SDK. | 349 * The cached linked bundle of the SDK. |
350 */ | 350 */ |
351 PackageBundle _bundle; | 351 PackageBundle _bundle; |
352 | 352 |
353 MockSdk( | 353 MockSdk( |
354 {bool buildSummaries: true, | 354 {bool generateSummaryFiles: false, |
355 bool dartAsync: true, | 355 bool dartAsync: true, |
356 resource.MemoryResourceProvider resourceProvider}) | 356 resource.MemoryResourceProvider resourceProvider}) |
357 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), | 357 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), |
358 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], | 358 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], |
359 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { | 359 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { |
360 for (_MockSdkLibrary library in sdkLibraries) { | 360 for (_MockSdkLibrary library in sdkLibraries) { |
361 provider.newFile(provider.convertPath(library.path), library.content); | 361 provider.newFile(provider.convertPath(library.path), library.content); |
362 library.parts.forEach((String path, String content) { | 362 library.parts.forEach((String path, String content) { |
363 provider.newFile(provider.convertPath(path), content); | 363 provider.newFile(provider.convertPath(path), content); |
364 }); | 364 }); |
365 } | 365 } |
366 provider.newFile( | 366 provider.newFile( |
367 provider.convertPath( | 367 provider.convertPath( |
368 '$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'), | 368 '$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'), |
369 librariesContent); | 369 librariesContent); |
370 if (buildSummaries) { | 370 if (generateSummaryFiles) { |
371 List<int> bytes = _computeLinkedBundleBytes(); | 371 List<int> bytes = _computeLinkedBundleBytes(); |
372 provider.newFileWithBytes( | 372 provider.newFileWithBytes( |
373 provider.convertPath('/lib/_internal/spec.sum'), bytes); | 373 provider.convertPath('/lib/_internal/spec.sum'), bytes); |
374 provider.newFileWithBytes( | 374 provider.newFileWithBytes( |
375 provider.convertPath('/lib/_internal/strong.sum'), bytes); | 375 provider.convertPath('/lib/_internal/strong.sum'), bytes); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 @override | 379 @override |
380 AnalysisContextImpl get context { | 380 AnalysisContextImpl get context { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 return null; | 424 return null; |
425 } | 425 } |
426 } | 426 } |
427 } | 427 } |
428 return null; | 428 return null; |
429 } | 429 } |
430 | 430 |
431 @override | 431 @override |
432 PackageBundle getLinkedBundle() { | 432 PackageBundle getLinkedBundle() { |
433 if (_bundle == null) { | 433 if (_bundle == null) { |
434 _bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes()); | 434 resource.File summaryFile = |
| 435 provider.getFile(provider.convertPath('/lib/_internal/spec.sum')); |
| 436 List<int> bytes; |
| 437 if (summaryFile.exists) { |
| 438 bytes = summaryFile.readAsBytesSync(); |
| 439 } else { |
| 440 bytes = _computeLinkedBundleBytes(); |
| 441 } |
| 442 _bundle = new PackageBundle.fromBuffer(bytes); |
435 } | 443 } |
436 return _bundle; | 444 return _bundle; |
437 } | 445 } |
438 | 446 |
439 @override | 447 @override |
440 SdkLibrary getSdkLibrary(String dartUri) { | 448 SdkLibrary getSdkLibrary(String dartUri) { |
441 // getSdkLibrary() is only used to determine whether a library is internal | 449 // getSdkLibrary() is only used to determine whether a library is internal |
442 // to the SDK. The mock SDK doesn't have any internals, so it's safe to | 450 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
443 // return null. | 451 // return null. |
444 return null; | 452 return null; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 536 |
529 @override | 537 @override |
530 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 538 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
531 if (factory == null) { | 539 if (factory == null) { |
532 return super.createCacheFromSourceFactory(factory); | 540 return super.createCacheFromSourceFactory(factory); |
533 } | 541 } |
534 return new AnalysisCache( | 542 return new AnalysisCache( |
535 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 543 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
536 } | 544 } |
537 } | 545 } |
OLD | NEW |