Chromium Code Reviews| 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 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 /** | 267 /** |
| 268 * The cached linked bundle of the SDK. | 268 * The cached linked bundle of the SDK. |
| 269 */ | 269 */ |
| 270 PackageBundle _bundle; | 270 PackageBundle _bundle; |
| 271 | 271 |
| 272 MockSdk({resource.ResourceProvider resourceProvider}) | 272 MockSdk({resource.ResourceProvider resourceProvider}) |
| 273 : provider = resourceProvider ?? new resource.MemoryResourceProvider() { | 273 : provider = resourceProvider ?? new resource.MemoryResourceProvider() { |
| 274 LIBRARIES.forEach((SdkLibrary library) { | 274 LIBRARIES.forEach((SdkLibrary library) { |
| 275 provider.newFile(library.path, (library as MockSdkLibrary).content); | 275 provider.newFile(library.path, (library as MockSdkLibrary).content); |
| 276 }); | 276 }); |
| 277 provider.newFile('/lib/_internal/sdk_library_metadata/lib/libraries.dart', | 277 provider.newFile( |
| 278 provider.convertPath( | |
| 279 '/lib/_internal/sdk_library_metadata/lib/libraries.dart'), | |
| 278 librariesContent); | 280 librariesContent); |
| 281 List<int> bytes = _computeLinkedBundleBytes(); | |
| 282 provider.newFileWithBytes( | |
| 283 provider.convertPath('/lib/_internal/spec.sum'), bytes); | |
| 284 provider.newFileWithBytes( | |
| 285 provider.convertPath('/lib/_internal/strong.sum'), bytes); | |
| 279 } | 286 } |
| 280 | 287 |
| 281 @override | 288 @override |
| 282 AnalysisContext get context { | 289 AnalysisContext get context { |
| 283 if (_analysisContext == null) { | 290 if (_analysisContext == null) { |
| 284 _analysisContext = new SdkAnalysisContext(null); | 291 _analysisContext = new SdkAnalysisContext(null); |
| 285 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 292 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 286 _analysisContext.sourceFactory = factory; | 293 _analysisContext.sourceFactory = factory; |
| 287 } | 294 } |
| 288 return _analysisContext; | 295 return _analysisContext; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 return null; | 341 return null; |
| 335 } | 342 } |
| 336 } | 343 } |
| 337 } | 344 } |
| 338 return null; | 345 return null; |
| 339 } | 346 } |
| 340 | 347 |
| 341 @override | 348 @override |
| 342 PackageBundle getLinkedBundle() { | 349 PackageBundle getLinkedBundle() { |
| 343 if (_bundle == null) { | 350 if (_bundle == null) { |
| 344 List<Source> librarySources = sdkLibraries | 351 _bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes()); |
|
scheglov
2016/12/02 01:15:52
If we already have these bytes in the file system,
Brian Wilkerson
2016/12/02 15:32:04
Probably so, but when I tried to use the stored by
| |
| 345 .map((SdkLibrary library) => mapDartUri(library.shortName)) | |
| 346 .toList(); | |
| 347 List<int> bytes = new SummaryBuilder( | |
| 348 librarySources, context, context.analysisOptions.strongMode) | |
| 349 .build(); | |
| 350 _bundle = new PackageBundle.fromBuffer(bytes); | |
| 351 } | 352 } |
| 352 return _bundle; | 353 return _bundle; |
| 353 } | 354 } |
| 354 | 355 |
| 355 @override | 356 @override |
| 356 SdkLibrary getSdkLibrary(String dartUri) { | 357 SdkLibrary getSdkLibrary(String dartUri) { |
| 357 // getSdkLibrary() is only used to determine whether a library is internal | 358 // getSdkLibrary() is only used to determine whether a library is internal |
| 358 // to the SDK. The mock SDK doesn't have any internals, so it's safe to | 359 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 359 // return null. | 360 // return null. |
| 360 return null; | 361 return null; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 376 if (path != null) { | 377 if (path != null) { |
| 377 resource.File file = provider.getResource(path); | 378 resource.File file = provider.getResource(path); |
| 378 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); | 379 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); |
| 379 return file.createSource(uri); | 380 return file.createSource(uri); |
| 380 } | 381 } |
| 381 | 382 |
| 382 // If we reach here then we tried to use a dartUri that's not in the | 383 // If we reach here then we tried to use a dartUri that's not in the |
| 383 // table above. | 384 // table above. |
| 384 return null; | 385 return null; |
| 385 } | 386 } |
| 387 | |
| 388 /** | |
| 389 * Compute the bytes in the linked bundle associated with this SDK. | |
| 390 */ | |
| 391 List<int> _computeLinkedBundleBytes() { | |
| 392 List<Source> librarySources = sdkLibraries | |
| 393 .map((SdkLibrary library) => mapDartUri(library.shortName)) | |
| 394 .toList(); | |
| 395 return new SummaryBuilder( | |
| 396 librarySources, context, context.analysisOptions.strongMode) | |
| 397 .build(); | |
| 398 } | |
| 386 } | 399 } |
| 387 | 400 |
| 388 class MockSdkLibrary implements SdkLibrary { | 401 class MockSdkLibrary implements SdkLibrary { |
| 389 final String shortName; | 402 final String shortName; |
| 390 final String path; | 403 final String path; |
| 391 final String content; | 404 final String content; |
| 392 | 405 |
| 393 const MockSdkLibrary(this.shortName, this.path, this.content); | 406 const MockSdkLibrary(this.shortName, this.path, this.content); |
| 394 | 407 |
| 395 @override | 408 @override |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 411 bool get isShared => throw unimplemented; | 424 bool get isShared => throw unimplemented; |
| 412 | 425 |
| 413 @override | 426 @override |
| 414 bool get isVmLibrary => throw unimplemented; | 427 bool get isVmLibrary => throw unimplemented; |
| 415 | 428 |
| 416 UnimplementedError get unimplemented => new UnimplementedError(); | 429 UnimplementedError get unimplemented => new UnimplementedError(); |
| 417 | 430 |
| 418 @override | 431 @override |
| 419 List<String> getPatches(int platform) => const <String>[]; | 432 List<String> getPatches(int platform) => const <String>[]; |
| 420 } | 433 } |
| OLD | NEW |