| 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.services.completion.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 376 |
| 377 CompletionSuggestion assertSuggestImportedClass(String name, | 377 CompletionSuggestion assertSuggestImportedClass(String name, |
| 378 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 378 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 379 if (computer is ImportedComputer) { | 379 if (computer is ImportedComputer) { |
| 380 return assertSuggestClass(name, relevance); | 380 return assertSuggestClass(name, relevance); |
| 381 } else { | 381 } else { |
| 382 return assertNotSuggested(name); | 382 return assertNotSuggested(name); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, |
| 387 String returnType, [CompletionRelevance relevance = |
| 388 CompletionRelevance.DEFAULT]) { |
| 389 if (computer is ImportedComputer) { |
| 390 return assertSuggestTopLevelVar(name, returnType, relevance); |
| 391 } else { |
| 392 return assertNotSuggested(name); |
| 393 } |
| 394 } |
| 395 |
| 396 CompletionSuggestion assertSuggestImportedFunction(String name, |
| 397 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 398 CompletionRelevance.DEFAULT]) { |
| 399 if (computer is ImportedComputer) { |
| 400 return assertSuggestFunction(name, returnType, isDeprecated, relevance); |
| 401 } else { |
| 402 return assertNotSuggested(name); |
| 403 } |
| 404 } |
| 405 |
| 386 CompletionSuggestion assertSuggestInvocationClass(String name, | 406 CompletionSuggestion assertSuggestInvocationClass(String name, |
| 387 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 407 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 388 if (computer is InvocationComputer) { | 408 if (computer is InvocationComputer) { |
| 389 return assertSuggestClass(name, relevance); | 409 return assertSuggestClass(name, relevance); |
| 390 } else { | 410 } else { |
| 391 return assertNotSuggested(name); | 411 return assertNotSuggested(name); |
| 392 } | 412 } |
| 393 } | 413 } |
| 394 | 414 |
| 395 CompletionSuggestion assertSuggestInvocationGetter(String name, | 415 CompletionSuggestion assertSuggestInvocationGetter(String name, |
| 396 String returnType, [CompletionRelevance relevance = | 416 String returnType, [CompletionRelevance relevance = |
| 397 CompletionRelevance.DEFAULT]) { | 417 CompletionRelevance.DEFAULT]) { |
| 398 if (computer is InvocationComputer) { | 418 if (computer is InvocationComputer) { |
| 399 return assertSuggestGetter(name, returnType, relevance); | 419 return assertSuggestGetter(name, returnType, relevance); |
| 400 } else { | 420 } else { |
| 401 return assertNotSuggested(name); | 421 return assertNotSuggested(name); |
| 402 } | 422 } |
| 403 } | 423 } |
| 404 | 424 |
| 405 CompletionSuggestion assertSuggestInvocationTopLevelVar(String name, | |
| 406 String returnType, [CompletionRelevance relevance = | |
| 407 CompletionRelevance.DEFAULT]) { | |
| 408 if (computer is InvocationComputer) { | |
| 409 return assertSuggestTopLevelVar(name, returnType, relevance); | |
| 410 } else { | |
| 411 return assertNotSuggested(name); | |
| 412 } | |
| 413 } | |
| 414 | |
| 415 CompletionSuggestion assertSuggestInvocationMethod(String name, | 425 CompletionSuggestion assertSuggestInvocationMethod(String name, |
| 416 String declaringType, String returnType, [CompletionRelevance relevance = | 426 String declaringType, String returnType, [CompletionRelevance relevance = |
| 417 CompletionRelevance.DEFAULT]) { | 427 CompletionRelevance.DEFAULT]) { |
| 418 if (computer is InvocationComputer) { | 428 if (computer is InvocationComputer) { |
| 419 return assertSuggestMethod(name, declaringType, returnType, relevance); | 429 return assertSuggestMethod(name, declaringType, returnType, relevance); |
| 420 } else { | 430 } else { |
| 421 return assertNotSuggested(name); | 431 return assertNotSuggested(name); |
| 422 } | |
| 423 } | |
| 424 | |
| 425 CompletionSuggestion assertSuggestLocalMethod(String name, | |
| 426 String declaringType, String returnType, [CompletionRelevance relevance = | |
| 427 CompletionRelevance.DEFAULT]) { | |
| 428 if (computer is LocalComputer) { | |
| 429 return assertSuggestMethod(name, declaringType, returnType, relevance); | |
| 430 } else { | |
| 431 return assertNotSuggested(name); | |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 | 434 |
| 435 CompletionSuggestion assertSuggestInvocationSetter(String name, | 435 CompletionSuggestion assertSuggestInvocationSetter(String name, |
| 436 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 436 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 437 if (computer is InvocationComputer) { | 437 if (computer is InvocationComputer) { |
| 438 return assertSuggestSetter(name); | 438 return assertSuggestSetter(name); |
| 439 } else { | 439 } else { |
| 440 return assertNotSuggested(name); | 440 return assertNotSuggested(name); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 CompletionSuggestion assertSuggestInvocationTopLevelVar(String name, |
| 445 String returnType, [CompletionRelevance relevance = |
| 446 CompletionRelevance.DEFAULT]) { |
| 447 if (computer is InvocationComputer) { |
| 448 return assertSuggestTopLevelVar(name, returnType, relevance); |
| 449 } else { |
| 450 return assertNotSuggested(name); |
| 451 } |
| 452 } |
| 453 |
| 444 CompletionSuggestion assertSuggestLocalClass(String name, | 454 CompletionSuggestion assertSuggestLocalClass(String name, |
| 445 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 455 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 446 if (computer is LocalComputer) { | 456 if (computer is LocalComputer) { |
| 447 return assertSuggestClass(name, relevance); | 457 return assertSuggestClass(name, relevance); |
| 448 } else { | 458 } else { |
| 449 return assertNotSuggested(name); | 459 return assertNotSuggested(name); |
| 450 } | 460 } |
| 451 } | 461 } |
| 452 | 462 |
| 463 CompletionSuggestion assertSuggestLocalMethod(String name, |
| 464 String declaringType, String returnType, [CompletionRelevance relevance = |
| 465 CompletionRelevance.DEFAULT]) { |
| 466 if (computer is LocalComputer) { |
| 467 return assertSuggestMethod(name, declaringType, returnType, relevance); |
| 468 } else { |
| 469 return assertNotSuggested(name); |
| 470 } |
| 471 } |
| 472 |
| 453 test_Block() { | 473 test_Block() { |
| 454 // Block BlockFunctionBody MethodDeclaration | 474 // Block BlockFunctionBody MethodDeclaration |
| 455 addSource('/testAB.dart', ''' | 475 addSource('/testAB.dart', ''' |
| 456 class A {int x;} | 476 class A {int x;} |
| 457 class _B { }'''); | 477 class _B { }'''); |
| 458 addSource('/testCD.dart', ''' | 478 addSource('/testCD.dart', ''' |
| 459 class C { } | 479 class C { } |
| 460 class D { }'''); | 480 class D { }'''); |
| 461 addSource('/testEEF.dart', ''' | 481 addSource('/testEEF.dart', ''' |
| 462 class EE { } | 482 class EE { } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return computeFull(true).then((_) { | 573 return computeFull(true).then((_) { |
| 554 assertNotSuggested('b'); | 574 assertNotSuggested('b'); |
| 555 assertNotSuggested('_c'); | 575 assertNotSuggested('_c'); |
| 556 assertSuggestLocalVariable('a', 'A'); | 576 assertSuggestLocalVariable('a', 'A'); |
| 557 assertSuggestLocalClass('A'); | 577 assertSuggestLocalClass('A'); |
| 558 assertSuggestLocalClass('X'); | 578 assertSuggestLocalClass('X'); |
| 559 assertSuggestImportedClass('Object'); | 579 assertSuggestImportedClass('Object'); |
| 560 }); | 580 }); |
| 561 } | 581 } |
| 562 | 582 |
| 583 test_Combinator_hide() { |
| 584 // SimpleIdentifier HideCombinator ImportDirective |
| 585 addSource('/testAB.dart', ''' |
| 586 library libAB; |
| 587 part '/partAB.dart'; |
| 588 class A { } |
| 589 class B { }'''); |
| 590 addSource('/partAB.dart', ''' |
| 591 part of libAB; |
| 592 var T1; |
| 593 PB F1() => new PB(); |
| 594 class PB { }'''); |
| 595 addSource('/testCD.dart', ''' |
| 596 class C { } |
| 597 class D { }'''); |
| 598 addTestSource(''' |
| 599 import "/testAB.dart" hide ^; |
| 600 import "/testCD.dart"; |
| 601 class X {}'''); |
| 602 computeFast(); |
| 603 return computeFull(true).then((_) { |
| 604 assertSuggestImportedClass('A'); |
| 605 assertSuggestImportedClass('B'); |
| 606 assertSuggestImportedClass('PB'); |
| 607 assertSuggestImportedTopLevelVar('T1', null); |
| 608 assertSuggestImportedFunction('F1', 'PB'); |
| 609 assertNotSuggested('C'); |
| 610 assertNotSuggested('D'); |
| 611 assertNotSuggested('X'); |
| 612 assertNotSuggested('Object'); |
| 613 }); |
| 614 } |
| 615 |
| 616 test_Combinator_show() { |
| 617 // SimpleIdentifier HideCombinator ImportDirective |
| 618 addSource('/testAB.dart', ''' |
| 619 library libAB; |
| 620 part '/partAB.dart'; |
| 621 class A { } |
| 622 class B { }'''); |
| 623 addSource('/partAB.dart', ''' |
| 624 part of libAB; |
| 625 var T1; |
| 626 PB F1() => new PB(); |
| 627 class PB { }'''); |
| 628 addSource('/testCD.dart', ''' |
| 629 class C { } |
| 630 class D { }'''); |
| 631 addTestSource(''' |
| 632 import "/testAB.dart" show ^; |
| 633 import "/testCD.dart"; |
| 634 class X {}'''); |
| 635 computeFast(); |
| 636 return computeFull(true).then((_) { |
| 637 assertSuggestImportedClass('A'); |
| 638 assertSuggestImportedClass('B'); |
| 639 assertSuggestImportedClass('PB'); |
| 640 assertSuggestImportedTopLevelVar('T1', null); |
| 641 assertSuggestImportedFunction('F1', 'PB'); |
| 642 assertNotSuggested('C'); |
| 643 assertNotSuggested('D'); |
| 644 assertNotSuggested('X'); |
| 645 assertNotSuggested('Object'); |
| 646 }); |
| 647 } |
| 648 |
| 563 test_ConstructorName_importedClass() { | 649 test_ConstructorName_importedClass() { |
| 564 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 650 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
| 565 // InstanceCreationExpression | 651 // InstanceCreationExpression |
| 566 addSource('/testB.dart', ''' | 652 addSource('/testB.dart', ''' |
| 567 lib B; | 653 lib B; |
| 568 int T1; | 654 int T1; |
| 569 F1() { } | 655 F1() { } |
| 570 class X {X.c(); X._d(); z() {}}'''); | 656 class X {X.c(); X._d(); z() {}}'''); |
| 571 addTestSource(''' | 657 addTestSource(''' |
| 572 import "/testB.dart"; | 658 import "/testB.dart"; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 addTestSource(''' | 959 addTestSource(''' |
| 874 import "/testB.dart"; | 960 import "/testB.dart"; |
| 875 class Y {Y.c(); Y._d(); z() {}} | 961 class Y {Y.c(); Y._d(); z() {}} |
| 876 main() {var ^}'''); | 962 main() {var ^}'''); |
| 877 computeFast(); | 963 computeFast(); |
| 878 return computeFull(true).then((_) { | 964 return computeFull(true).then((_) { |
| 879 assertNoSuggestions(); | 965 assertNoSuggestions(); |
| 880 }); | 966 }); |
| 881 } | 967 } |
| 882 } | 968 } |
| OLD | NEW |