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

Side by Side Diff: pkg/analyzer/test/src/context/mock_sdk.dart

Issue 2542853003: Create summary files in MockSdk classes (Closed)
Patch Set: Created 4 years 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
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 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
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 dartAsync: true, resource.MemoryResourceProvider resourceProvider}) 354 {bool buildSummaries: true,
355 bool dartAsync: true,
356 resource.MemoryResourceProvider resourceProvider})
355 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), 357 : provider = resourceProvider ?? new resource.MemoryResourceProvider(),
356 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], 358 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE],
357 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { 359 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP {
358 for (_MockSdkLibrary library in sdkLibraries) { 360 for (_MockSdkLibrary library in sdkLibraries) {
359 provider.newFile(provider.convertPath(library.path), library.content); 361 provider.newFile(provider.convertPath(library.path), library.content);
360 library.parts.forEach((String path, String content) { 362 library.parts.forEach((String path, String content) {
361 provider.newFile(provider.convertPath(path), content); 363 provider.newFile(provider.convertPath(path), content);
362 }); 364 });
363 } 365 }
364 provider.newFile( 366 provider.newFile(
365 provider.convertPath( 367 provider.convertPath(
366 '$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'), 368 '$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'),
367 librariesContent); 369 librariesContent);
370 if (buildSummaries) {
371 List<int> bytes = _computeLinkedBundleBytes();
372 provider.newFileWithBytes(
373 provider.convertPath('/lib/_internal/spec.sum'), bytes);
374 provider.newFileWithBytes(
375 provider.convertPath('/lib/_internal/strong.sum'), bytes);
376 }
368 } 377 }
369 378
370 @override 379 @override
371 AnalysisContextImpl get context { 380 AnalysisContextImpl get context {
372 if (_analysisContext == null) { 381 if (_analysisContext == null) {
373 _analysisContext = new _SdkAnalysisContext(this); 382 _analysisContext = new _SdkAnalysisContext(this);
374 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); 383 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]);
375 _analysisContext.sourceFactory = factory; 384 _analysisContext.sourceFactory = factory;
376 } 385 }
377 return _analysisContext; 386 return _analysisContext;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return null; 424 return null;
416 } 425 }
417 } 426 }
418 } 427 }
419 return null; 428 return null;
420 } 429 }
421 430
422 @override 431 @override
423 PackageBundle getLinkedBundle() { 432 PackageBundle getLinkedBundle() {
424 if (_bundle == null) { 433 if (_bundle == null) {
425 List<Source> librarySources = sdkLibraries 434 _bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes());
426 .map((SdkLibrary library) => mapDartUri(library.shortName))
427 .toList();
428 List<int> bytes = new SummaryBuilder(
429 librarySources, context, context.analysisOptions.strongMode)
430 .build();
431 _bundle = new PackageBundle.fromBuffer(bytes);
432 } 435 }
433 return _bundle; 436 return _bundle;
434 } 437 }
435 438
436 @override 439 @override
437 SdkLibrary getSdkLibrary(String dartUri) { 440 SdkLibrary getSdkLibrary(String dartUri) {
438 // getSdkLibrary() is only used to determine whether a library is internal 441 // getSdkLibrary() is only used to determine whether a library is internal
439 // to the SDK. The mock SDK doesn't have any internals, so it's safe to 442 // to the SDK. The mock SDK doesn't have any internals, so it's safe to
440 // return null. 443 // return null.
441 return null; 444 return null;
(...skipping 18 matching lines...) Expand all
460 */ 463 */
461 void updateUriFile(String uri, String updateContent(String content)) { 464 void updateUriFile(String uri, String updateContent(String content)) {
462 assert(_analysisContext == null); 465 assert(_analysisContext == null);
463 String path = FULL_URI_MAP[uri]; 466 String path = FULL_URI_MAP[uri];
464 assert(path != null); 467 assert(path != null);
465 path = provider.convertPath(path); 468 path = provider.convertPath(path);
466 String content = provider.getFile(path).readAsStringSync(); 469 String content = provider.getFile(path).readAsStringSync();
467 String newContent = updateContent(content); 470 String newContent = updateContent(content);
468 provider.updateFile(path, newContent); 471 provider.updateFile(path, newContent);
469 } 472 }
473
474 /**
475 * Compute the bytes in the linked bundle associated with this SDK.
scheglov 2016/12/02 01:15:52 "in the" -> "of the"?
Brian Wilkerson 2016/12/02 15:32:04 Done
476 */
477 List<int> _computeLinkedBundleBytes() {
478 List<Source> librarySources = sdkLibraries
479 .map((SdkLibrary library) => mapDartUri(library.shortName))
480 .toList();
481 return new SummaryBuilder(
482 librarySources, context, context.analysisOptions.strongMode)
483 .build();
484 }
470 } 485 }
471 486
472 class _MockSdkLibrary implements SdkLibrary { 487 class _MockSdkLibrary implements SdkLibrary {
473 final String shortName; 488 final String shortName;
474 final String path; 489 final String path;
475 final String content; 490 final String content;
476 final Map<String, String> parts; 491 final Map<String, String> parts;
477 492
478 const _MockSdkLibrary(this.shortName, this.path, this.content, 493 const _MockSdkLibrary(this.shortName, this.path, this.content,
479 [this.parts = const <String, String>{}]); 494 [this.parts = const <String, String>{}]);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 528
514 @override 529 @override
515 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 530 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
516 if (factory == null) { 531 if (factory == null) {
517 return super.createCacheFromSourceFactory(factory); 532 return super.createCacheFromSourceFactory(factory);
518 } 533 }
519 return new AnalysisCache( 534 return new AnalysisCache(
520 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 535 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
521 } 536 }
522 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698