| 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 analyzer.test.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void test_applyChanges_empty() { | 339 void test_applyChanges_empty() { |
| 340 context.applyChanges(new ChangeSet()); | 340 context.applyChanges(new ChangeSet()); |
| 341 expect(context.performAnalysisTask().changeNotices, isNull); | 341 expect(context.performAnalysisTask().changeNotices, isNull); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void test_applyChanges_incremental_resetDriver() { | 344 void test_applyChanges_incremental_resetDriver() { |
| 345 // AnalysisContext incremental analysis has been removed | 345 // AnalysisContext incremental analysis has been removed |
| 346 if (context != null) return; | 346 if (context != null) return; |
| 347 throw 'is this test used by the new analysis driver?'; | 347 throw 'is this test used by the new analysis driver?'; |
| 348 | 348 |
| 349 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; | 349 // context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; |
| 350 Source source = addSource( | 350 // Source source = addSource( |
| 351 "/test.dart", | 351 // "/test.dart", |
| 352 r''' | 352 // r''' |
| 353 main() { | 353 //main() { |
| 354 print(42); | 354 // print(42); |
| 355 } | 355 //} |
| 356 '''); | 356 //'''); |
| 357 _performPendingAnalysisTasks(); | 357 // _performPendingAnalysisTasks(); |
| 358 expect(context.getErrors(source).errors, hasLength(0)); | 358 // expect(context.getErrors(source).errors, hasLength(0)); |
| 359 // Update the source to have a parse error. | 359 // // Update the source to have a parse error. |
| 360 // This is an incremental change, but we always invalidate DART_ERRORS. | 360 // // This is an incremental change, but we always invalidate DART_ERRORS. |
| 361 context.setContents( | 361 // context.setContents( |
| 362 source, | 362 // source, |
| 363 r''' | 363 // r''' |
| 364 main() { | 364 //main() { |
| 365 print(42) | 365 // print(42) |
| 366 } | 366 //} |
| 367 '''); | 367 //'''); |
| 368 AnalysisCache cache = context.analysisCache; | 368 // AnalysisCache cache = context.analysisCache; |
| 369 expect(cache.getValue(source, PARSE_ERRORS), hasLength(1)); | 369 // expect(cache.getValue(source, PARSE_ERRORS), hasLength(1)); |
| 370 expect(cache.getState(source, DART_ERRORS), CacheState.INVALID); | 370 // expect(cache.getState(source, DART_ERRORS), CacheState.INVALID); |
| 371 // Perform enough analysis to prepare inputs (is not actually tested) for | 371 // // Perform enough analysis to prepare inputs (is not actually tested) for |
| 372 // the DART_ERRORS computing task, but don't compute it yet. | 372 // // the DART_ERRORS computing task, but don't compute it yet. |
| 373 context.performAnalysisTask(); | 373 // context.performAnalysisTask(); |
| 374 context.performAnalysisTask(); | 374 // context.performAnalysisTask(); |
| 375 expect(cache.getState(source, DART_ERRORS), CacheState.INVALID); | 375 // expect(cache.getState(source, DART_ERRORS), CacheState.INVALID); |
| 376 // Update the source so that PARSE_ERRORS is empty. | 376 // // Update the source so that PARSE_ERRORS is empty. |
| 377 context.setContents( | 377 // context.setContents( |
| 378 source, | 378 // source, |
| 379 r''' | 379 // r''' |
| 380 main() { | 380 //main() { |
| 381 print(42); | 381 // print(42); |
| 382 } | 382 //} |
| 383 '''); | 383 //'''); |
| 384 expect(cache.getValue(source, PARSE_ERRORS), hasLength(0)); | 384 // expect(cache.getValue(source, PARSE_ERRORS), hasLength(0)); |
| 385 // After full analysis DART_ERRORS should also be empty. | 385 // // After full analysis DART_ERRORS should also be empty. |
| 386 _performPendingAnalysisTasks(); | 386 // _performPendingAnalysisTasks(); |
| 387 expect(cache.getValue(source, DART_ERRORS), hasLength(0)); | 387 // expect(cache.getValue(source, DART_ERRORS), hasLength(0)); |
| 388 expect(context.getErrors(source).errors, hasLength(0)); | 388 // expect(context.getErrors(source).errors, hasLength(0)); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void test_applyChanges_overriddenSource() { | 391 void test_applyChanges_overriddenSource() { |
| 392 String content = "library test;"; | 392 String content = "library test;"; |
| 393 Source source = addSource("/test.dart", content); | 393 Source source = addSource("/test.dart", content); |
| 394 context.setContents(source, content); | 394 context.setContents(source, content); |
| 395 context.computeErrors(source); | 395 context.computeErrors(source); |
| 396 while (!context.sourcesNeedingProcessing.isEmpty) { | 396 while (!context.sourcesNeedingProcessing.isEmpty) { |
| 397 context.performAnalysisTask(); | 397 context.performAnalysisTask(); |
| 398 } | 398 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 * 2. Change overlay. | 474 * 2. Change overlay. |
| 475 * 3. If the contents of the document buffer is the same as the contents | 475 * 3. If the contents of the document buffer is the same as the contents |
| 476 * of the file, remove overlay. | 476 * of the file, remove overlay. |
| 477 * So, we need to try to use incremental resolution for removing overlays too. | 477 * So, we need to try to use incremental resolution for removing overlays too. |
| 478 */ | 478 */ |
| 479 void test_applyChanges_remove_incremental() { | 479 void test_applyChanges_remove_incremental() { |
| 480 // AnalysisContext incremental analysis has been removed | 480 // AnalysisContext incremental analysis has been removed |
| 481 if (context != null) return; | 481 if (context != null) return; |
| 482 throw 'is this test used by the new analysis driver?'; | 482 throw 'is this test used by the new analysis driver?'; |
| 483 | 483 |
| 484 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 484 // MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 485 Source source = resourceProvider | 485 // Source source = resourceProvider |
| 486 .newFile( | 486 // .newFile( |
| 487 '/test.dart', | 487 // '/test.dart', |
| 488 r''' | 488 // r''' |
| 489 main() { | 489 //main() { |
| 490 print(1); | 490 // print(1); |
| 491 } | 491 //} |
| 492 ''') | 492 //''') |
| 493 .createSource(); | 493 // .createSource(); |
| 494 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; | 494 // context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; |
| 495 context.applyChanges(new ChangeSet()..addedSource(source)); | 495 // context.applyChanges(new ChangeSet()..addedSource(source)); |
| 496 // remember compilation unit | 496 // // remember compilation unit |
| 497 _analyzeAll_assertFinished(); | 497 // _analyzeAll_assertFinished(); |
| 498 CompilationUnit unit = context.getResolvedCompilationUnit2(source, source); | 498 // CompilationUnit unit = context.getResolvedCompilationUnit2(source, source)
; |
| 499 // add overlay | 499 // // add overlay |
| 500 context.setContents( | 500 // context.setContents( |
| 501 source, | 501 // source, |
| 502 r''' | 502 // r''' |
| 503 main() { | 503 //main() { |
| 504 print(12); | 504 // print(12); |
| 505 } | 505 //} |
| 506 '''); | 506 //'''); |
| 507 _analyzeAll_assertFinished(); | 507 // _analyzeAll_assertFinished(); |
| 508 expect(context.getResolvedCompilationUnit2(source, source), unit); | 508 // expect(context.getResolvedCompilationUnit2(source, source), unit); |
| 509 // remove overlay | 509 // // remove overlay |
| 510 context.setContents(source, null); | 510 // context.setContents(source, null); |
| 511 _analyzeAll_assertFinished(); | 511 // _analyzeAll_assertFinished(); |
| 512 expect(context.getResolvedCompilationUnit2(source, source), unit); | 512 // expect(context.getResolvedCompilationUnit2(source, source), unit); |
| 513 } | 513 } |
| 514 | 514 |
| 515 Future test_applyChanges_removeContainer() { | 515 Future test_applyChanges_removeContainer() { |
| 516 SourcesChangedListener listener = new SourcesChangedListener(); | 516 SourcesChangedListener listener = new SourcesChangedListener(); |
| 517 context.onSourcesChanged.listen(listener.onData); | 517 context.onSourcesChanged.listen(listener.onData); |
| 518 String libAContents = r''' | 518 String libAContents = r''' |
| 519 library libA; | 519 library libA; |
| 520 import 'libB.dart';'''; | 520 import 'libB.dart';'''; |
| 521 Source libA = addSource("/libA.dart", libAContents); | 521 Source libA = addSource("/libA.dart", libAContents); |
| 522 String libBContents = "library libB;"; | 522 String libBContents = "library libB;"; |
| (...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2775 listener.assertEvent(changedSources: [librarySource]); | 2775 listener.assertEvent(changedSources: [librarySource]); |
| 2776 listener.assertNoMoreEvents(); | 2776 listener.assertNoMoreEvents(); |
| 2777 }); | 2777 }); |
| 2778 } | 2778 } |
| 2779 | 2779 |
| 2780 void test_setContents_null() { | 2780 void test_setContents_null() { |
| 2781 // AnalysisContext incremental analysis has been removed | 2781 // AnalysisContext incremental analysis has been removed |
| 2782 if (context != null) return; | 2782 if (context != null) return; |
| 2783 throw 'is this test used by the new analysis driver?'; | 2783 throw 'is this test used by the new analysis driver?'; |
| 2784 | 2784 |
| 2785 Source librarySource = addSource( | 2785 // Source librarySource = addSource( |
| 2786 "/lib.dart", | 2786 // "/lib.dart", |
| 2787 r''' | 2787 // r''' |
| 2788 library lib; | 2788 //library lib; |
| 2789 int a = 0;'''); | 2789 //int a = 0;'''); |
| 2790 context.setContents(librarySource, '// different'); | 2790 // context.setContents(librarySource, '// different'); |
| 2791 context.computeLibraryElement(librarySource); | 2791 // context.computeLibraryElement(librarySource); |
| 2792 context.setContents(librarySource, null); | 2792 // context.setContents(librarySource, null); |
| 2793 expect(context.getResolvedCompilationUnit2(librarySource, librarySource), | 2793 // expect(context.getResolvedCompilationUnit2(librarySource, librarySource), |
| 2794 isNull); | 2794 // isNull); |
| 2795 } | 2795 } |
| 2796 | 2796 |
| 2797 void test_setContents_unchanged_consistentModificationTime() { | 2797 void test_setContents_unchanged_consistentModificationTime() { |
| 2798 String contents = "// foo"; | 2798 String contents = "// foo"; |
| 2799 Source source = addSource("/test.dart", contents); | 2799 Source source = addSource("/test.dart", contents); |
| 2800 context.setContents(source, contents); | 2800 context.setContents(source, contents); |
| 2801 // do all, no tasks | 2801 // do all, no tasks |
| 2802 _analyzeAll_assertFinished(); | 2802 _analyzeAll_assertFinished(); |
| 2803 { | 2803 { |
| 2804 AnalysisResult result = context.performAnalysisTask(); | 2804 AnalysisResult result = context.performAnalysisTask(); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3126 * Initialize the visitor. | 3126 * Initialize the visitor. |
| 3127 */ | 3127 */ |
| 3128 _ElementGatherer(); | 3128 _ElementGatherer(); |
| 3129 | 3129 |
| 3130 @override | 3130 @override |
| 3131 void visitElement(Element element) { | 3131 void visitElement(Element element) { |
| 3132 elements[element] = element; | 3132 elements[element] = element; |
| 3133 super.visitElement(element); | 3133 super.visitElement(element); |
| 3134 } | 3134 } |
| 3135 } | 3135 } |
| OLD | NEW |