| 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.context.context_test; | 5 library test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| 10 import 'package:analyzer/src/context/cache.dart'; | 11 import 'package:analyzer/src/context/cache.dart'; |
| 11 import 'package:analyzer/src/context/context.dart'; | 12 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' | 15 import 'package:analyzer/src/generated/engine.dart' |
| 15 show | 16 show |
| 16 AnalysisContext, | 17 AnalysisContext, |
| 17 AnalysisContextStatistics, | 18 AnalysisContextStatistics, |
| 18 AnalysisDelta, | 19 AnalysisDelta, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 importedLibraries = libAElement.importedLibraries; | 271 importedLibraries = libAElement.importedLibraries; |
| 271 expect(importedLibraries, hasLength(1)); | 272 expect(importedLibraries, hasLength(1)); |
| 272 return pumpEventQueue().then((_) { | 273 return pumpEventQueue().then((_) { |
| 273 listener.assertEvent(wereSourcesAdded: true); | 274 listener.assertEvent(wereSourcesAdded: true); |
| 274 listener.assertEvent(wereSourcesAdded: true); | 275 listener.assertEvent(wereSourcesAdded: true); |
| 275 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | 276 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 276 listener.assertNoMoreEvents(); | 277 listener.assertNoMoreEvents(); |
| 277 }); | 278 }); |
| 278 } | 279 } |
| 279 | 280 |
| 281 /** |
| 282 * IDEA uses the following scenarion: |
| 283 * 1. Add overlay. |
| 284 * 2. Change overlay. |
| 285 * 3. If the contents of the document buffer is the same as the contents |
| 286 * of the file, remove overlay. |
| 287 * So, we need to try to use incremental resolution for removing overlays too. |
| 288 */ |
| 289 void test_applyChanges_remove_incremental() { |
| 290 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 291 Source source = resourceProvider.newFile('/test.dart', r''' |
| 292 main() { |
| 293 print(1); |
| 294 } |
| 295 ''').createSource(); |
| 296 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; |
| 297 context.applyChanges(new ChangeSet()..addedSource(source)); |
| 298 // remember compilation unit |
| 299 _analyzeAll_assertFinished(); |
| 300 CompilationUnit unit = context.getResolvedCompilationUnit2(source, source); |
| 301 // add overlay |
| 302 context.setContents(source, r''' |
| 303 main() { |
| 304 print(12); |
| 305 } |
| 306 '''); |
| 307 _analyzeAll_assertFinished(); |
| 308 expect(context.getResolvedCompilationUnit2(source, source), unit); |
| 309 // remove overlay |
| 310 context.setContents(source, null); |
| 311 _analyzeAll_assertFinished(); |
| 312 expect(context.getResolvedCompilationUnit2(source, source), unit); |
| 313 } |
| 314 |
| 280 Future test_applyChanges_removeContainer() { | 315 Future test_applyChanges_removeContainer() { |
| 281 SourcesChangedListener listener = new SourcesChangedListener(); | 316 SourcesChangedListener listener = new SourcesChangedListener(); |
| 282 context.onSourcesChanged.listen(listener.onData); | 317 context.onSourcesChanged.listen(listener.onData); |
| 283 String libAContents = r''' | 318 String libAContents = r''' |
| 284 library libA; | 319 library libA; |
| 285 import 'libB.dart';'''; | 320 import 'libB.dart';'''; |
| 286 Source libA = addSource("/libA.dart", libAContents); | 321 Source libA = addSource("/libA.dart", libAContents); |
| 287 String libBContents = "library libB;"; | 322 String libBContents = "library libB;"; |
| 288 Source libB = addSource("/libB.dart", libBContents); | 323 Source libB = addSource("/libB.dart", libBContents); |
| 289 context.computeLibraryElement(libA); | 324 context.computeLibraryElement(libA); |
| (...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2270 } | 2305 } |
| 2271 } | 2306 } |
| 2272 | 2307 |
| 2273 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2308 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 2274 implements SourceContainer { | 2309 implements SourceContainer { |
| 2275 Source libB; | 2310 Source libB; |
| 2276 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2311 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 2277 @override | 2312 @override |
| 2278 bool contains(Source source) => source == libB; | 2313 bool contains(Source source) => source == libB; |
| 2279 } | 2314 } |
| OLD | NEW |