| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Common logic needed to provide a Dart SDK to the analyzer's resolver. This | 5 /// Common logic needed to provide a Dart SDK to the analyzer's resolver. This |
| 6 /// includes logic to determine where the sdk is located in the filesystem, and | 6 /// includes logic to determine where the sdk is located in the filesystem, and |
| 7 /// definitions to provide mock sdks. | 7 /// definitions to provide mock sdks. |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisContext, TimestampedData; | 10 show AnalysisContext, AnalysisEngine, TimestampedData; |
| 11 import 'package:analyzer/src/generated/sdk.dart'; | 11 import 'package:analyzer/src/generated/sdk.dart' |
| 12 import 'package:analyzer/src/generated/source.dart'; | 12 show DartSdk, SdkLibrary, SdkLibraryImpl; |
| 13 import 'package:analyzer/src/context/context.dart'; | 13 import 'package:analyzer/src/generated/source.dart' |
| 14 show DartUriResolver, Source, SourceFactory, UriKind; |
| 15 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; |
| 16 import 'package:analyzer/src/context/cache.dart' |
| 17 show AnalysisCache, CachePartition; |
| 14 | 18 |
| 15 /// Dart SDK which contains a mock implementation of the SDK libraries. May be | 19 /// Dart SDK which contains a mock implementation of the SDK libraries. May be |
| 16 /// used to speed up execution when most of the core libraries is not needed. | 20 /// used to speed up execution when most of the core libraries is not needed. |
| 17 class MockDartSdk implements DartSdk { | 21 class MockDartSdk implements DartSdk { |
| 18 final Map<Uri, _MockSdkSource> _sources = {}; | 22 final Map<Uri, _MockSdkSource> _sources = {}; |
| 19 final bool reportMissing; | 23 final bool reportMissing; |
| 20 final Map<String, SdkLibrary> _libs = {}; | 24 final Map<String, SdkLibrary> _libs = {}; |
| 21 final String sdkVersion = '0'; | 25 final String sdkVersion = '0'; |
| 22 List<String> get uris => _sources.keys.map((uri) => '$uri').toList(); | 26 List<String> get uris => _sources.keys.map((uri) => '$uri').toList(); |
| 23 final AnalysisContext context = new SdkAnalysisContext(null); | 27 AnalysisContext context; |
| 24 DartUriResolver _resolver; | 28 DartUriResolver _resolver; |
| 25 DartUriResolver get resolver => _resolver; | 29 DartUriResolver get resolver => _resolver; |
| 26 | 30 |
| 27 MockDartSdk(Map<String, String> sources, {this.reportMissing}) { | 31 MockDartSdk(Map<String, String> sources, {this.reportMissing}) { |
| 32 context = new _SdkAnalysisContext(this); |
| 28 sources.forEach((uriString, contents) { | 33 sources.forEach((uriString, contents) { |
| 29 var uri = Uri.parse(uriString); | 34 var uri = Uri.parse(uriString); |
| 30 _sources[uri] = new _MockSdkSource(uri, contents); | 35 _sources[uri] = new _MockSdkSource(uri, contents); |
| 31 _libs[uriString] = new SdkLibraryImpl(uri.path) | 36 _libs[uriString] = new SdkLibraryImpl(uri.path) |
| 32 ..setDart2JsLibrary() | 37 ..setDart2JsLibrary() |
| 33 ..setVmLibrary(); | 38 ..setVmLibrary(); |
| 34 }); | 39 }); |
| 35 _resolver = new DartUriResolver(this); | 40 _resolver = new DartUriResolver(this); |
| 36 context.sourceFactory = new SourceFactory([_resolver]); | 41 context.sourceFactory = new SourceFactory([_resolver]); |
| 37 } | 42 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ''', | 178 ''', |
| 174 'dart:math': ''' | 179 'dart:math': ''' |
| 175 library dart.math; | 180 library dart.math; |
| 176 class Random { | 181 class Random { |
| 177 bool nextBool() {} | 182 bool nextBool() {} |
| 178 } | 183 } |
| 179 num min(num x, num y) {} | 184 num min(num x, num y) {} |
| 180 num max(num x, num y) {} | 185 num max(num x, num y) {} |
| 181 ''', | 186 ''', |
| 182 }; | 187 }; |
| 188 |
| 189 /// An [AnalysisContextImpl] that only contains sources for a Dart SDK. |
| 190 class _SdkAnalysisContext extends AnalysisContextImpl { |
| 191 final DartSdk sdk; |
| 192 |
| 193 _SdkAnalysisContext(this.sdk); |
| 194 |
| 195 @override |
| 196 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 197 if (factory == null) { |
| 198 return super.createCacheFromSourceFactory(factory); |
| 199 } |
| 200 return new AnalysisCache( |
| 201 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
| 202 } |
| 203 } |
| OLD | NEW |