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 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/generated/engine.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/context/context.dart'; | |
| 11 import 'package:analyzer/src/generated/engine.dart' | |
| 12 show AnalysisEngine, ChangeSet; | |
| 10 import 'package:analyzer/src/generated/sdk.dart'; | 13 import 'package:analyzer/src/generated/sdk.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 //import 'package:analyzer/src/generated/engine.dart'; | |
|
Brian Wilkerson
2015/05/03 15:35:33
Did you intend to remove this line?
scheglov
2015/05/03 20:26:28
Acknowledged.
| |
| 12 | 16 |
| 13 class MockSdk implements DartSdk { | 17 class MockSdk implements DartSdk { |
| 14 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', | 18 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', |
| 15 '/lib/core/core.dart', ''' | 19 '/lib/core/core.dart', ''' |
| 16 library dart.core; | 20 library dart.core; |
| 17 | 21 |
| 18 import 'dart:async'; | 22 import 'dart:async'; |
| 19 | 23 |
| 20 class Object { | 24 class Object { |
| 21 bool operator ==(other) => identical(this, other); | 25 bool operator ==(other) => identical(this, other); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 LIB_COLLECTION, | 172 LIB_COLLECTION, |
| 169 LIB_CONVERT, | 173 LIB_CONVERT, |
| 170 LIB_MATH, | 174 LIB_MATH, |
| 171 LIB_HTML, | 175 LIB_HTML, |
| 172 ]; | 176 ]; |
| 173 | 177 |
| 174 final resource.MemoryResourceProvider provider = | 178 final resource.MemoryResourceProvider provider = |
| 175 new resource.MemoryResourceProvider(); | 179 new resource.MemoryResourceProvider(); |
| 176 | 180 |
| 177 /** | 181 /** |
| 178 * The [AnalysisContext] which is used for all of the sources. | 182 * The [AnalysisContextImpl] which is used for all of the sources. |
| 179 */ | 183 */ |
| 180 InternalAnalysisContext _analysisContext; | 184 AnalysisContextImpl _analysisContext; |
| 181 | 185 |
| 182 MockSdk() { | 186 MockSdk() { |
| 183 LIBRARIES.forEach((_MockSdkLibrary library) { | 187 LIBRARIES.forEach((_MockSdkLibrary library) { |
| 184 provider.newFile(library.path, library.content); | 188 provider.newFile(library.path, library.content); |
| 185 }); | 189 }); |
| 186 } | 190 } |
| 187 | 191 |
| 188 @override | 192 @override |
| 189 AnalysisContext get context { | 193 AnalysisContextImpl get context { |
| 190 if (_analysisContext == null) { | 194 if (_analysisContext == null) { |
| 191 _analysisContext = new SdkAnalysisContext(); | 195 _analysisContext = new _SdkAnalysisContext(this); |
| 192 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 196 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 193 _analysisContext.sourceFactory = factory; | 197 _analysisContext.sourceFactory = factory; |
| 194 ChangeSet changeSet = new ChangeSet(); | 198 ChangeSet changeSet = new ChangeSet(); |
| 195 for (String uri in uris) { | 199 for (String uri in uris) { |
| 196 Source source = factory.forUri(uri); | 200 Source source = factory.forUri(uri); |
| 197 changeSet.addedSource(source); | 201 changeSet.addedSource(source); |
| 198 } | 202 } |
| 199 _analysisContext.applyChanges(changeSet); | 203 _analysisContext.applyChanges(changeSet); |
| 200 } | 204 } |
| 201 return _analysisContext; | 205 return _analysisContext; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 bool get isInternal => throw unimplemented; | 310 bool get isInternal => throw unimplemented; |
| 307 | 311 |
| 308 @override | 312 @override |
| 309 bool get isShared => throw unimplemented; | 313 bool get isShared => throw unimplemented; |
| 310 | 314 |
| 311 @override | 315 @override |
| 312 bool get isVmLibrary => throw unimplemented; | 316 bool get isVmLibrary => throw unimplemented; |
| 313 | 317 |
| 314 UnimplementedError get unimplemented => new UnimplementedError(); | 318 UnimplementedError get unimplemented => new UnimplementedError(); |
| 315 } | 319 } |
| 320 | |
| 321 /** | |
| 322 * An [AnalysisContextImpl] that only contains sources for a Dart SDK. | |
| 323 */ | |
| 324 class _SdkAnalysisContext extends AnalysisContextImpl { | |
| 325 final DartSdk sdk; | |
| 326 | |
| 327 _SdkAnalysisContext(this.sdk); | |
| 328 | |
| 329 @override | |
| 330 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | |
| 331 if (factory == null) { | |
| 332 return super.createCacheFromSourceFactory(factory); | |
| 333 } | |
| 334 return new AnalysisCache(<CachePartition>[ | |
| 335 AnalysisEngine.instance.partitionManager_new.forSdk(sdk) | |
| 336 ]); | |
| 337 } | |
| 338 } | |
| OLD | NEW |