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

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

Issue 2242963002: Add DartSdk.getLinkedBundle() and use it in PubSummaryManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
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/dart/element/element.dart' show LibraryElement;
7 import 'package:analyzer/file_system/file_system.dart' as resource; 8 import 'package:analyzer/file_system/file_system.dart' as resource;
8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; 9 import 'package:analyzer/file_system/memory_file_system.dart' as resource;
9 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/context/context.dart'; 11 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; 12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
12 import 'package:analyzer/src/generated/sdk.dart'; 13 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
15 import 'package:analyzer/src/summary/idl.dart' show PackageBundle;
16 import 'package:analyzer/src/summary/summarize_elements.dart'
17 show PackageBundleAssembler;
14 18
15 const String librariesContent = r''' 19 const String librariesContent = r'''
16 const Map<String, LibraryInfo> libraries = const { 20 const Map<String, LibraryInfo> libraries = const {
17 "async": const LibraryInfo("async/async.dart"), 21 "async": const LibraryInfo("async/async.dart"),
18 "collection": const LibraryInfo("collection/collection.dart"), 22 "collection": const LibraryInfo("collection/collection.dart"),
19 "convert": const LibraryInfo("convert/convert.dart"), 23 "convert": const LibraryInfo("convert/convert.dart"),
20 "core": const LibraryInfo("core/core.dart"), 24 "core": const LibraryInfo("core/core.dart"),
21 "html": const LibraryInfo("html/dartium/html_dartium.dart"), 25 "html": const LibraryInfo("html/dartium/html_dartium.dart"),
22 "math": const LibraryInfo("math/math.dart"), 26 "math": const LibraryInfo("math/math.dart"),
23 "_foreign_helper": const LibraryInfo("_internal/js_runtime/lib/foreign_helper. dart"), 27 "_foreign_helper": const LibraryInfo("_internal/js_runtime/lib/foreign_helper. dart"),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 final Map<String, String> uriMap; 328 final Map<String, String> uriMap;
325 329
326 /** 330 /**
327 * The [AnalysisContextImpl] which is used for all of the sources. 331 * The [AnalysisContextImpl] which is used for all of the sources.
328 */ 332 */
329 AnalysisContextImpl _analysisContext; 333 AnalysisContextImpl _analysisContext;
330 334
331 @override 335 @override
332 final List<SdkLibrary> sdkLibraries; 336 final List<SdkLibrary> sdkLibraries;
333 337
338 /**
339 * The cached linked bundle of the SDK.
340 */
341 PackageBundle _bundle;
342
334 MockSdk({bool dartAsync: true, resource.ResourceProvider resourceProvider}) 343 MockSdk({bool dartAsync: true, resource.ResourceProvider resourceProvider})
335 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), 344 : provider = resourceProvider ?? new resource.MemoryResourceProvider(),
336 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], 345 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE],
337 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { 346 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP {
338 for (_MockSdkLibrary library in sdkLibraries) { 347 for (_MockSdkLibrary library in sdkLibraries) {
339 provider.newFile(library.path, library.content); 348 provider.newFile(library.path, library.content);
340 library.parts.forEach((String path, String content) { 349 library.parts.forEach((String path, String content) {
341 provider.newFile(path, content); 350 provider.newFile(path, content);
342 }); 351 });
343 } 352 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return file.createSource(dartUri); 398 return file.createSource(dartUri);
390 } catch (exception) { 399 } catch (exception) {
391 return null; 400 return null;
392 } 401 }
393 } 402 }
394 } 403 }
395 return null; 404 return null;
396 } 405 }
397 406
398 @override 407 @override
408 PackageBundle getLinkedBundle() {
409 if (_bundle == null) {
410 PackageBundleAssembler assembler = new PackageBundleAssembler();
411 for (SdkLibrary sdkLibrary in sdkLibraries) {
412 String uriStr = sdkLibrary.shortName;
413 Source source = mapDartUri(uriStr);
414 LibraryElement libraryElement = context.computeLibraryElement(source);
415 assembler.serializeLibraryElement(libraryElement);
416 }
417 List<int> bytes = assembler.assemble().toBuffer();
418 _bundle = new PackageBundle.fromBuffer(bytes);
419 }
420 return _bundle;
421 }
422
423 @override
399 SdkLibrary getSdkLibrary(String dartUri) { 424 SdkLibrary getSdkLibrary(String dartUri) {
400 // getSdkLibrary() is only used to determine whether a library is internal 425 // getSdkLibrary() is only used to determine whether a library is internal
401 // to the SDK. The mock SDK doesn't have any internals, so it's safe to 426 // to the SDK. The mock SDK doesn't have any internals, so it's safe to
402 // return null. 427 // return null.
403 return null; 428 return null;
404 } 429 }
405 430
406 @override 431 @override
407 Source mapDartUri(String dartUri) { 432 Source mapDartUri(String dartUri) {
408 String path = uriMap[dartUri]; 433 String path = uriMap[dartUri];
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 484
460 @override 485 @override
461 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 486 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
462 if (factory == null) { 487 if (factory == null) {
463 return super.createCacheFromSourceFactory(factory); 488 return super.createCacheFromSourceFactory(factory);
464 } 489 }
465 return new AnalysisCache( 490 return new AnalysisCache(
466 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 491 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
467 } 492 }
468 } 493 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summary_sdk.dart ('k') | pkg/analyzer/test/src/summary/pub_summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698