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

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

Issue 1121963002: Record dependencies and invalidate results. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge and fixes for review comments. Created 5 years, 7 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 | Annotate | Revision Log
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 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';
12 15
13 class MockSdk implements DartSdk { 16 class MockSdk implements DartSdk {
14 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', 17 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core',
15 '/lib/core/core.dart', ''' 18 '/lib/core/core.dart', '''
16 library dart.core; 19 library dart.core;
17 20
18 import 'dart:async'; 21 import 'dart:async';
19 22
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 LIB_COLLECTION, 171 LIB_COLLECTION,
169 LIB_CONVERT, 172 LIB_CONVERT,
170 LIB_MATH, 173 LIB_MATH,
171 LIB_HTML, 174 LIB_HTML,
172 ]; 175 ];
173 176
174 final resource.MemoryResourceProvider provider = 177 final resource.MemoryResourceProvider provider =
175 new resource.MemoryResourceProvider(); 178 new resource.MemoryResourceProvider();
176 179
177 /** 180 /**
178 * The [AnalysisContext] which is used for all of the sources. 181 * The [AnalysisContextImpl] which is used for all of the sources.
179 */ 182 */
180 InternalAnalysisContext _analysisContext; 183 AnalysisContextImpl _analysisContext;
181 184
182 MockSdk() { 185 MockSdk() {
183 LIBRARIES.forEach((_MockSdkLibrary library) { 186 LIBRARIES.forEach((_MockSdkLibrary library) {
184 provider.newFile(library.path, library.content); 187 provider.newFile(library.path, library.content);
185 }); 188 });
186 } 189 }
187 190
188 @override 191 @override
189 AnalysisContext get context { 192 AnalysisContextImpl get context {
190 if (_analysisContext == null) { 193 if (_analysisContext == null) {
191 _analysisContext = new SdkAnalysisContext(); 194 _analysisContext = new _SdkAnalysisContext(this);
192 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); 195 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]);
193 _analysisContext.sourceFactory = factory; 196 _analysisContext.sourceFactory = factory;
194 ChangeSet changeSet = new ChangeSet(); 197 ChangeSet changeSet = new ChangeSet();
195 for (String uri in uris) { 198 for (String uri in uris) {
196 Source source = factory.forUri(uri); 199 Source source = factory.forUri(uri);
197 changeSet.addedSource(source); 200 changeSet.addedSource(source);
198 } 201 }
199 _analysisContext.applyChanges(changeSet); 202 _analysisContext.applyChanges(changeSet);
200 } 203 }
201 return _analysisContext; 204 return _analysisContext;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 bool get isInternal => throw unimplemented; 309 bool get isInternal => throw unimplemented;
307 310
308 @override 311 @override
309 bool get isShared => throw unimplemented; 312 bool get isShared => throw unimplemented;
310 313
311 @override 314 @override
312 bool get isVmLibrary => throw unimplemented; 315 bool get isVmLibrary => throw unimplemented;
313 316
314 UnimplementedError get unimplemented => new UnimplementedError(); 317 UnimplementedError get unimplemented => new UnimplementedError();
315 } 318 }
319
320 /**
321 * An [AnalysisContextImpl] that only contains sources for a Dart SDK.
322 */
323 class _SdkAnalysisContext extends AnalysisContextImpl {
324 final DartSdk sdk;
325
326 _SdkAnalysisContext(this.sdk);
327
328 @override
329 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
330 if (factory == null) {
331 return super.createCacheFromSourceFactory(factory);
332 }
333 return new AnalysisCache(<CachePartition>[
334 AnalysisEngine.instance.partitionManager_new.forSdk(sdk)
335 ]);
336 }
337 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698