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 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'; |
| 11 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; | 11 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; |
| 12 import 'package:analyzer/src/generated/sdk.dart'; | 12 import 'package:analyzer/src/generated/sdk.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 | 14 |
| 15 const String librariesContent = r''' | |
| 16 const Map<String, LibraryInfo> libraries = const { | |
| 17 "async": const LibraryInfo("async/async.dart"), | |
| 18 "collection": const LibraryInfo("collection/collection.dart"), | |
| 19 "convert": const LibraryInfo("convert/convert.dart"), | |
| 20 "core": const LibraryInfo("core/core.dart"), | |
| 21 "html": const LibraryInfo("html/dartium/html_dartium.dart"), | |
| 22 "math": const LibraryInfo("math/math.dart"), | |
| 23 "_foreign_helper": const LibraryInfo("_internal/js_runtime/lib/foreign_helper. dart"), | |
| 24 }; | |
| 25 '''; | |
| 26 | |
| 15 const _MockSdkLibrary _LIB_ASYNC = const _MockSdkLibrary( | 27 const _MockSdkLibrary _LIB_ASYNC = const _MockSdkLibrary( |
| 16 'dart:async', | 28 'dart:async', |
| 17 '/lib/async/async.dart', | 29 '/lib/async/async.dart', |
|
scheglov
2016/08/10 21:25:43
We might want to use different paths for SDK files
Brian Wilkerson
2016/08/10 21:41:32
I thought about that, then forgot. Done.
| |
| 18 ''' | 30 ''' |
| 19 library dart.async; | 31 library dart.async; |
| 20 | 32 |
| 21 import 'dart:math'; | 33 import 'dart:math'; |
| 22 | 34 |
| 23 part 'stream.dart'; | 35 part 'stream.dart'; |
| 24 | 36 |
| 25 class Future<T> { | 37 class Future<T> { |
| 26 factory Future(computation()) => null; | 38 factory Future(computation()) => null; |
| 27 factory Future.delayed(Duration duration, [T computation()]) => null; | 39 factory Future.delayed(Duration duration, [T computation()]) => null; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 MockSdk({bool dartAsync: true, resource.ResourceProvider resourceProvider}) | 332 MockSdk({bool dartAsync: true, resource.ResourceProvider resourceProvider}) |
| 321 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), | 333 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), |
| 322 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], | 334 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], |
| 323 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { | 335 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { |
| 324 for (_MockSdkLibrary library in sdkLibraries) { | 336 for (_MockSdkLibrary library in sdkLibraries) { |
| 325 provider.newFile(library.path, library.content); | 337 provider.newFile(library.path, library.content); |
| 326 library.parts.forEach((String path, String content) { | 338 library.parts.forEach((String path, String content) { |
| 327 provider.newFile(path, content); | 339 provider.newFile(path, content); |
| 328 }); | 340 }); |
| 329 } | 341 } |
| 342 provider.newFile( | |
| 343 '/_internal/sdk_library_metadata/lib/libraries.dart', librariesContent); | |
| 330 } | 344 } |
| 331 | 345 |
| 332 @override | 346 @override |
| 333 AnalysisContextImpl get context { | 347 AnalysisContextImpl get context { |
| 334 if (_analysisContext == null) { | 348 if (_analysisContext == null) { |
| 335 _analysisContext = new _SdkAnalysisContext(this); | 349 _analysisContext = new _SdkAnalysisContext(this); |
| 336 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 350 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 337 _analysisContext.sourceFactory = factory; | 351 _analysisContext.sourceFactory = factory; |
| 338 } | 352 } |
| 339 return _analysisContext; | 353 return _analysisContext; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 | 457 |
| 444 @override | 458 @override |
| 445 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 459 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 446 if (factory == null) { | 460 if (factory == null) { |
| 447 return super.createCacheFromSourceFactory(factory); | 461 return super.createCacheFromSourceFactory(factory); |
| 448 } | 462 } |
| 449 return new AnalysisCache( | 463 return new AnalysisCache( |
| 450 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 464 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
| 451 } | 465 } |
| 452 } | 466 } |
| OLD | NEW |