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 test.src.mock_sdk; | 5 library test.src.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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 '''); | 111 '''); |
112 | 112 |
113 static const _MockSdkLibrary LIB_ASYNC = const _MockSdkLibrary( | 113 static const _MockSdkLibrary LIB_ASYNC = const _MockSdkLibrary( |
114 'dart:async', | 114 'dart:async', |
115 '/lib/async/async.dart', | 115 '/lib/async/async.dart', |
116 ''' | 116 ''' |
117 library dart.async; | 117 library dart.async; |
118 | 118 |
119 import 'dart:math'; | 119 import 'dart:math'; |
120 | 120 |
| 121 part 'stream.dart'; |
| 122 |
121 class Future<T> { | 123 class Future<T> { |
122 factory Future.delayed(Duration duration, [T computation()]) => null; | 124 factory Future.delayed(Duration duration, [T computation()]) => null; |
123 factory Future.value([value]) => null; | 125 factory Future.value([value]) => null; |
124 static Future wait(List<Future> futures) => null; | 126 static Future wait(List<Future> futures) => null; |
125 } | 127 } |
126 | 128 ''', |
| 129 const <_MockSdkFile>[ |
| 130 const _MockSdkFile( |
| 131 '/lib/async/stream.dart', |
| 132 r''' |
| 133 part of dart.async; |
127 class Stream<T> {} | 134 class Stream<T> {} |
128 abstract class StreamTransformer<S, T> {} | 135 abstract class StreamTransformer<S, T> {} |
129 '''); | 136 ''') |
| 137 ]); |
130 | 138 |
131 static const _MockSdkLibrary LIB_COLLECTION = const _MockSdkLibrary( | 139 static const _MockSdkLibrary LIB_COLLECTION = const _MockSdkLibrary( |
132 'dart:collection', | 140 'dart:collection', |
133 '/lib/collection/collection.dart', | 141 '/lib/collection/collection.dart', |
134 ''' | 142 ''' |
135 library dart.collection; | 143 library dart.collection; |
136 | 144 |
137 abstract class HashMap<K, V> implements Map<K, V> {} | 145 abstract class HashMap<K, V> implements Map<K, V> {} |
138 '''); | 146 '''); |
139 | 147 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 new resource.MemoryResourceProvider(); | 198 new resource.MemoryResourceProvider(); |
191 | 199 |
192 /** | 200 /** |
193 * The [AnalysisContextImpl] which is used for all of the sources. | 201 * The [AnalysisContextImpl] which is used for all of the sources. |
194 */ | 202 */ |
195 AnalysisContextImpl _analysisContext; | 203 AnalysisContextImpl _analysisContext; |
196 | 204 |
197 MockSdk() { | 205 MockSdk() { |
198 LIBRARIES.forEach((_MockSdkLibrary library) { | 206 LIBRARIES.forEach((_MockSdkLibrary library) { |
199 provider.newFile(library.path, library.content); | 207 provider.newFile(library.path, library.content); |
| 208 library.parts.forEach((file) { |
| 209 provider.newFile(file.path, file.content); |
| 210 }); |
200 }); | 211 }); |
201 } | 212 } |
202 | 213 |
203 @override | 214 @override |
204 AnalysisContextImpl get context { | 215 AnalysisContextImpl get context { |
205 if (_analysisContext == null) { | 216 if (_analysisContext == null) { |
206 _analysisContext = new _SdkAnalysisContext(this); | 217 _analysisContext = new _SdkAnalysisContext(this); |
207 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 218 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
208 _analysisContext.sourceFactory = factory; | 219 _analysisContext.sourceFactory = factory; |
209 ChangeSet changeSet = new ChangeSet(); | 220 ChangeSet changeSet = new ChangeSet(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // return null. | 284 // return null. |
274 return null; | 285 return null; |
275 } | 286 } |
276 | 287 |
277 @override | 288 @override |
278 Source mapDartUri(String dartUri) { | 289 Source mapDartUri(String dartUri) { |
279 const Map<String, String> uriToPath = const { | 290 const Map<String, String> uriToPath = const { |
280 "dart:core": "/lib/core/core.dart", | 291 "dart:core": "/lib/core/core.dart", |
281 "dart:html": "/lib/html/dartium/html_dartium.dart", | 292 "dart:html": "/lib/html/dartium/html_dartium.dart", |
282 "dart:async": "/lib/async/async.dart", | 293 "dart:async": "/lib/async/async.dart", |
| 294 "dart:async/stream.dart": "/lib/async/stream.dart", |
283 "dart:collection": "/lib/collection/collection.dart", | 295 "dart:collection": "/lib/collection/collection.dart", |
284 "dart:convert": "/lib/convert/convert.dart", | 296 "dart:convert": "/lib/convert/convert.dart", |
285 "dart:math": "/lib/math/math.dart" | 297 "dart:math": "/lib/math/math.dart" |
286 }; | 298 }; |
287 | 299 |
288 String path = uriToPath[dartUri]; | 300 String path = uriToPath[dartUri]; |
289 if (path != null) { | 301 if (path != null) { |
290 resource.File file = provider.getResource(path); | 302 resource.File file = provider.getResource(path); |
291 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); | 303 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); |
292 return file.createSource(uri); | 304 return file.createSource(uri); |
293 } | 305 } |
294 | 306 |
295 // If we reach here then we tried to use a dartUri that's not in the | 307 // If we reach here then we tried to use a dartUri that's not in the |
296 // table above. | 308 // table above. |
297 return null; | 309 return null; |
298 } | 310 } |
299 } | 311 } |
300 | 312 |
301 class _MockSdkLibrary implements SdkLibrary { | 313 class _MockSdkLibrary implements SdkLibrary { |
302 final String shortName; | 314 final String shortName; |
303 final String path; | 315 final String path; |
304 final String content; | 316 final String content; |
| 317 final List<_MockSdkFile> parts; |
305 | 318 |
306 const _MockSdkLibrary(this.shortName, this.path, this.content); | 319 const _MockSdkLibrary(this.shortName, this.path, this.content, |
| 320 [this.parts = const <_MockSdkFile>[]]); |
307 | 321 |
308 @override | 322 @override |
309 String get category => throw unimplemented; | 323 String get category => throw unimplemented; |
310 | 324 |
311 @override | 325 @override |
312 bool get isDart2JsLibrary => throw unimplemented; | 326 bool get isDart2JsLibrary => throw unimplemented; |
313 | 327 |
314 @override | 328 @override |
315 bool get isDocumented => throw unimplemented; | 329 bool get isDocumented => throw unimplemented; |
316 | 330 |
317 @override | 331 @override |
318 bool get isImplementation => throw unimplemented; | 332 bool get isImplementation => throw unimplemented; |
319 | 333 |
320 @override | 334 @override |
321 bool get isInternal => throw unimplemented; | 335 bool get isInternal => throw unimplemented; |
322 | 336 |
323 @override | 337 @override |
324 bool get isShared => throw unimplemented; | 338 bool get isShared => throw unimplemented; |
325 | 339 |
326 @override | 340 @override |
327 bool get isVmLibrary => throw unimplemented; | 341 bool get isVmLibrary => throw unimplemented; |
328 | 342 |
329 UnimplementedError get unimplemented => new UnimplementedError(); | 343 UnimplementedError get unimplemented => new UnimplementedError(); |
330 } | 344 } |
331 | 345 |
| 346 class _MockSdkFile { |
| 347 final String path; |
| 348 final String content; |
| 349 |
| 350 const _MockSdkFile(this.path, this.content); |
| 351 } |
| 352 |
332 /** | 353 /** |
333 * An [AnalysisContextImpl] that only contains sources for a Dart SDK. | 354 * An [AnalysisContextImpl] that only contains sources for a Dart SDK. |
334 */ | 355 */ |
335 class _SdkAnalysisContext extends AnalysisContextImpl { | 356 class _SdkAnalysisContext extends AnalysisContextImpl { |
336 final DartSdk sdk; | 357 final DartSdk sdk; |
337 | 358 |
338 _SdkAnalysisContext(this.sdk); | 359 _SdkAnalysisContext(this.sdk); |
339 | 360 |
340 @override | 361 @override |
341 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 362 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
342 if (factory == null) { | 363 if (factory == null) { |
343 return super.createCacheFromSourceFactory(factory); | 364 return super.createCacheFromSourceFactory(factory); |
344 } | 365 } |
345 return new AnalysisCache(<CachePartition>[ | 366 return new AnalysisCache(<CachePartition>[ |
346 AnalysisEngine.instance.partitionManager_new.forSdk(sdk) | 367 AnalysisEngine.instance.partitionManager_new.forSdk(sdk) |
347 ]); | 368 ]); |
348 } | 369 } |
349 } | 370 } |
OLD | NEW |