| 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/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 import 'package:analyzer/src/task/html.dart'; | 38 import 'package:analyzer/src/task/html.dart'; |
| 39 import 'package:analyzer/task/dart.dart'; | 39 import 'package:analyzer/task/dart.dart'; |
| 40 import 'package:analyzer/task/model.dart'; | 40 import 'package:analyzer/task/model.dart'; |
| 41 import 'package:html/dom.dart' show Document; | 41 import 'package:html/dom.dart' show Document; |
| 42 import 'package:unittest/unittest.dart'; | 42 import 'package:unittest/unittest.dart'; |
| 43 import 'package:watcher/src/utils.dart'; | 43 import 'package:watcher/src/utils.dart'; |
| 44 | 44 |
| 45 import '../../generated/engine_test.dart'; | 45 import '../../generated/engine_test.dart'; |
| 46 import '../../generated/test_support.dart'; | 46 import '../../generated/test_support.dart'; |
| 47 import '../../reflective_tests.dart'; | 47 import '../../reflective_tests.dart'; |
| 48 import '../../utils.dart'; |
| 48 import 'abstract_context.dart'; | 49 import 'abstract_context.dart'; |
| 49 | 50 |
| 50 main() { | 51 main() { |
| 51 groupSep = ' | '; | 52 initializeTestEnvironment(); |
| 52 runReflectiveTests(AnalysisContextImplTest); | 53 runReflectiveTests(AnalysisContextImplTest); |
| 53 runReflectiveTests(LimitedInvalidateTest); | 54 runReflectiveTests(LimitedInvalidateTest); |
| 54 } | 55 } |
| 55 | 56 |
| 56 @reflectiveTest | 57 @reflectiveTest |
| 57 class AnalysisContextImplTest extends AbstractContextTest { | 58 class AnalysisContextImplTest extends AbstractContextTest { |
| 58 Future fail_implicitAnalysisEvents_removed() async { | 59 Future fail_implicitAnalysisEvents_removed() async { |
| 59 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); | 60 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); |
| 60 context.implicitAnalysisEvents.listen(listener.onData); | 61 context.implicitAnalysisEvents.listen(listener.onData); |
| 61 // | 62 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 // longer implicitly analyzing the file. | 77 // longer implicitly analyzing the file. |
| 77 // | 78 // |
| 78 context.setContents(sourceA, "library a;"); | 79 context.setContents(sourceA, "library a;"); |
| 79 context.computeErrors(sourceA); | 80 context.computeErrors(sourceA); |
| 80 await pumpEventQueue(); | 81 await pumpEventQueue(); |
| 81 listener.expectNotAnalyzed(sourceB); | 82 listener.expectNotAnalyzed(sourceB); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void fail_performAnalysisTask_importedLibraryDelete_html() { | 85 void fail_performAnalysisTask_importedLibraryDelete_html() { |
| 85 // NOTE: This was failing before converting to the new task model. | 86 // NOTE: This was failing before converting to the new task model. |
| 86 Source htmlSource = addSource("/page.html", r''' | 87 Source htmlSource = addSource( |
| 88 "/page.html", |
| 89 r''' |
| 87 <html><body><script type="application/dart"> | 90 <html><body><script type="application/dart"> |
| 88 import 'libB.dart'; | 91 import 'libB.dart'; |
| 89 main() {print('hello dart');} | 92 main() {print('hello dart');} |
| 90 </script></body></html>'''); | 93 </script></body></html>'''); |
| 91 Source libBSource = addSource("/libB.dart", "library libB;"); | 94 Source libBSource = addSource("/libB.dart", "library libB;"); |
| 92 _analyzeAll_assertFinished(); | 95 _analyzeAll_assertFinished(); |
| 93 context.computeErrors(htmlSource); | 96 context.computeErrors(htmlSource); |
| 94 expect( | 97 expect( |
| 95 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | 98 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 96 reason: "libB resolved 1"); | 99 reason: "libB resolved 1"); |
| 97 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), | 100 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), |
| 98 isTrue, reason: "htmlSource doesn't have errors"); | 101 isTrue, |
| 102 reason: "htmlSource doesn't have errors"); |
| 99 // remove libB.dart content and analyze | 103 // remove libB.dart content and analyze |
| 100 context.setContents(libBSource, null); | 104 context.setContents(libBSource, null); |
| 101 _analyzeAll_assertFinished(); | 105 _analyzeAll_assertFinished(); |
| 102 context.computeErrors(htmlSource); | 106 context.computeErrors(htmlSource); |
| 103 AnalysisErrorInfo errors = context.getErrors(htmlSource); | 107 AnalysisErrorInfo errors = context.getErrors(htmlSource); |
| 104 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, | 108 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, |
| 105 reason: "htmlSource has an error"); | 109 reason: "htmlSource has an error"); |
| 106 } | 110 } |
| 107 | 111 |
| 108 void fail_recordLibraryElements() { | 112 void fail_recordLibraryElements() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 changeSet2.changedContent(source, 'library test;'); | 171 changeSet2.changedContent(source, 'library test;'); |
| 168 context.applyChanges(changeSet2); | 172 context.applyChanges(changeSet2); |
| 169 return pumpEventQueue().then((_) { | 173 return pumpEventQueue().then((_) { |
| 170 listener.assertEvent(wereSourcesAdded: true); | 174 listener.assertEvent(wereSourcesAdded: true); |
| 171 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 175 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 172 listener.assertNoMoreEvents(); | 176 listener.assertNoMoreEvents(); |
| 173 }); | 177 }); |
| 174 } | 178 } |
| 175 | 179 |
| 176 void test_applyChanges_change_flush_element() { | 180 void test_applyChanges_change_flush_element() { |
| 177 Source librarySource = addSource("/lib.dart", r''' | 181 Source librarySource = addSource( |
| 182 "/lib.dart", |
| 183 r''' |
| 178 library lib; | 184 library lib; |
| 179 int a = 0;'''); | 185 int a = 0;'''); |
| 180 expect(context.computeLibraryElement(librarySource), isNotNull); | 186 expect(context.computeLibraryElement(librarySource), isNotNull); |
| 181 context.setContents(librarySource, r''' | 187 context.setContents( |
| 188 librarySource, |
| 189 r''' |
| 182 library lib; | 190 library lib; |
| 183 int aa = 0;'''); | 191 int aa = 0;'''); |
| 184 expect(context.getLibraryElement(librarySource), isNull); | 192 expect(context.getLibraryElement(librarySource), isNull); |
| 185 } | 193 } |
| 186 | 194 |
| 187 Future test_applyChanges_change_multiple() { | 195 Future test_applyChanges_change_multiple() { |
| 188 SourcesChangedListener listener = new SourcesChangedListener(); | 196 SourcesChangedListener listener = new SourcesChangedListener(); |
| 189 context.onSourcesChanged.listen(listener.onData); | 197 context.onSourcesChanged.listen(listener.onData); |
| 190 String libraryContents1 = r''' | 198 String libraryContents1 = r''' |
| 191 library lib; | 199 library lib; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 211 context.resolveCompilationUnit2(librarySource, librarySource); | 219 context.resolveCompilationUnit2(librarySource, librarySource); |
| 212 expect(libraryUnit, isNotNull); | 220 expect(libraryUnit, isNotNull); |
| 213 CompilationUnit partUnit = | 221 CompilationUnit partUnit = |
| 214 context.resolveCompilationUnit2(partSource, librarySource); | 222 context.resolveCompilationUnit2(partSource, librarySource); |
| 215 expect(partUnit, isNotNull); | 223 expect(partUnit, isNotNull); |
| 216 TopLevelVariableDeclaration declaration = | 224 TopLevelVariableDeclaration declaration = |
| 217 libraryUnit.declarations[0] as TopLevelVariableDeclaration; | 225 libraryUnit.declarations[0] as TopLevelVariableDeclaration; |
| 218 Element declarationElement = declaration.variables.variables[0].element; | 226 Element declarationElement = declaration.variables.variables[0].element; |
| 219 TopLevelVariableDeclaration use = | 227 TopLevelVariableDeclaration use = |
| 220 partUnit.declarations[0] as TopLevelVariableDeclaration; | 228 partUnit.declarations[0] as TopLevelVariableDeclaration; |
| 221 Element useElement = (use.variables.variables[ | 229 Element useElement = (use.variables.variables[0].initializer |
| 222 0].initializer as SimpleIdentifier).staticElement; | 230 as SimpleIdentifier).staticElement; |
| 223 expect((useElement as PropertyAccessorElement).variable, | 231 expect((useElement as PropertyAccessorElement).variable, |
| 224 same(declarationElement)); | 232 same(declarationElement)); |
| 225 return pumpEventQueue().then((_) { | 233 return pumpEventQueue().then((_) { |
| 226 listener.assertEvent(wereSourcesAdded: true); | 234 listener.assertEvent(wereSourcesAdded: true); |
| 227 listener.assertEvent(wereSourcesAdded: true); | 235 listener.assertEvent(wereSourcesAdded: true); |
| 228 listener.assertEvent(changedSources: [librarySource]); | 236 listener.assertEvent(changedSources: [librarySource]); |
| 229 listener.assertEvent(changedSources: [partSource]); | 237 listener.assertEvent(changedSources: [partSource]); |
| 230 listener.assertNoMoreEvents(); | 238 listener.assertNoMoreEvents(); |
| 231 }); | 239 }); |
| 232 } | 240 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 /** | 315 /** |
| 308 * IDEA uses the following scenario: | 316 * IDEA uses the following scenario: |
| 309 * 1. Add overlay. | 317 * 1. Add overlay. |
| 310 * 2. Change overlay. | 318 * 2. Change overlay. |
| 311 * 3. If the contents of the document buffer is the same as the contents | 319 * 3. If the contents of the document buffer is the same as the contents |
| 312 * of the file, remove overlay. | 320 * of the file, remove overlay. |
| 313 * So, we need to try to use incremental resolution for removing overlays too. | 321 * So, we need to try to use incremental resolution for removing overlays too. |
| 314 */ | 322 */ |
| 315 void test_applyChanges_remove_incremental() { | 323 void test_applyChanges_remove_incremental() { |
| 316 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 324 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 317 Source source = resourceProvider.newFile('/test.dart', r''' | 325 Source source = resourceProvider |
| 326 .newFile( |
| 327 '/test.dart', |
| 328 r''' |
| 318 main() { | 329 main() { |
| 319 print(1); | 330 print(1); |
| 320 } | 331 } |
| 321 ''').createSource(); | 332 ''') |
| 333 .createSource(); |
| 322 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; | 334 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; |
| 323 context.applyChanges(new ChangeSet()..addedSource(source)); | 335 context.applyChanges(new ChangeSet()..addedSource(source)); |
| 324 // remember compilation unit | 336 // remember compilation unit |
| 325 _analyzeAll_assertFinished(); | 337 _analyzeAll_assertFinished(); |
| 326 CompilationUnit unit = context.getResolvedCompilationUnit2(source, source); | 338 CompilationUnit unit = context.getResolvedCompilationUnit2(source, source); |
| 327 // add overlay | 339 // add overlay |
| 328 context.setContents(source, r''' | 340 context.setContents( |
| 341 source, |
| 342 r''' |
| 329 main() { | 343 main() { |
| 330 print(12); | 344 print(12); |
| 331 } | 345 } |
| 332 '''); | 346 '''); |
| 333 _analyzeAll_assertFinished(); | 347 _analyzeAll_assertFinished(); |
| 334 expect(context.getResolvedCompilationUnit2(source, source), unit); | 348 expect(context.getResolvedCompilationUnit2(source, source), unit); |
| 335 // remove overlay | 349 // remove overlay |
| 336 context.setContents(source, null); | 350 context.setContents(source, null); |
| 337 context.validateCacheConsistency(); | 351 context.validateCacheConsistency(); |
| 338 _analyzeAll_assertFinished(); | 352 _analyzeAll_assertFinished(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 363 return pumpEventQueue().then((_) { | 377 return pumpEventQueue().then((_) { |
| 364 listener.assertEvent(wereSourcesAdded: true); | 378 listener.assertEvent(wereSourcesAdded: true); |
| 365 listener.assertEvent(wereSourcesAdded: true); | 379 listener.assertEvent(wereSourcesAdded: true); |
| 366 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | 380 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 367 listener.assertNoMoreEvents(); | 381 listener.assertNoMoreEvents(); |
| 368 }); | 382 }); |
| 369 } | 383 } |
| 370 | 384 |
| 371 void test_computeDocumentationComment_block() { | 385 void test_computeDocumentationComment_block() { |
| 372 String comment = "/** Comment */"; | 386 String comment = "/** Comment */"; |
| 373 Source source = addSource("/test.dart", """ | 387 Source source = addSource( |
| 388 "/test.dart", |
| 389 """ |
| 374 $comment | 390 $comment |
| 375 class A {}"""); | 391 class A {}"""); |
| 376 LibraryElement libraryElement = context.computeLibraryElement(source); | 392 LibraryElement libraryElement = context.computeLibraryElement(source); |
| 377 expect(libraryElement, isNotNull); | 393 expect(libraryElement, isNotNull); |
| 378 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 394 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 379 expect(libraryElement, isNotNull); | 395 expect(libraryElement, isNotNull); |
| 380 expect(context.computeDocumentationComment(classElement), comment); | 396 expect(context.computeDocumentationComment(classElement), comment); |
| 381 } | 397 } |
| 382 | 398 |
| 383 void test_computeDocumentationComment_none() { | 399 void test_computeDocumentationComment_none() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 expect(context.computeKindOf(source), same(SourceKind.PART)); | 504 expect(context.computeKindOf(source), same(SourceKind.PART)); |
| 489 } | 505 } |
| 490 | 506 |
| 491 void test_computeLibraryElement() { | 507 void test_computeLibraryElement() { |
| 492 Source source = addSource("/test.dart", "library lib;"); | 508 Source source = addSource("/test.dart", "library lib;"); |
| 493 LibraryElement element = context.computeLibraryElement(source); | 509 LibraryElement element = context.computeLibraryElement(source); |
| 494 expect(element, isNotNull); | 510 expect(element, isNotNull); |
| 495 } | 511 } |
| 496 | 512 |
| 497 void test_computeLineInfo_dart() { | 513 void test_computeLineInfo_dart() { |
| 498 Source source = addSource("/test.dart", r''' | 514 Source source = addSource( |
| 515 "/test.dart", |
| 516 r''' |
| 499 library lib; | 517 library lib; |
| 500 | 518 |
| 501 main() {}'''); | 519 main() {}'''); |
| 502 LineInfo info = context.computeLineInfo(source); | 520 LineInfo info = context.computeLineInfo(source); |
| 503 expect(info, isNotNull); | 521 expect(info, isNotNull); |
| 504 } | 522 } |
| 505 | 523 |
| 506 void test_computeLineInfo_html() { | 524 void test_computeLineInfo_html() { |
| 507 Source source = addSource("/test.html", r''' | 525 Source source = addSource( |
| 526 "/test.html", |
| 527 r''' |
| 508 <html> | 528 <html> |
| 509 <body> | 529 <body> |
| 510 <h1>A</h1> | 530 <h1>A</h1> |
| 511 </body> | 531 </body> |
| 512 </html>'''); | 532 </html>'''); |
| 513 LineInfo info = context.computeLineInfo(source); | 533 LineInfo info = context.computeLineInfo(source); |
| 514 expect(info, isNotNull); | 534 expect(info, isNotNull); |
| 515 } | 535 } |
| 516 | 536 |
| 517 Future test_computeResolvedCompilationUnitAsync() { | 537 Future test_computeResolvedCompilationUnitAsync() { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 context.getCacheEntry(libTarget).getValue(RESOLVED_UNIT); | 663 context.getCacheEntry(libTarget).getValue(RESOLVED_UNIT); |
| 644 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); | 664 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); |
| 645 expect(units, unorderedEquals([unit])); | 665 expect(units, unorderedEquals([unit])); |
| 646 } | 666 } |
| 647 | 667 |
| 648 void test_ensureResolvedDartUnits_definingUnit_notResolved() { | 668 void test_ensureResolvedDartUnits_definingUnit_notResolved() { |
| 649 Source source = addSource('/test.dart', ''); | 669 Source source = addSource('/test.dart', ''); |
| 650 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); | 670 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); |
| 651 analysisDriver.computeResult(libTarget, RESOLVED_UNIT); | 671 analysisDriver.computeResult(libTarget, RESOLVED_UNIT); |
| 652 // flush | 672 // flush |
| 653 context.getCacheEntry(libTarget).setState( | 673 context |
| 654 RESOLVED_UNIT, CacheState.FLUSHED); | 674 .getCacheEntry(libTarget) |
| 675 .setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 655 // schedule recomputing | 676 // schedule recomputing |
| 656 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); | 677 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); |
| 657 expect(units, isNull); | 678 expect(units, isNull); |
| 658 // should be the next result to compute | 679 // should be the next result to compute |
| 659 TargetedResult nextResult = context.dartWorkManager.getNextResult(); | 680 TargetedResult nextResult = context.dartWorkManager.getNextResult(); |
| 660 expect(nextResult.target, libTarget); | 681 expect(nextResult.target, libTarget); |
| 661 expect(nextResult.result, RESOLVED_UNIT); | 682 expect(nextResult.result, RESOLVED_UNIT); |
| 662 } | 683 } |
| 663 | 684 |
| 664 void test_ensureResolvedDartUnits_partUnit_hasResolved() { | 685 void test_ensureResolvedDartUnits_partUnit_hasResolved() { |
| 665 Source libSource1 = addSource('/lib1.dart', r''' | 686 Source libSource1 = addSource( |
| 687 '/lib1.dart', |
| 688 r''' |
| 666 library lib; | 689 library lib; |
| 667 part 'part.dart'; | 690 part 'part.dart'; |
| 668 '''); | 691 '''); |
| 669 Source libSource2 = addSource('/lib2.dart', r''' | 692 Source libSource2 = addSource( |
| 693 '/lib2.dart', |
| 694 r''' |
| 670 library lib; | 695 library lib; |
| 671 part 'part.dart'; | 696 part 'part.dart'; |
| 672 '''); | 697 '''); |
| 673 Source partSource = addSource('/part.dart', r''' | 698 Source partSource = addSource( |
| 699 '/part.dart', |
| 700 r''' |
| 674 part of lib; | 701 part of lib; |
| 675 '''); | 702 '''); |
| 676 LibrarySpecificUnit partTarget1 = | 703 LibrarySpecificUnit partTarget1 = |
| 677 new LibrarySpecificUnit(libSource1, partSource); | 704 new LibrarySpecificUnit(libSource1, partSource); |
| 678 LibrarySpecificUnit partTarget2 = | 705 LibrarySpecificUnit partTarget2 = |
| 679 new LibrarySpecificUnit(libSource2, partSource); | 706 new LibrarySpecificUnit(libSource2, partSource); |
| 680 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); | 707 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); |
| 681 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); | 708 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); |
| 682 CompilationUnit unit1 = | 709 CompilationUnit unit1 = |
| 683 context.getCacheEntry(partTarget1).getValue(RESOLVED_UNIT); | 710 context.getCacheEntry(partTarget1).getValue(RESOLVED_UNIT); |
| 684 CompilationUnit unit2 = | 711 CompilationUnit unit2 = |
| 685 context.getCacheEntry(partTarget2).getValue(RESOLVED_UNIT); | 712 context.getCacheEntry(partTarget2).getValue(RESOLVED_UNIT); |
| 686 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); | 713 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); |
| 687 expect(units, unorderedEquals([unit1, unit2])); | 714 expect(units, unorderedEquals([unit1, unit2])); |
| 688 } | 715 } |
| 689 | 716 |
| 690 void test_ensureResolvedDartUnits_partUnit_notResolved() { | 717 void test_ensureResolvedDartUnits_partUnit_notResolved() { |
| 691 Source libSource1 = addSource('/lib1.dart', r''' | 718 Source libSource1 = addSource( |
| 719 '/lib1.dart', |
| 720 r''' |
| 692 library lib; | 721 library lib; |
| 693 part 'part.dart'; | 722 part 'part.dart'; |
| 694 '''); | 723 '''); |
| 695 Source libSource2 = addSource('/lib2.dart', r''' | 724 Source libSource2 = addSource( |
| 725 '/lib2.dart', |
| 726 r''' |
| 696 library lib; | 727 library lib; |
| 697 part 'part.dart'; | 728 part 'part.dart'; |
| 698 '''); | 729 '''); |
| 699 Source partSource = addSource('/part.dart', r''' | 730 Source partSource = addSource( |
| 731 '/part.dart', |
| 732 r''' |
| 700 part of lib; | 733 part of lib; |
| 701 '''); | 734 '''); |
| 702 LibrarySpecificUnit partTarget1 = | 735 LibrarySpecificUnit partTarget1 = |
| 703 new LibrarySpecificUnit(libSource1, partSource); | 736 new LibrarySpecificUnit(libSource1, partSource); |
| 704 LibrarySpecificUnit partTarget2 = | 737 LibrarySpecificUnit partTarget2 = |
| 705 new LibrarySpecificUnit(libSource2, partSource); | 738 new LibrarySpecificUnit(libSource2, partSource); |
| 706 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); | 739 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); |
| 707 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); | 740 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); |
| 708 // flush | 741 // flush |
| 709 context.getCacheEntry(partTarget1).setState( | 742 context |
| 710 RESOLVED_UNIT, CacheState.FLUSHED); | 743 .getCacheEntry(partTarget1) |
| 711 context.getCacheEntry(partTarget2).setState( | 744 .setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 712 RESOLVED_UNIT, CacheState.FLUSHED); | 745 context |
| 746 .getCacheEntry(partTarget2) |
| 747 .setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 713 // schedule recomputing | 748 // schedule recomputing |
| 714 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); | 749 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); |
| 715 expect(units, isNull); | 750 expect(units, isNull); |
| 716 // should be the next result to compute | 751 // should be the next result to compute |
| 717 TargetedResult nextResult = context.dartWorkManager.getNextResult(); | 752 TargetedResult nextResult = context.dartWorkManager.getNextResult(); |
| 718 expect(nextResult.target, anyOf(partTarget1, partTarget2)); | 753 expect(nextResult.target, anyOf(partTarget1, partTarget2)); |
| 719 expect(nextResult.result, RESOLVED_UNIT); | 754 expect(nextResult.result, RESOLVED_UNIT); |
| 720 } | 755 } |
| 721 | 756 |
| 722 void test_exists_false() { | 757 void test_exists_false() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 expect(core, isNotNull); | 813 expect(core, isNotNull); |
| 779 ClassElement classObject = | 814 ClassElement classObject = |
| 780 _findClass(core.definingCompilationUnit, "Object"); | 815 _findClass(core.definingCompilationUnit, "Object"); |
| 781 expect(classObject, isNotNull); | 816 expect(classObject, isNotNull); |
| 782 ElementLocation location = classObject.location; | 817 ElementLocation location = classObject.location; |
| 783 Element element = context.getElement(location); | 818 Element element = context.getElement(location); |
| 784 expect(element, same(classObject)); | 819 expect(element, same(classObject)); |
| 785 } | 820 } |
| 786 | 821 |
| 787 void test_getElement_constructor_named() { | 822 void test_getElement_constructor_named() { |
| 788 Source source = addSource("/lib.dart", r''' | 823 Source source = addSource( |
| 824 "/lib.dart", |
| 825 r''' |
| 789 class A { | 826 class A { |
| 790 A.named() {} | 827 A.named() {} |
| 791 }'''); | 828 }'''); |
| 792 _analyzeAll_assertFinished(); | 829 _analyzeAll_assertFinished(); |
| 793 LibraryElement library = context.computeLibraryElement(source); | 830 LibraryElement library = context.computeLibraryElement(source); |
| 794 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | 831 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
| 795 ConstructorElement constructor = classA.constructors[0]; | 832 ConstructorElement constructor = classA.constructors[0]; |
| 796 ElementLocation location = constructor.location; | 833 ElementLocation location = constructor.location; |
| 797 Element element = context.getElement(location); | 834 Element element = context.getElement(location); |
| 798 expect(element, same(constructor)); | 835 expect(element, same(constructor)); |
| 799 } | 836 } |
| 800 | 837 |
| 801 void test_getElement_constructor_unnamed() { | 838 void test_getElement_constructor_unnamed() { |
| 802 Source source = addSource("/lib.dart", r''' | 839 Source source = addSource( |
| 840 "/lib.dart", |
| 841 r''' |
| 803 class A { | 842 class A { |
| 804 A() {} | 843 A() {} |
| 805 }'''); | 844 }'''); |
| 806 _analyzeAll_assertFinished(); | 845 _analyzeAll_assertFinished(); |
| 807 LibraryElement library = context.computeLibraryElement(source); | 846 LibraryElement library = context.computeLibraryElement(source); |
| 808 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | 847 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
| 809 ConstructorElement constructor = classA.constructors[0]; | 848 ConstructorElement constructor = classA.constructors[0]; |
| 810 ElementLocation location = constructor.location; | 849 ElementLocation location = constructor.location; |
| 811 Element element = context.getElement(location); | 850 Element element = context.getElement(location); |
| 812 expect(element, same(constructor)); | 851 expect(element, same(constructor)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 AnalysisErrorInfo errorInfo = context.getErrors(source); | 887 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 849 expect(errorInfo, isNotNull); | 888 expect(errorInfo, isNotNull); |
| 850 List<AnalysisError> errors = errorInfo.errors; | 889 List<AnalysisError> errors = errorInfo.errors; |
| 851 expect(errors, hasLength(0)); | 890 expect(errors, hasLength(0)); |
| 852 context.computeErrors(source); | 891 context.computeErrors(source); |
| 853 errors = errorInfo.errors; | 892 errors = errorInfo.errors; |
| 854 expect(errors, hasLength(0)); | 893 expect(errors, hasLength(0)); |
| 855 } | 894 } |
| 856 | 895 |
| 857 void test_getErrors_html_some() { | 896 void test_getErrors_html_some() { |
| 858 Source source = addSource("/test.html", r''' | 897 Source source = addSource( |
| 898 "/test.html", |
| 899 r''' |
| 859 <html><head> | 900 <html><head> |
| 860 <script type='application/dart' src='test.dart'/> | 901 <script type='application/dart' src='test.dart'/> |
| 861 </head></html>'''); | 902 </head></html>'''); |
| 862 AnalysisErrorInfo errorInfo = context.getErrors(source); | 903 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 863 expect(errorInfo, isNotNull); | 904 expect(errorInfo, isNotNull); |
| 864 List<AnalysisError> errors = errorInfo.errors; | 905 List<AnalysisError> errors = errorInfo.errors; |
| 865 expect(errors, hasLength(0)); | 906 expect(errors, hasLength(0)); |
| 866 errors = context.computeErrors(source); | 907 errors = context.computeErrors(source); |
| 867 expect(errors, hasLength(3)); | 908 expect(errors, hasLength(3)); |
| 868 } | 909 } |
| 869 | 910 |
| 870 void test_getHtmlFilesReferencing_html() { | 911 void test_getHtmlFilesReferencing_html() { |
| 871 Source htmlSource = addSource("/test.html", r''' | 912 Source htmlSource = addSource( |
| 913 "/test.html", |
| 914 r''' |
| 872 <html><head> | 915 <html><head> |
| 873 <script type='application/dart' src='test.dart'/> | 916 <script type='application/dart' src='test.dart'/> |
| 874 <script type='application/dart' src='test.js'/> | 917 <script type='application/dart' src='test.js'/> |
| 875 </head></html>'''); | 918 </head></html>'''); |
| 876 Source librarySource = addSource("/test.dart", "library lib;"); | 919 Source librarySource = addSource("/test.dart", "library lib;"); |
| 877 Source secondHtmlSource = addSource("/test.html", "<html></html>"); | 920 Source secondHtmlSource = addSource("/test.html", "<html></html>"); |
| 878 context.computeLibraryElement(librarySource); | 921 context.computeLibraryElement(librarySource); |
| 879 List<Source> result = context.getHtmlFilesReferencing(secondHtmlSource); | 922 List<Source> result = context.getHtmlFilesReferencing(secondHtmlSource); |
| 880 expect(result, hasLength(0)); | 923 expect(result, hasLength(0)); |
| 881 context.parseHtmlDocument(htmlSource); | 924 context.parseHtmlDocument(htmlSource); |
| 882 result = context.getHtmlFilesReferencing(secondHtmlSource); | 925 result = context.getHtmlFilesReferencing(secondHtmlSource); |
| 883 expect(result, hasLength(0)); | 926 expect(result, hasLength(0)); |
| 884 } | 927 } |
| 885 | 928 |
| 886 void test_getHtmlFilesReferencing_library() { | 929 void test_getHtmlFilesReferencing_library() { |
| 887 Source htmlSource = addSource("/test.html", r''' | 930 Source htmlSource = addSource( |
| 931 "/test.html", |
| 932 r''' |
| 888 <!DOCTYPE html> | 933 <!DOCTYPE html> |
| 889 <html><head> | 934 <html><head> |
| 890 <script type='application/dart' src='test.dart'/> | 935 <script type='application/dart' src='test.dart'/> |
| 891 <script type='application/dart' src='test.js'/> | 936 <script type='application/dart' src='test.js'/> |
| 892 </head></html>'''); | 937 </head></html>'''); |
| 893 Source librarySource = addSource("/test.dart", "library lib;"); | 938 Source librarySource = addSource("/test.dart", "library lib;"); |
| 894 context.computeLibraryElement(librarySource); | 939 context.computeLibraryElement(librarySource); |
| 895 List<Source> result = context.getHtmlFilesReferencing(librarySource); | 940 List<Source> result = context.getHtmlFilesReferencing(librarySource); |
| 896 expect(result, hasLength(0)); | 941 expect(result, hasLength(0)); |
| 897 // Indirectly force the data to be computed. | 942 // Indirectly force the data to be computed. |
| 898 context.computeErrors(htmlSource); | 943 context.computeErrors(htmlSource); |
| 899 result = context.getHtmlFilesReferencing(librarySource); | 944 result = context.getHtmlFilesReferencing(librarySource); |
| 900 expect(result, hasLength(1)); | 945 expect(result, hasLength(1)); |
| 901 expect(result[0], htmlSource); | 946 expect(result[0], htmlSource); |
| 902 } | 947 } |
| 903 | 948 |
| 904 void test_getHtmlFilesReferencing_part() { | 949 void test_getHtmlFilesReferencing_part() { |
| 905 Source htmlSource = addSource("/test.html", r''' | 950 Source htmlSource = addSource( |
| 951 "/test.html", |
| 952 r''' |
| 906 <!DOCTYPE html> | 953 <!DOCTYPE html> |
| 907 <html><head> | 954 <html><head> |
| 908 <script type='application/dart' src='test.dart'/> | 955 <script type='application/dart' src='test.dart'/> |
| 909 <script type='application/dart' src='test.js'/> | 956 <script type='application/dart' src='test.js'/> |
| 910 </head></html>'''); | 957 </head></html>'''); |
| 911 Source librarySource = | 958 Source librarySource = |
| 912 addSource("/test.dart", "library lib; part 'part.dart';"); | 959 addSource("/test.dart", "library lib; part 'part.dart';"); |
| 913 Source partSource = addSource("/part.dart", "part of lib;"); | 960 Source partSource = addSource("/part.dart", "part of lib;"); |
| 914 context.computeLibraryElement(librarySource); | 961 context.computeLibraryElement(librarySource); |
| 915 List<Source> result = context.getHtmlFilesReferencing(partSource); | 962 List<Source> result = context.getHtmlFilesReferencing(partSource); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 context.computeKindOf(source); | 995 context.computeKindOf(source); |
| 949 expect(context.getKindOf(source), same(SourceKind.PART)); | 996 expect(context.getKindOf(source), same(SourceKind.PART)); |
| 950 } | 997 } |
| 951 | 998 |
| 952 void test_getKindOf_unknown() { | 999 void test_getKindOf_unknown() { |
| 953 Source source = addSource("/test.css", ""); | 1000 Source source = addSource("/test.css", ""); |
| 954 expect(context.getKindOf(source), same(SourceKind.UNKNOWN)); | 1001 expect(context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| 955 } | 1002 } |
| 956 | 1003 |
| 957 void test_getLaunchableClientLibrarySources_doesNotImportHtml() { | 1004 void test_getLaunchableClientLibrarySources_doesNotImportHtml() { |
| 958 Source source = addSource("/test.dart", r''' | 1005 Source source = addSource( |
| 1006 "/test.dart", |
| 1007 r''' |
| 959 main() {}'''); | 1008 main() {}'''); |
| 960 context.computeLibraryElement(source); | 1009 context.computeLibraryElement(source); |
| 961 List<Source> sources = context.launchableClientLibrarySources; | 1010 List<Source> sources = context.launchableClientLibrarySources; |
| 962 expect(sources, isEmpty); | 1011 expect(sources, isEmpty); |
| 963 } | 1012 } |
| 964 | 1013 |
| 965 void test_getLaunchableClientLibrarySources_importsHtml_explicitly() { | 1014 void test_getLaunchableClientLibrarySources_importsHtml_explicitly() { |
| 966 List<Source> sources = context.launchableClientLibrarySources; | 1015 List<Source> sources = context.launchableClientLibrarySources; |
| 967 expect(sources, isEmpty); | 1016 expect(sources, isEmpty); |
| 968 Source source = addSource("/test.dart", r''' | 1017 Source source = addSource( |
| 1018 "/test.dart", |
| 1019 r''' |
| 969 import 'dart:html'; | 1020 import 'dart:html'; |
| 970 main() {}'''); | 1021 main() {}'''); |
| 971 context.computeLibraryElement(source); | 1022 context.computeLibraryElement(source); |
| 972 sources = context.launchableClientLibrarySources; | 1023 sources = context.launchableClientLibrarySources; |
| 973 expect(sources, unorderedEquals([source])); | 1024 expect(sources, unorderedEquals([source])); |
| 974 } | 1025 } |
| 975 | 1026 |
| 976 void test_getLaunchableClientLibrarySources_importsHtml_implicitly() { | 1027 void test_getLaunchableClientLibrarySources_importsHtml_implicitly() { |
| 977 List<Source> sources = context.launchableClientLibrarySources; | 1028 List<Source> sources = context.launchableClientLibrarySources; |
| 978 expect(sources, isEmpty); | 1029 expect(sources, isEmpty); |
| 979 addSource("/a.dart", r''' | 1030 addSource( |
| 1031 "/a.dart", |
| 1032 r''' |
| 980 import 'dart:html'; | 1033 import 'dart:html'; |
| 981 '''); | 1034 '''); |
| 982 Source source = addSource("/test.dart", r''' | 1035 Source source = addSource( |
| 1036 "/test.dart", |
| 1037 r''' |
| 983 import 'a.dart'; | 1038 import 'a.dart'; |
| 984 main() {}'''); | 1039 main() {}'''); |
| 985 context.computeLibraryElement(source); | 1040 context.computeLibraryElement(source); |
| 986 sources = context.launchableClientLibrarySources; | 1041 sources = context.launchableClientLibrarySources; |
| 987 expect(sources, unorderedEquals([source])); | 1042 expect(sources, unorderedEquals([source])); |
| 988 } | 1043 } |
| 989 | 1044 |
| 990 void test_getLaunchableClientLibrarySources_importsHtml_implicitly2() { | 1045 void test_getLaunchableClientLibrarySources_importsHtml_implicitly2() { |
| 991 List<Source> sources = context.launchableClientLibrarySources; | 1046 List<Source> sources = context.launchableClientLibrarySources; |
| 992 expect(sources, isEmpty); | 1047 expect(sources, isEmpty); |
| 993 addSource("/a.dart", r''' | 1048 addSource( |
| 1049 "/a.dart", |
| 1050 r''' |
| 994 export 'dart:html'; | 1051 export 'dart:html'; |
| 995 '''); | 1052 '''); |
| 996 Source source = addSource("/test.dart", r''' | 1053 Source source = addSource( |
| 1054 "/test.dart", |
| 1055 r''' |
| 997 import 'a.dart'; | 1056 import 'a.dart'; |
| 998 main() {}'''); | 1057 main() {}'''); |
| 999 context.computeLibraryElement(source); | 1058 context.computeLibraryElement(source); |
| 1000 sources = context.launchableClientLibrarySources; | 1059 sources = context.launchableClientLibrarySources; |
| 1001 expect(sources, unorderedEquals([source])); | 1060 expect(sources, unorderedEquals([source])); |
| 1002 } | 1061 } |
| 1003 | 1062 |
| 1004 void test_getLaunchableServerLibrarySources() { | 1063 void test_getLaunchableServerLibrarySources() { |
| 1005 expect(context.launchableServerLibrarySources, isEmpty); | 1064 expect(context.launchableServerLibrarySources, isEmpty); |
| 1006 Source source = addSource("/test.dart", "main() {}"); | 1065 Source source = addSource("/test.dart", "main() {}"); |
| 1007 context.computeLibraryElement(source); | 1066 context.computeLibraryElement(source); |
| 1008 expect(context.launchableServerLibrarySources, unorderedEquals([source])); | 1067 expect(context.launchableServerLibrarySources, unorderedEquals([source])); |
| 1009 } | 1068 } |
| 1010 | 1069 |
| 1011 void test_getLaunchableServerLibrarySources_importsHtml_explicitly() { | 1070 void test_getLaunchableServerLibrarySources_importsHtml_explicitly() { |
| 1012 Source source = addSource("/test.dart", r''' | 1071 Source source = addSource( |
| 1072 "/test.dart", |
| 1073 r''' |
| 1013 import 'dart:html'; | 1074 import 'dart:html'; |
| 1014 main() {} | 1075 main() {} |
| 1015 '''); | 1076 '''); |
| 1016 context.computeLibraryElement(source); | 1077 context.computeLibraryElement(source); |
| 1017 expect(context.launchableServerLibrarySources, isEmpty); | 1078 expect(context.launchableServerLibrarySources, isEmpty); |
| 1018 } | 1079 } |
| 1019 | 1080 |
| 1020 void test_getLaunchableServerLibrarySources_importsHtml_implicitly() { | 1081 void test_getLaunchableServerLibrarySources_importsHtml_implicitly() { |
| 1021 addSource("/imports_html.dart", r''' | 1082 addSource( |
| 1083 "/imports_html.dart", |
| 1084 r''' |
| 1022 import 'dart:html'; | 1085 import 'dart:html'; |
| 1023 '''); | 1086 '''); |
| 1024 Source source = addSource("/test.dart", r''' | 1087 Source source = addSource( |
| 1088 "/test.dart", |
| 1089 r''' |
| 1025 import 'imports_html.dart'; | 1090 import 'imports_html.dart'; |
| 1026 main() {}'''); | 1091 main() {}'''); |
| 1027 context.computeLibraryElement(source); | 1092 context.computeLibraryElement(source); |
| 1028 expect(context.launchableServerLibrarySources, isEmpty); | 1093 expect(context.launchableServerLibrarySources, isEmpty); |
| 1029 } | 1094 } |
| 1030 | 1095 |
| 1031 void test_getLaunchableServerLibrarySources_noMain() { | 1096 void test_getLaunchableServerLibrarySources_noMain() { |
| 1032 Source source = addSource("/test.dart", ''); | 1097 Source source = addSource("/test.dart", ''); |
| 1033 context.computeLibraryElement(source); | 1098 context.computeLibraryElement(source); |
| 1034 expect(context.launchableServerLibrarySources, isEmpty); | 1099 expect(context.launchableServerLibrarySources, isEmpty); |
| 1035 } | 1100 } |
| 1036 | 1101 |
| 1037 void test_getLibrariesContaining() { | 1102 void test_getLibrariesContaining() { |
| 1038 Source librarySource = addSource("/lib.dart", r''' | 1103 Source librarySource = addSource( |
| 1104 "/lib.dart", |
| 1105 r''' |
| 1039 library lib; | 1106 library lib; |
| 1040 part 'part.dart';'''); | 1107 part 'part.dart';'''); |
| 1041 Source partSource = addSource("/part.dart", "part of lib;"); | 1108 Source partSource = addSource("/part.dart", "part of lib;"); |
| 1042 context.computeLibraryElement(librarySource); | 1109 context.computeLibraryElement(librarySource); |
| 1043 List<Source> result = context.getLibrariesContaining(librarySource); | 1110 List<Source> result = context.getLibrariesContaining(librarySource); |
| 1044 expect(result, hasLength(1)); | 1111 expect(result, hasLength(1)); |
| 1045 expect(result[0], librarySource); | 1112 expect(result[0], librarySource); |
| 1046 result = context.getLibrariesContaining(partSource); | 1113 result = context.getLibrariesContaining(partSource); |
| 1047 expect(result, hasLength(1)); | 1114 expect(result, hasLength(1)); |
| 1048 expect(result[0], librarySource); | 1115 expect(result[0], librarySource); |
| 1049 } | 1116 } |
| 1050 | 1117 |
| 1051 void test_getLibrariesDependingOn() { | 1118 void test_getLibrariesDependingOn() { |
| 1052 Source libASource = addSource("/libA.dart", "library libA;"); | 1119 Source libASource = addSource("/libA.dart", "library libA;"); |
| 1053 addSource("/libB.dart", "library libB;"); | 1120 addSource("/libB.dart", "library libB;"); |
| 1054 Source lib1Source = addSource("/lib1.dart", r''' | 1121 Source lib1Source = addSource( |
| 1122 "/lib1.dart", |
| 1123 r''' |
| 1055 library lib1; | 1124 library lib1; |
| 1056 import 'libA.dart'; | 1125 import 'libA.dart'; |
| 1057 export 'libB.dart';'''); | 1126 export 'libB.dart';'''); |
| 1058 Source lib2Source = addSource("/lib2.dart", r''' | 1127 Source lib2Source = addSource( |
| 1128 "/lib2.dart", |
| 1129 r''' |
| 1059 library lib2; | 1130 library lib2; |
| 1060 import 'libB.dart'; | 1131 import 'libB.dart'; |
| 1061 export 'libA.dart';'''); | 1132 export 'libA.dart';'''); |
| 1062 context.computeLibraryElement(lib1Source); | 1133 context.computeLibraryElement(lib1Source); |
| 1063 context.computeLibraryElement(lib2Source); | 1134 context.computeLibraryElement(lib2Source); |
| 1064 List<Source> result = context.getLibrariesDependingOn(libASource); | 1135 List<Source> result = context.getLibrariesDependingOn(libASource); |
| 1065 expect(result, unorderedEquals([lib1Source, lib2Source])); | 1136 expect(result, unorderedEquals([lib1Source, lib2Source])); |
| 1066 } | 1137 } |
| 1067 | 1138 |
| 1068 void test_getLibrariesReferencedFromHtml() { | 1139 void test_getLibrariesReferencedFromHtml() { |
| 1069 Source htmlSource = addSource("/test.html", r''' | 1140 Source htmlSource = addSource( |
| 1141 "/test.html", |
| 1142 r''' |
| 1070 <!DOCTYPE html> | 1143 <!DOCTYPE html> |
| 1071 <html><head> | 1144 <html><head> |
| 1072 <script type='application/dart' src='test.dart'/> | 1145 <script type='application/dart' src='test.dart'/> |
| 1073 <script type='application/dart' src='test.js'/> | 1146 <script type='application/dart' src='test.js'/> |
| 1074 </head></html>'''); | 1147 </head></html>'''); |
| 1075 Source librarySource = addSource("/test.dart", "library lib;"); | 1148 Source librarySource = addSource("/test.dart", "library lib;"); |
| 1076 context.computeLibraryElement(librarySource); | 1149 context.computeLibraryElement(librarySource); |
| 1077 // Indirectly force the data to be computed. | 1150 // Indirectly force the data to be computed. |
| 1078 context.computeErrors(htmlSource); | 1151 context.computeErrors(htmlSource); |
| 1079 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); | 1152 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); |
| 1080 expect(result, hasLength(1)); | 1153 expect(result, hasLength(1)); |
| 1081 expect(result[0], librarySource); | 1154 expect(result[0], librarySource); |
| 1082 } | 1155 } |
| 1083 | 1156 |
| 1084 void test_getLibrariesReferencedFromHtml_none() { | 1157 void test_getLibrariesReferencedFromHtml_none() { |
| 1085 Source htmlSource = addSource("/test.html", r''' | 1158 Source htmlSource = addSource( |
| 1159 "/test.html", |
| 1160 r''' |
| 1086 <html><head> | 1161 <html><head> |
| 1087 <script type='application/dart' src='test.js'/> | 1162 <script type='application/dart' src='test.js'/> |
| 1088 </head></html>'''); | 1163 </head></html>'''); |
| 1089 addSource("/test.dart", "library lib;"); | 1164 addSource("/test.dart", "library lib;"); |
| 1090 context.parseHtmlDocument(htmlSource); | 1165 context.parseHtmlDocument(htmlSource); |
| 1091 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); | 1166 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); |
| 1092 expect(result, hasLength(0)); | 1167 expect(result, hasLength(0)); |
| 1093 } | 1168 } |
| 1094 | 1169 |
| 1095 void test_getLibraryElement() { | 1170 void test_getLibraryElement() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1110 expect(sources, hasLength(originalLength + 1)); | 1185 expect(sources, hasLength(originalLength + 1)); |
| 1111 for (Source returnedSource in sources) { | 1186 for (Source returnedSource in sources) { |
| 1112 if (returnedSource == source) { | 1187 if (returnedSource == source) { |
| 1113 return; | 1188 return; |
| 1114 } | 1189 } |
| 1115 } | 1190 } |
| 1116 fail("The added source was not in the list of library sources"); | 1191 fail("The added source was not in the list of library sources"); |
| 1117 } | 1192 } |
| 1118 | 1193 |
| 1119 void test_getLineInfo() { | 1194 void test_getLineInfo() { |
| 1120 Source source = addSource("/test.dart", r''' | 1195 Source source = addSource( |
| 1196 "/test.dart", |
| 1197 r''' |
| 1121 library lib; | 1198 library lib; |
| 1122 | 1199 |
| 1123 main() {}'''); | 1200 main() {}'''); |
| 1124 LineInfo info = context.getLineInfo(source); | 1201 LineInfo info = context.getLineInfo(source); |
| 1125 expect(info, isNull); | 1202 expect(info, isNull); |
| 1126 context.parseCompilationUnit(source); | 1203 context.parseCompilationUnit(source); |
| 1127 info = context.getLineInfo(source); | 1204 info = context.getLineInfo(source); |
| 1128 expect(info, isNotNull); | 1205 expect(info, isNotNull); |
| 1129 } | 1206 } |
| 1130 | 1207 |
| 1131 void test_getModificationStamp_fromSource() { | 1208 void test_getModificationStamp_fromSource() { |
| 1132 int stamp = 42; | 1209 int stamp = 42; |
| 1133 expect(context.getModificationStamp( | 1210 expect( |
| 1134 new AnalysisContextImplTest_Source_getModificationStamp_fromSource( | 1211 context.getModificationStamp( |
| 1135 stamp)), stamp); | 1212 new AnalysisContextImplTest_Source_getModificationStamp_fromSource( |
| 1213 stamp)), |
| 1214 stamp); |
| 1136 } | 1215 } |
| 1137 | 1216 |
| 1138 void test_getModificationStamp_overridden() { | 1217 void test_getModificationStamp_overridden() { |
| 1139 int stamp = 42; | 1218 int stamp = 42; |
| 1140 Source source = | 1219 Source source = |
| 1141 new AnalysisContextImplTest_Source_getModificationStamp_overridden( | 1220 new AnalysisContextImplTest_Source_getModificationStamp_overridden( |
| 1142 stamp); | 1221 stamp); |
| 1143 context.setContents(source, ""); | 1222 context.setContents(source, ""); |
| 1144 expect(stamp != context.getModificationStamp(source), isTrue); | 1223 expect(stamp != context.getModificationStamp(source), isTrue); |
| 1145 } | 1224 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 Source sourceB = newSource('/b.dart', "library b;"); | 1323 Source sourceB = newSource('/b.dart', "library b;"); |
| 1245 ChangeSet changeSet = new ChangeSet(); | 1324 ChangeSet changeSet = new ChangeSet(); |
| 1246 changeSet.addedSource(sourceA); | 1325 changeSet.addedSource(sourceA); |
| 1247 context.applyChanges(changeSet); | 1326 context.applyChanges(changeSet); |
| 1248 context.computeErrors(sourceA); | 1327 context.computeErrors(sourceA); |
| 1249 await pumpEventQueue(); | 1328 await pumpEventQueue(); |
| 1250 listener.expectAnalyzed(sourceB); | 1329 listener.expectAnalyzed(sourceB); |
| 1251 } | 1330 } |
| 1252 | 1331 |
| 1253 void test_isClientLibrary_dart() { | 1332 void test_isClientLibrary_dart() { |
| 1254 Source source = addSource("/test.dart", r''' | 1333 Source source = addSource( |
| 1334 "/test.dart", |
| 1335 r''' |
| 1255 import 'dart:html'; | 1336 import 'dart:html'; |
| 1256 | 1337 |
| 1257 main() {}'''); | 1338 main() {}'''); |
| 1258 expect(context.isClientLibrary(source), isFalse); | 1339 expect(context.isClientLibrary(source), isFalse); |
| 1259 expect(context.isServerLibrary(source), isFalse); | 1340 expect(context.isServerLibrary(source), isFalse); |
| 1260 context.computeLibraryElement(source); | 1341 context.computeLibraryElement(source); |
| 1261 expect(context.isClientLibrary(source), isTrue); | 1342 expect(context.isClientLibrary(source), isTrue); |
| 1262 expect(context.isServerLibrary(source), isFalse); | 1343 expect(context.isServerLibrary(source), isFalse); |
| 1263 } | 1344 } |
| 1264 | 1345 |
| 1265 void test_isClientLibrary_html() { | 1346 void test_isClientLibrary_html() { |
| 1266 Source source = addSource("/test.html", "<html></html>"); | 1347 Source source = addSource("/test.html", "<html></html>"); |
| 1267 expect(context.isClientLibrary(source), isFalse); | 1348 expect(context.isClientLibrary(source), isFalse); |
| 1268 } | 1349 } |
| 1269 | 1350 |
| 1270 void test_isServerLibrary_dart() { | 1351 void test_isServerLibrary_dart() { |
| 1271 Source source = addSource("/test.dart", r''' | 1352 Source source = addSource( |
| 1353 "/test.dart", |
| 1354 r''' |
| 1272 library lib; | 1355 library lib; |
| 1273 | 1356 |
| 1274 main() {}'''); | 1357 main() {}'''); |
| 1275 expect(context.isClientLibrary(source), isFalse); | 1358 expect(context.isClientLibrary(source), isFalse); |
| 1276 expect(context.isServerLibrary(source), isFalse); | 1359 expect(context.isServerLibrary(source), isFalse); |
| 1277 context.computeLibraryElement(source); | 1360 context.computeLibraryElement(source); |
| 1278 expect(context.isClientLibrary(source), isFalse); | 1361 expect(context.isClientLibrary(source), isFalse); |
| 1279 expect(context.isServerLibrary(source), isTrue); | 1362 expect(context.isServerLibrary(source), isTrue); |
| 1280 } | 1363 } |
| 1281 | 1364 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 } | 1413 } |
| 1331 } | 1414 } |
| 1332 | 1415 |
| 1333 void test_parseHtmlDocument() { | 1416 void test_parseHtmlDocument() { |
| 1334 Source source = addSource("/lib.html", "<!DOCTYPE html><html></html>"); | 1417 Source source = addSource("/lib.html", "<!DOCTYPE html><html></html>"); |
| 1335 Document document = context.parseHtmlDocument(source); | 1418 Document document = context.parseHtmlDocument(source); |
| 1336 expect(document, isNotNull); | 1419 expect(document, isNotNull); |
| 1337 } | 1420 } |
| 1338 | 1421 |
| 1339 void test_parseHtmlUnit_resolveDirectives() { | 1422 void test_parseHtmlUnit_resolveDirectives() { |
| 1340 Source libSource = addSource("/lib.dart", r''' | 1423 Source libSource = addSource( |
| 1424 "/lib.dart", |
| 1425 r''' |
| 1341 library lib; | 1426 library lib; |
| 1342 class ClassA {}'''); | 1427 class ClassA {}'''); |
| 1343 Source source = addSource("/lib.html", r''' | 1428 Source source = addSource( |
| 1429 "/lib.html", |
| 1430 r''' |
| 1344 <!DOCTYPE html> | 1431 <!DOCTYPE html> |
| 1345 <html> | 1432 <html> |
| 1346 <head> | 1433 <head> |
| 1347 <script type='application/dart'> | 1434 <script type='application/dart'> |
| 1348 import 'lib.dart'; | 1435 import 'lib.dart'; |
| 1349 ClassA v = null; | 1436 ClassA v = null; |
| 1350 </script> | 1437 </script> |
| 1351 </head> | 1438 </head> |
| 1352 <body> | 1439 <body> |
| 1353 </body> | 1440 </body> |
| 1354 </html>'''); | 1441 </html>'''); |
| 1355 Document document = context.parseHtmlDocument(source); | 1442 Document document = context.parseHtmlDocument(source); |
| 1356 expect(document, isNotNull); | 1443 expect(document, isNotNull); |
| 1357 List<DartScript> scripts = context.computeResult(source, DART_SCRIPTS); | 1444 List<DartScript> scripts = context.computeResult(source, DART_SCRIPTS); |
| 1358 expect(scripts, hasLength(1)); | 1445 expect(scripts, hasLength(1)); |
| 1359 CompilationUnit unit = context.computeResult(scripts[0], PARSED_UNIT); | 1446 CompilationUnit unit = context.computeResult(scripts[0], PARSED_UNIT); |
| 1360 ImportDirective importNode = unit.directives[0] as ImportDirective; | 1447 ImportDirective importNode = unit.directives[0] as ImportDirective; |
| 1361 expect(importNode.uriContent, isNotNull); | 1448 expect(importNode.uriContent, isNotNull); |
| 1362 expect(importNode.source, libSource); | 1449 expect(importNode.source, libSource); |
| 1363 } | 1450 } |
| 1364 | 1451 |
| 1365 void test_performAnalysisTask_addPart() { | 1452 void test_performAnalysisTask_addPart() { |
| 1366 Source libSource = addSource("/lib.dart", r''' | 1453 Source libSource = addSource( |
| 1454 "/lib.dart", |
| 1455 r''' |
| 1367 library lib; | 1456 library lib; |
| 1368 part 'part.dart';'''); | 1457 part 'part.dart';'''); |
| 1369 // run all tasks without part | 1458 // run all tasks without part |
| 1370 _analyzeAll_assertFinished(); | 1459 _analyzeAll_assertFinished(); |
| 1371 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), | 1460 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), |
| 1372 isTrue, reason: "lib has errors"); | 1461 isTrue, |
| 1462 reason: "lib has errors"); |
| 1373 // add part and run all tasks | 1463 // add part and run all tasks |
| 1374 Source partSource = addSource("/part.dart", r''' | 1464 Source partSource = addSource( |
| 1465 "/part.dart", |
| 1466 r''' |
| 1375 part of lib; | 1467 part of lib; |
| 1376 '''); | 1468 '''); |
| 1377 _analyzeAll_assertFinished(); | 1469 _analyzeAll_assertFinished(); |
| 1378 // "libSource" should be here | 1470 // "libSource" should be here |
| 1379 List<Source> librariesWithPart = context.getLibrariesContaining(partSource); | 1471 List<Source> librariesWithPart = context.getLibrariesContaining(partSource); |
| 1380 expect(librariesWithPart, unorderedEquals([libSource])); | 1472 expect(librariesWithPart, unorderedEquals([libSource])); |
| 1381 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), | 1473 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), |
| 1382 isFalse, reason: "lib doesn't have errors"); | 1474 isFalse, |
| 1475 reason: "lib doesn't have errors"); |
| 1383 expect( | 1476 expect( |
| 1384 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 1477 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1385 reason: "part resolved"); | 1478 reason: "part resolved"); |
| 1386 } | 1479 } |
| 1387 | 1480 |
| 1388 void test_performAnalysisTask_changeLibraryContents() { | 1481 void test_performAnalysisTask_changeLibraryContents() { |
| 1389 Source libSource = | 1482 Source libSource = |
| 1390 addSource("/test.dart", "library lib; part 'test-part.dart';"); | 1483 addSource("/test.dart", "library lib; part 'test-part.dart';"); |
| 1391 Source partSource = addSource("/test-part.dart", "part of lib;"); | 1484 Source partSource = addSource("/test-part.dart", "part of lib;"); |
| 1392 _analyzeAll_assertFinished(); | 1485 _analyzeAll_assertFinished(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 1543 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1451 reason: "part changed 3"); | 1544 reason: "part changed 3"); |
| 1452 _analyzeAll_assertFinished(); | 1545 _analyzeAll_assertFinished(); |
| 1453 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1546 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1454 reason: "library resolved 3"); | 1547 reason: "library resolved 3"); |
| 1455 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 1548 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1456 reason: "part resolved 3"); | 1549 reason: "part resolved 3"); |
| 1457 } | 1550 } |
| 1458 | 1551 |
| 1459 void test_performAnalysisTask_changePartContents_makeItAPart() { | 1552 void test_performAnalysisTask_changePartContents_makeItAPart() { |
| 1460 Source libSource = addSource("/lib.dart", r''' | 1553 Source libSource = addSource( |
| 1554 "/lib.dart", |
| 1555 r''' |
| 1461 library lib; | 1556 library lib; |
| 1462 part 'part.dart'; | 1557 part 'part.dart'; |
| 1463 void f(x) {}'''); | 1558 void f(x) {}'''); |
| 1464 Source partSource = addSource("/part.dart", "void g() { f(null); }"); | 1559 Source partSource = addSource("/part.dart", "void g() { f(null); }"); |
| 1465 _analyzeAll_assertFinished(); | 1560 _analyzeAll_assertFinished(); |
| 1466 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1561 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1467 reason: "library resolved 1"); | 1562 reason: "library resolved 1"); |
| 1468 expect( | 1563 expect( |
| 1469 context.getResolvedCompilationUnit2(partSource, partSource), isNotNull, | 1564 context.getResolvedCompilationUnit2(partSource, partSource), isNotNull, |
| 1470 reason: "part resolved 1"); | 1565 reason: "part resolved 1"); |
| 1471 // update and analyze | 1566 // update and analyze |
| 1472 context.setContents(partSource, r''' | 1567 context.setContents( |
| 1568 partSource, |
| 1569 r''' |
| 1473 part of lib; | 1570 part of lib; |
| 1474 void g() { f(null); }'''); | 1571 void g() { f(null); }'''); |
| 1475 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | 1572 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1476 reason: "library changed 2"); | 1573 reason: "library changed 2"); |
| 1477 expect(context.getResolvedCompilationUnit2(partSource, partSource), isNull, | 1574 expect(context.getResolvedCompilationUnit2(partSource, partSource), isNull, |
| 1478 reason: "part changed 2"); | 1575 reason: "part changed 2"); |
| 1479 _analyzeAll_assertFinished(); | 1576 _analyzeAll_assertFinished(); |
| 1480 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1577 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1481 reason: "library resolved 2"); | 1578 reason: "library resolved 2"); |
| 1482 expect( | 1579 expect( |
| 1483 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 1580 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1484 reason: "part resolved 2"); | 1581 reason: "part resolved 2"); |
| 1485 expect(context.getErrors(libSource).errors, hasLength(0)); | 1582 expect(context.getErrors(libSource).errors, hasLength(0)); |
| 1486 expect(context.getErrors(partSource).errors, hasLength(0)); | 1583 expect(context.getErrors(partSource).errors, hasLength(0)); |
| 1487 } | 1584 } |
| 1488 | 1585 |
| 1489 /** | 1586 /** |
| 1490 * https://code.google.com/p/dart/issues/detail?id=12424 | 1587 * https://code.google.com/p/dart/issues/detail?id=12424 |
| 1491 */ | 1588 */ |
| 1492 void test_performAnalysisTask_changePartContents_makeItNotPart() { | 1589 void test_performAnalysisTask_changePartContents_makeItNotPart() { |
| 1493 Source libSource = addSource("/lib.dart", r''' | 1590 Source libSource = addSource( |
| 1591 "/lib.dart", |
| 1592 r''' |
| 1494 library lib; | 1593 library lib; |
| 1495 part 'part.dart'; | 1594 part 'part.dart'; |
| 1496 void f(x) {}'''); | 1595 void f(x) {}'''); |
| 1497 Source partSource = addSource("/part.dart", r''' | 1596 Source partSource = addSource( |
| 1597 "/part.dart", |
| 1598 r''' |
| 1498 part of lib; | 1599 part of lib; |
| 1499 void g() { f(null); }'''); | 1600 void g() { f(null); }'''); |
| 1500 _analyzeAll_assertFinished(); | 1601 _analyzeAll_assertFinished(); |
| 1501 expect(context.getErrors(libSource).errors, hasLength(0)); | 1602 expect(context.getErrors(libSource).errors, hasLength(0)); |
| 1502 expect(context.getErrors(partSource).errors, hasLength(0)); | 1603 expect(context.getErrors(partSource).errors, hasLength(0)); |
| 1503 // Remove 'part' directive, which should make "f(null)" an error. | 1604 // Remove 'part' directive, which should make "f(null)" an error. |
| 1504 context.setContents(partSource, r''' | 1605 context.setContents( |
| 1606 partSource, |
| 1607 r''' |
| 1505 //part of lib; | 1608 //part of lib; |
| 1506 void g() { f(null); }'''); | 1609 void g() { f(null); }'''); |
| 1507 _analyzeAll_assertFinished(); | 1610 _analyzeAll_assertFinished(); |
| 1508 expect(context.getErrors(libSource).errors.length != 0, isTrue); | 1611 expect(context.getErrors(libSource).errors.length != 0, isTrue); |
| 1509 } | 1612 } |
| 1510 | 1613 |
| 1511 void test_performAnalysisTask_changePartContents_noSemanticChanges() { | 1614 void test_performAnalysisTask_changePartContents_noSemanticChanges() { |
| 1512 Source libSource = | 1615 Source libSource = |
| 1513 addSource("/test.dart", "library lib; part 'test-part.dart';"); | 1616 addSource("/test.dart", "library lib; part 'test-part.dart';"); |
| 1514 Source partSource = addSource("/test-part.dart", "part of lib;"); | 1617 Source partSource = addSource("/test-part.dart", "part of lib;"); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 } | 1692 } |
| 1590 | 1693 |
| 1591 void test_performAnalysisTask_importedLibraryAdd() { | 1694 void test_performAnalysisTask_importedLibraryAdd() { |
| 1592 Source libASource = | 1695 Source libASource = |
| 1593 addSource("/libA.dart", "library libA; import 'libB.dart';"); | 1696 addSource("/libA.dart", "library libA; import 'libB.dart';"); |
| 1594 _analyzeAll_assertFinished(); | 1697 _analyzeAll_assertFinished(); |
| 1595 expect( | 1698 expect( |
| 1596 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | 1699 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1597 reason: "libA resolved 1"); | 1700 reason: "libA resolved 1"); |
| 1598 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), | 1701 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), |
| 1599 isTrue, reason: "libA has an error"); | 1702 isTrue, |
| 1703 reason: "libA has an error"); |
| 1600 // add libB.dart and analyze | 1704 // add libB.dart and analyze |
| 1601 Source libBSource = addSource("/libB.dart", "library libB;"); | 1705 Source libBSource = addSource("/libB.dart", "library libB;"); |
| 1602 _analyzeAll_assertFinished(); | 1706 _analyzeAll_assertFinished(); |
| 1603 expect( | 1707 expect( |
| 1604 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | 1708 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1605 reason: "libA resolved 2"); | 1709 reason: "libA resolved 2"); |
| 1606 expect( | 1710 expect( |
| 1607 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | 1711 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1608 reason: "libB resolved 2"); | 1712 reason: "libB resolved 2"); |
| 1609 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), | 1713 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), |
| 1610 isFalse, reason: "libA doesn't have errors"); | 1714 isFalse, |
| 1715 reason: "libA doesn't have errors"); |
| 1611 } | 1716 } |
| 1612 | 1717 |
| 1613 void test_performAnalysisTask_importedLibraryAdd_html() { | 1718 void test_performAnalysisTask_importedLibraryAdd_html() { |
| 1614 Source htmlSource = addSource("/page.html", r''' | 1719 Source htmlSource = addSource( |
| 1720 "/page.html", |
| 1721 r''' |
| 1615 <html><body><script type="application/dart"> | 1722 <html><body><script type="application/dart"> |
| 1616 import '/libB.dart'; | 1723 import '/libB.dart'; |
| 1617 main() {print('hello dart');} | 1724 main() {print('hello dart');} |
| 1618 </script></body></html>'''); | 1725 </script></body></html>'''); |
| 1619 _analyzeAll_assertFinished(); | 1726 _analyzeAll_assertFinished(); |
| 1620 context.computeErrors(htmlSource); | 1727 context.computeErrors(htmlSource); |
| 1621 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), | 1728 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), |
| 1622 isTrue, reason: "htmlSource has an error"); | 1729 isTrue, |
| 1730 reason: "htmlSource has an error"); |
| 1623 // add libB.dart and analyze | 1731 // add libB.dart and analyze |
| 1624 Source libBSource = addSource("/libB.dart", "library libB;"); | 1732 Source libBSource = addSource("/libB.dart", "library libB;"); |
| 1625 _analyzeAll_assertFinished(); | 1733 _analyzeAll_assertFinished(); |
| 1626 expect( | 1734 expect( |
| 1627 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | 1735 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1628 reason: "libB resolved 2"); | 1736 reason: "libB resolved 2"); |
| 1629 // TODO (danrubel) commented out to fix red bots | 1737 // TODO (danrubel) commented out to fix red bots |
| 1630 // context.computeErrors(htmlSource); | 1738 // context.computeErrors(htmlSource); |
| 1631 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); | 1739 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); |
| 1632 // expect( | 1740 // expect( |
| 1633 // !_hasAnalysisErrorWithErrorSeverity(errors), | 1741 // !_hasAnalysisErrorWithErrorSeverity(errors), |
| 1634 // isTrue, | 1742 // isTrue, |
| 1635 // reason: "htmlSource doesn't have errors"); | 1743 // reason: "htmlSource doesn't have errors"); |
| 1636 } | 1744 } |
| 1637 | 1745 |
| 1638 void test_performAnalysisTask_importedLibraryDelete() { | 1746 void test_performAnalysisTask_importedLibraryDelete() { |
| 1639 Source libASource = | 1747 Source libASource = |
| 1640 addSource("/libA.dart", "library libA; import 'libB.dart';"); | 1748 addSource("/libA.dart", "library libA; import 'libB.dart';"); |
| 1641 Source libBSource = addSource("/libB.dart", "library libB;"); | 1749 Source libBSource = addSource("/libB.dart", "library libB;"); |
| 1642 _analyzeAll_assertFinished(); | 1750 _analyzeAll_assertFinished(); |
| 1643 expect( | 1751 expect( |
| 1644 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | 1752 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1645 reason: "libA resolved 1"); | 1753 reason: "libA resolved 1"); |
| 1646 expect( | 1754 expect( |
| 1647 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | 1755 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1648 reason: "libB resolved 1"); | 1756 reason: "libB resolved 1"); |
| 1649 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), | 1757 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), |
| 1650 isTrue, reason: "libA doesn't have errors"); | 1758 isTrue, |
| 1759 reason: "libA doesn't have errors"); |
| 1651 // remove libB.dart and analyze | 1760 // remove libB.dart and analyze |
| 1652 _removeSource(libBSource); | 1761 _removeSource(libBSource); |
| 1653 _analyzeAll_assertFinished(); | 1762 _analyzeAll_assertFinished(); |
| 1654 expect( | 1763 expect( |
| 1655 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | 1764 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1656 reason: "libA resolved 2"); | 1765 reason: "libA resolved 2"); |
| 1657 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), | 1766 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), |
| 1658 isTrue, reason: "libA has an error"); | 1767 isTrue, |
| 1768 reason: "libA has an error"); |
| 1659 } | 1769 } |
| 1660 | 1770 |
| 1661 void test_performAnalysisTask_IOException() { | 1771 void test_performAnalysisTask_IOException() { |
| 1662 TestSource source = _addSourceWithException2("/test.dart", "library test;"); | 1772 TestSource source = _addSourceWithException2("/test.dart", "library test;"); |
| 1663 source.generateExceptionOnRead = false; | 1773 source.generateExceptionOnRead = false; |
| 1664 _analyzeAll_assertFinished(); | 1774 _analyzeAll_assertFinished(); |
| 1665 expect(source.readCount, 1); | 1775 expect(source.readCount, 1); |
| 1666 _changeSource(source, ""); | 1776 _changeSource(source, ""); |
| 1667 source.generateExceptionOnRead = true; | 1777 source.generateExceptionOnRead = true; |
| 1668 _analyzeAll_assertFinished(); | 1778 _analyzeAll_assertFinished(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 Source sourceA = | 1843 Source sourceA = |
| 1734 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); | 1844 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); |
| 1735 addSource("/libB.dart", "library libB; class B{}"); | 1845 addSource("/libB.dart", "library libB; class B{}"); |
| 1736 CompilationUnit compilationUnit = | 1846 CompilationUnit compilationUnit = |
| 1737 context.resolveCompilationUnit2(sourceA, sourceA); | 1847 context.resolveCompilationUnit2(sourceA, sourceA); |
| 1738 expect(compilationUnit, isNotNull); | 1848 expect(compilationUnit, isNotNull); |
| 1739 LibraryElement library = compilationUnit.element.library; | 1849 LibraryElement library = compilationUnit.element.library; |
| 1740 List<LibraryElement> importedLibraries = library.importedLibraries; | 1850 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 1741 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 1851 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 1742 List<LibraryElement> visibleLibraries = library.visibleLibraries; | 1852 List<LibraryElement> visibleLibraries = library.visibleLibraries; |
| 1743 assertNamedElements(visibleLibraries, [ | 1853 assertNamedElements(visibleLibraries, |
| 1744 "dart.core", | 1854 ["dart.core", "dart.async", "dart.math", "libA", "libB"]); |
| 1745 "dart.async", | |
| 1746 "dart.math", | |
| 1747 "libA", | |
| 1748 "libB" | |
| 1749 ]); | |
| 1750 } | 1855 } |
| 1751 | 1856 |
| 1752 void test_resolveCompilationUnit_import_relative_cyclic() { | 1857 void test_resolveCompilationUnit_import_relative_cyclic() { |
| 1753 Source sourceA = | 1858 Source sourceA = |
| 1754 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); | 1859 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); |
| 1755 addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}"); | 1860 addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}"); |
| 1756 CompilationUnit compilationUnit = | 1861 CompilationUnit compilationUnit = |
| 1757 context.resolveCompilationUnit2(sourceA, sourceA); | 1862 context.resolveCompilationUnit2(sourceA, sourceA); |
| 1758 expect(compilationUnit, isNotNull); | 1863 expect(compilationUnit, isNotNull); |
| 1759 LibraryElement library = compilationUnit.element.library; | 1864 LibraryElement library = compilationUnit.element.library; |
| 1760 List<LibraryElement> importedLibraries = library.importedLibraries; | 1865 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 1761 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 1866 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 1762 List<LibraryElement> visibleLibraries = library.visibleLibraries; | 1867 List<LibraryElement> visibleLibraries = library.visibleLibraries; |
| 1763 assertNamedElements(visibleLibraries, [ | 1868 assertNamedElements(visibleLibraries, |
| 1764 "dart.core", | 1869 ["dart.core", "dart.async", "dart.math", "libA", "libB"]); |
| 1765 "dart.async", | |
| 1766 "dart.math", | |
| 1767 "libA", | |
| 1768 "libB" | |
| 1769 ]); | |
| 1770 } | 1870 } |
| 1771 | 1871 |
| 1772 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { | 1872 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { |
| 1773 // _context = new _AnalysisContext_sourceChangeDuringResolution(); | 1873 // _context = new _AnalysisContext_sourceChangeDuringResolution(); |
| 1774 // AnalysisContextFactory.initContextWithCore(_context); | 1874 // AnalysisContextFactory.initContextWithCore(_context); |
| 1775 // _sourceFactory = _context.sourceFactory; | 1875 // _sourceFactory = _context.sourceFactory; |
| 1776 // Source source = _addSource("/lib.dart", "library lib;"); | 1876 // Source source = _addSource("/lib.dart", "library lib;"); |
| 1777 // CompilationUnit compilationUnit = | 1877 // CompilationUnit compilationUnit = |
| 1778 // _context.resolveCompilationUnit2(source, source); | 1878 // _context.resolveCompilationUnit2(source, source); |
| 1779 // expect(compilationUnit, isNotNull); | 1879 // expect(compilationUnit, isNotNull); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 context.getResolvedCompilationUnit2(partSource, librarySource), isNull); | 2003 context.getResolvedCompilationUnit2(partSource, librarySource), isNull); |
| 1904 return pumpEventQueue().then((_) { | 2004 return pumpEventQueue().then((_) { |
| 1905 listener.assertEvent(wereSourcesAdded: true); | 2005 listener.assertEvent(wereSourcesAdded: true); |
| 1906 listener.assertEvent(wereSourcesAdded: true); | 2006 listener.assertEvent(wereSourcesAdded: true); |
| 1907 listener.assertEvent(changedSources: [librarySource]); | 2007 listener.assertEvent(changedSources: [librarySource]); |
| 1908 listener.assertNoMoreEvents(); | 2008 listener.assertNoMoreEvents(); |
| 1909 }); | 2009 }); |
| 1910 } | 2010 } |
| 1911 | 2011 |
| 1912 void test_setContents_null() { | 2012 void test_setContents_null() { |
| 1913 Source librarySource = addSource("/lib.dart", r''' | 2013 Source librarySource = addSource( |
| 2014 "/lib.dart", |
| 2015 r''' |
| 1914 library lib; | 2016 library lib; |
| 1915 int a = 0;'''); | 2017 int a = 0;'''); |
| 1916 context.setContents(librarySource, '// different'); | 2018 context.setContents(librarySource, '// different'); |
| 1917 context.computeLibraryElement(librarySource); | 2019 context.computeLibraryElement(librarySource); |
| 1918 context.setContents(librarySource, null); | 2020 context.setContents(librarySource, null); |
| 1919 expect(context.getResolvedCompilationUnit2(librarySource, librarySource), | 2021 expect(context.getResolvedCompilationUnit2(librarySource, librarySource), |
| 1920 isNull); | 2022 isNull); |
| 1921 } | 2023 } |
| 1922 | 2024 |
| 1923 void test_setContents_unchanged_consistentModificationTime() { | 2025 void test_setContents_unchanged_consistentModificationTime() { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2090 context.analysisOptions = options; | 2192 context.analysisOptions = options; |
| 2091 } | 2193 } |
| 2092 | 2194 |
| 2093 @override | 2195 @override |
| 2094 void tearDown() { | 2196 void tearDown() { |
| 2095 AnalysisEngine.instance.limitInvalidationInTaskModel = false; | 2197 AnalysisEngine.instance.limitInvalidationInTaskModel = false; |
| 2096 super.tearDown(); | 2198 super.tearDown(); |
| 2097 } | 2199 } |
| 2098 | 2200 |
| 2099 void test_noChange_thenChange() { | 2201 void test_noChange_thenChange() { |
| 2100 Source sourceA = addSource("/a.dart", r''' | 2202 Source sourceA = addSource( |
| 2203 "/a.dart", |
| 2204 r''' |
| 2101 library lib_a; | 2205 library lib_a; |
| 2102 | 2206 |
| 2103 class A { | 2207 class A { |
| 2104 A(); | 2208 A(); |
| 2105 } | 2209 } |
| 2106 class B { | 2210 class B { |
| 2107 B(); | 2211 B(); |
| 2108 } | 2212 } |
| 2109 '''); | 2213 '''); |
| 2110 Source sourceB = addSource("/b.dart", r''' | 2214 Source sourceB = addSource( |
| 2215 "/b.dart", |
| 2216 r''' |
| 2111 library lib_b; | 2217 library lib_b; |
| 2112 import 'a.dart'; | 2218 import 'a.dart'; |
| 2113 main() { | 2219 main() { |
| 2114 new A(); | 2220 new A(); |
| 2115 } | 2221 } |
| 2116 '''); | 2222 '''); |
| 2117 _performPendingAnalysisTasks(); | 2223 _performPendingAnalysisTasks(); |
| 2118 expect(context.getErrors(sourceA).errors, hasLength(0)); | 2224 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2119 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2225 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2120 var unitA = context.getResolvedCompilationUnit2(sourceA, sourceA); | 2226 var unitA = context.getResolvedCompilationUnit2(sourceA, sourceA); |
| 2121 var unitElementA = unitA.element; | 2227 var unitElementA = unitA.element; |
| 2122 var libraryElementA = unitElementA.library; | 2228 var libraryElementA = unitElementA.library; |
| 2123 // Update a.dart, no declaration changes. | 2229 // Update a.dart, no declaration changes. |
| 2124 context.setContents(sourceA, r''' | 2230 context.setContents( |
| 2231 sourceA, |
| 2232 r''' |
| 2125 library lib_a; | 2233 library lib_a; |
| 2126 class A { | 2234 class A { |
| 2127 A(); | 2235 A(); |
| 2128 } | 2236 } |
| 2129 class B { | 2237 class B { |
| 2130 B(); | 2238 B(); |
| 2131 } | 2239 } |
| 2132 '''); | 2240 '''); |
| 2133 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2241 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2134 _assertValid(sourceB, LIBRARY_ERRORS_READY); | 2242 _assertValid(sourceB, LIBRARY_ERRORS_READY); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2147 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2255 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2148 // The a.dart's unit and element are the same. | 2256 // The a.dart's unit and element are the same. |
| 2149 { | 2257 { |
| 2150 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); | 2258 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2151 expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA)); | 2259 expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA)); |
| 2152 expect(unitA.element, same(unitElementA)); | 2260 expect(unitA.element, same(unitElementA)); |
| 2153 expect(unitElementA.library, same(libraryElementA)); | 2261 expect(unitElementA.library, same(libraryElementA)); |
| 2154 } | 2262 } |
| 2155 // Update a.dart, rename A to A2, invalidates b.dart, so | 2263 // Update a.dart, rename A to A2, invalidates b.dart, so |
| 2156 // we know that the previous update did not damage dependencies. | 2264 // we know that the previous update did not damage dependencies. |
| 2157 context.setContents(sourceA, r''' | 2265 context.setContents( |
| 2266 sourceA, |
| 2267 r''' |
| 2158 library lib_a; | 2268 library lib_a; |
| 2159 class A { | 2269 class A { |
| 2160 A(); | 2270 A(); |
| 2161 m() {} | 2271 m() {} |
| 2162 } | 2272 } |
| 2163 class B { | 2273 class B { |
| 2164 B(); | 2274 B(); |
| 2165 } | 2275 } |
| 2166 '''); | 2276 '''); |
| 2167 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2277 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2168 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2278 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2169 // The a.dart's unit and element are the same. | 2279 // The a.dart's unit and element are the same. |
| 2170 { | 2280 { |
| 2171 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); | 2281 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2172 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); | 2282 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); |
| 2173 expect(unitA.element, same(unitElementA)); | 2283 expect(unitA.element, same(unitElementA)); |
| 2174 expect(unitElementA.library, same(libraryElementA)); | 2284 expect(unitElementA.library, same(libraryElementA)); |
| 2175 } | 2285 } |
| 2176 // Analyze. | 2286 // Analyze. |
| 2177 _performPendingAnalysisTasks(); | 2287 _performPendingAnalysisTasks(); |
| 2178 expect(context.getErrors(sourceA).errors, hasLength(0)); | 2288 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2179 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2289 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2180 } | 2290 } |
| 2181 | 2291 |
| 2182 void test_unusedName() { | 2292 void test_unusedName() { |
| 2183 Source sourceA = addSource("/a.dart", r''' | 2293 Source sourceA = addSource( |
| 2294 "/a.dart", |
| 2295 r''' |
| 2184 library lib_a; | 2296 library lib_a; |
| 2185 class A {} | 2297 class A {} |
| 2186 class B {} | 2298 class B {} |
| 2187 class C {} | 2299 class C {} |
| 2188 '''); | 2300 '''); |
| 2189 Source sourceB = addSource("/b.dart", r''' | 2301 Source sourceB = addSource( |
| 2302 "/b.dart", |
| 2303 r''' |
| 2190 library lib_b; | 2304 library lib_b; |
| 2191 import 'a.dart'; | 2305 import 'a.dart'; |
| 2192 main() { | 2306 main() { |
| 2193 new A(); | 2307 new A(); |
| 2194 new C(); | 2308 new C(); |
| 2195 } | 2309 } |
| 2196 '''); | 2310 '''); |
| 2197 _performPendingAnalysisTasks(); | 2311 _performPendingAnalysisTasks(); |
| 2198 // Update A. | 2312 // Update A. |
| 2199 context.setContents(sourceA, r''' | 2313 context.setContents( |
| 2314 sourceA, |
| 2315 r''' |
| 2200 library lib_a; | 2316 library lib_a; |
| 2201 class A {} | 2317 class A {} |
| 2202 class B2 {} | 2318 class B2 {} |
| 2203 class C {} | 2319 class C {} |
| 2204 '''); | 2320 '''); |
| 2205 // Only a.dart is invalidated. | 2321 // Only a.dart is invalidated. |
| 2206 // Because b.dart does not use B, so it is valid. | 2322 // Because b.dart does not use B, so it is valid. |
| 2207 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2323 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2208 _assertValid(sourceB, LIBRARY_ERRORS_READY); | 2324 _assertValid(sourceB, LIBRARY_ERRORS_READY); |
| 2209 } | 2325 } |
| 2210 | 2326 |
| 2211 void test_usedName_directUser() { | 2327 void test_usedName_directUser() { |
| 2212 Source sourceA = addSource("/a.dart", r''' | 2328 Source sourceA = addSource( |
| 2329 "/a.dart", |
| 2330 r''' |
| 2213 library lib_a; | 2331 library lib_a; |
| 2214 class A {} | 2332 class A {} |
| 2215 class B {} | 2333 class B {} |
| 2216 class C {} | 2334 class C {} |
| 2217 '''); | 2335 '''); |
| 2218 Source sourceB = addSource("/b.dart", r''' | 2336 Source sourceB = addSource( |
| 2337 "/b.dart", |
| 2338 r''' |
| 2219 library lib_b; | 2339 library lib_b; |
| 2220 import 'a.dart'; | 2340 import 'a.dart'; |
| 2221 main() { | 2341 main() { |
| 2222 new A(); | 2342 new A(); |
| 2223 new C2(); | 2343 new C2(); |
| 2224 } | 2344 } |
| 2225 '''); | 2345 '''); |
| 2226 _performPendingAnalysisTasks(); | 2346 _performPendingAnalysisTasks(); |
| 2227 expect(context.getErrors(sourceB).errors, hasLength(1)); | 2347 expect(context.getErrors(sourceB).errors, hasLength(1)); |
| 2228 // Update a.dart, invalidates b.dart because it references "C2". | 2348 // Update a.dart, invalidates b.dart because it references "C2". |
| 2229 context.setContents(sourceA, r''' | 2349 context.setContents( |
| 2350 sourceA, |
| 2351 r''' |
| 2230 library lib_a; | 2352 library lib_a; |
| 2231 class A {} | 2353 class A {} |
| 2232 class B {} | 2354 class B {} |
| 2233 class C2 {} | 2355 class C2 {} |
| 2234 '''); | 2356 '''); |
| 2235 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2357 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2236 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2358 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2237 // Now b.dart is analyzed and the error is fixed. | 2359 // Now b.dart is analyzed and the error is fixed. |
| 2238 _performPendingAnalysisTasks(); | 2360 _performPendingAnalysisTasks(); |
| 2239 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2361 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2240 // Update a.dart, invalidates b.dart because it references "C". | 2362 // Update a.dart, invalidates b.dart because it references "C". |
| 2241 context.setContents(sourceA, r''' | 2363 context.setContents( |
| 2364 sourceA, |
| 2365 r''' |
| 2242 library lib_a; | 2366 library lib_a; |
| 2243 class A {} | 2367 class A {} |
| 2244 class B {} | 2368 class B {} |
| 2245 class C {} | 2369 class C {} |
| 2246 '''); | 2370 '''); |
| 2247 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2371 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2248 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2372 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2249 _performPendingAnalysisTasks(); | 2373 _performPendingAnalysisTasks(); |
| 2250 // Now b.dart is analyzed and it again has the error. | 2374 // Now b.dart is analyzed and it again has the error. |
| 2251 expect(context.getErrors(sourceB).errors, hasLength(1)); | 2375 expect(context.getErrors(sourceB).errors, hasLength(1)); |
| 2252 } | 2376 } |
| 2253 | 2377 |
| 2254 void test_usedName_directUser_withIncremental() { | 2378 void test_usedName_directUser_withIncremental() { |
| 2255 Source sourceA = addSource("/a.dart", r''' | 2379 Source sourceA = addSource( |
| 2380 "/a.dart", |
| 2381 r''' |
| 2256 library lib_a; | 2382 library lib_a; |
| 2257 class A { | 2383 class A { |
| 2258 m() {} | 2384 m() {} |
| 2259 } | 2385 } |
| 2260 '''); | 2386 '''); |
| 2261 Source sourceB = addSource("/b.dart", r''' | 2387 Source sourceB = addSource( |
| 2388 "/b.dart", |
| 2389 r''' |
| 2262 library lib_b; | 2390 library lib_b; |
| 2263 import 'a.dart'; | 2391 import 'a.dart'; |
| 2264 main() { | 2392 main() { |
| 2265 A a = new A(); | 2393 A a = new A(); |
| 2266 a.m(); | 2394 a.m(); |
| 2267 } | 2395 } |
| 2268 '''); | 2396 '''); |
| 2269 _performPendingAnalysisTasks(); | 2397 _performPendingAnalysisTasks(); |
| 2270 // Update A. | 2398 // Update A. |
| 2271 context.setContents(sourceA, r''' | 2399 context.setContents( |
| 2400 sourceA, |
| 2401 r''' |
| 2272 library lib_a; | 2402 library lib_a; |
| 2273 class A { | 2403 class A { |
| 2274 m2() {} | 2404 m2() {} |
| 2275 } | 2405 } |
| 2276 '''); | 2406 '''); |
| 2277 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2407 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2278 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2408 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2279 } | 2409 } |
| 2280 | 2410 |
| 2281 void test_usedName_indirectUser() { | 2411 void test_usedName_indirectUser() { |
| 2282 Source sourceA = addSource("/a.dart", r''' | 2412 Source sourceA = addSource( |
| 2413 "/a.dart", |
| 2414 r''' |
| 2283 library lib_a; | 2415 library lib_a; |
| 2284 class A { | 2416 class A { |
| 2285 m() {} | 2417 m() {} |
| 2286 } | 2418 } |
| 2287 '''); | 2419 '''); |
| 2288 Source sourceB = addSource("/b.dart", r''' | 2420 Source sourceB = addSource( |
| 2421 "/b.dart", |
| 2422 r''' |
| 2289 library lib_b; | 2423 library lib_b; |
| 2290 import 'a.dart'; | 2424 import 'a.dart'; |
| 2291 class B extends A {} | 2425 class B extends A {} |
| 2292 '''); | 2426 '''); |
| 2293 Source sourceC = addSource("/c.dart", r''' | 2427 Source sourceC = addSource( |
| 2428 "/c.dart", |
| 2429 r''' |
| 2294 library lib_c; | 2430 library lib_c; |
| 2295 import 'b.dart'; | 2431 import 'b.dart'; |
| 2296 class C extends B { | 2432 class C extends B { |
| 2297 main() { | 2433 main() { |
| 2298 m(); | 2434 m(); |
| 2299 } | 2435 } |
| 2300 } | 2436 } |
| 2301 '''); | 2437 '''); |
| 2302 // No errors, "A.m" exists. | 2438 // No errors, "A.m" exists. |
| 2303 _performPendingAnalysisTasks(); | 2439 _performPendingAnalysisTasks(); |
| 2304 expect(context.getErrors(sourceC).errors, hasLength(0)); | 2440 expect(context.getErrors(sourceC).errors, hasLength(0)); |
| 2305 // Replace "A.m" with "A.m2", invalidate both b.dart and c.dart files. | 2441 // Replace "A.m" with "A.m2", invalidate both b.dart and c.dart files. |
| 2306 context.setContents(sourceA, r''' | 2442 context.setContents( |
| 2443 sourceA, |
| 2444 r''' |
| 2307 library lib_a; | 2445 library lib_a; |
| 2308 class A { | 2446 class A { |
| 2309 m2() {} | 2447 m2() {} |
| 2310 } | 2448 } |
| 2311 '''); | 2449 '''); |
| 2312 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2450 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2313 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2451 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2314 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); | 2452 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); |
| 2315 // There is an error in c.dart, "A.m" does not exist. | 2453 // There is an error in c.dart, "A.m" does not exist. |
| 2316 _performPendingAnalysisTasks(); | 2454 _performPendingAnalysisTasks(); |
| 2317 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2455 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2318 expect(context.getErrors(sourceC).errors, hasLength(1)); | 2456 expect(context.getErrors(sourceC).errors, hasLength(1)); |
| 2319 // Restore "A.m", invalidate both b.dart and c.dart files. | 2457 // Restore "A.m", invalidate both b.dart and c.dart files. |
| 2320 context.setContents(sourceA, r''' | 2458 context.setContents( |
| 2459 sourceA, |
| 2460 r''' |
| 2321 library lib_a; | 2461 library lib_a; |
| 2322 class A { | 2462 class A { |
| 2323 m() {} | 2463 m() {} |
| 2324 } | 2464 } |
| 2325 '''); | 2465 '''); |
| 2326 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2466 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2327 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2467 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2328 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); | 2468 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); |
| 2329 // No errors, "A.m" exists. | 2469 // No errors, "A.m" exists. |
| 2330 _performPendingAnalysisTasks(); | 2470 _performPendingAnalysisTasks(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2350 } | 2490 } |
| 2351 } | 2491 } |
| 2352 | 2492 |
| 2353 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2493 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 2354 implements SourceContainer { | 2494 implements SourceContainer { |
| 2355 Source libB; | 2495 Source libB; |
| 2356 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2496 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 2357 @override | 2497 @override |
| 2358 bool contains(Source source) => source == libB; | 2498 bool contains(Source source) => source == libB; |
| 2359 } | 2499 } |
| OLD | NEW |