| 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 assertSuggestInvocationClass(String name, |
| 387 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 388 if (computer is InvocationComputer) { |
| 389 return assertSuggestClass(name, relevance); |
| 390 } else { |
| 391 return assertNotSuggested(name); |
| 392 } |
| 393 } |
| 394 |
| 386 CompletionSuggestion assertSuggestInvocationGetter(String name, | 395 CompletionSuggestion assertSuggestInvocationGetter(String name, |
| 387 String returnType, [CompletionRelevance relevance = | 396 String returnType, [CompletionRelevance relevance = |
| 388 CompletionRelevance.DEFAULT]) { | 397 CompletionRelevance.DEFAULT]) { |
| 389 if (computer is InvocationComputer) { | 398 if (computer is InvocationComputer) { |
| 390 return assertSuggestGetter(name, returnType, relevance); | 399 return assertSuggestGetter(name, returnType, relevance); |
| 391 } else { | 400 } else { |
| 392 return null; | 401 return assertNotSuggested(name); |
| 393 } | 402 } |
| 394 } | 403 } |
| 395 | 404 |
| 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, |
| 416 String declaringType, String returnType, [CompletionRelevance relevance = |
| 417 CompletionRelevance.DEFAULT]) { |
| 418 if (computer is InvocationComputer) { |
| 419 return assertSuggestMethod(name, declaringType, returnType, relevance); |
| 420 } else { |
| 421 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 } |
| 433 } |
| 434 |
| 435 CompletionSuggestion assertSuggestInvocationSetter(String name, |
| 436 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 437 if (computer is InvocationComputer) { |
| 438 return assertSuggestSetter(name); |
| 439 } else { |
| 440 return assertNotSuggested(name); |
| 441 } |
| 442 } |
| 443 |
| 396 CompletionSuggestion assertSuggestLocalClass(String name, | 444 CompletionSuggestion assertSuggestLocalClass(String name, |
| 397 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 445 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 398 if (computer is LocalComputer) { | 446 if (computer is LocalComputer) { |
| 399 return assertSuggestClass(name, relevance); | 447 return assertSuggestClass(name, relevance); |
| 400 } else { | 448 } else { |
| 401 return assertNotSuggested(name); | 449 return assertNotSuggested(name); |
| 402 } | 450 } |
| 403 } | 451 } |
| 404 | 452 |
| 405 test_Block() { | 453 test_Block() { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 assertNotSuggested('f'); | 623 assertNotSuggested('f'); |
| 576 assertNotSuggested('x'); | 624 assertNotSuggested('x'); |
| 577 assertNotSuggested('foo'); | 625 assertNotSuggested('foo'); |
| 578 assertNotSuggested('F1'); | 626 assertNotSuggested('F1'); |
| 579 assertNotSuggested('F2'); | 627 assertNotSuggested('F2'); |
| 580 assertNotSuggested('T1'); | 628 assertNotSuggested('T1'); |
| 581 assertNotSuggested('T2'); | 629 assertNotSuggested('T2'); |
| 582 }); | 630 }); |
| 583 } | 631 } |
| 584 | 632 |
| 585 test_IsExpression_type() { | 633 test_IsExpression() { |
| 586 // SimpleIdentifier TypeName IsExpression IfStatement | 634 // SimpleIdentifier TypeName IsExpression IfStatement |
| 587 addSource('/testB.dart', ''' | 635 addSource('/testB.dart', ''' |
| 588 lib B; | 636 lib B; |
| 589 foo() { } | 637 foo() { } |
| 590 class X {X.c(); X._d(); z() {}}'''); | 638 class X {X.c(); X._d(); z() {}}'''); |
| 591 addTestSource(''' | 639 addTestSource(''' |
| 592 import "/testB.dart"; | 640 import "/testB.dart"; |
| 593 class Y {Y.c(); Y._d(); z() {}} | 641 class Y {Y.c(); Y._d(); z() {}} |
| 594 main() {var x; if (x is ^) { }}'''); | 642 main() {var x; if (x is ^) { }}'''); |
| 595 computeFast(); | 643 computeFast(); |
| 596 return computeFull(true).then((_) { | 644 return computeFull(true).then((_) { |
| 597 assertSuggestImportedClass('X'); | 645 assertSuggestImportedClass('X'); |
| 598 assertSuggestLocalClass('Y'); | 646 assertSuggestLocalClass('Y'); |
| 599 assertNotSuggested('x'); | 647 assertNotSuggested('x'); |
| 600 assertNotSuggested('main'); | 648 assertNotSuggested('main'); |
| 601 assertNotSuggested('foo'); | 649 assertNotSuggested('foo'); |
| 602 }); | 650 }); |
| 603 } | 651 } |
| 604 | 652 |
| 605 test_VariableDeclaration_name() { | 653 test_PrefixedIdentifier_class_imported() { |
| 606 // SimpleIdentifier VariableDeclaration VariableDeclarationList | 654 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 607 // VariableDeclarationStatement Block | |
| 608 addSource('/testB.dart', ''' | 655 addSource('/testB.dart', ''' |
| 609 lib B; | 656 lib B; |
| 610 foo() { } | 657 class I {X get f => new A();get _g => new A();} |
| 611 class _B { } | 658 class A implements I { |
| 612 class X {X.c(); X._d(); z() {}}'''); | 659 var b; X _c; |
| 660 X get d => new A();get _e => new A(); |
| 661 set s1(I x) {} set _s2(I x) {} |
| 662 m(X x) {} I _n(X x) {}} |
| 663 class X{}'''); |
| 613 addTestSource(''' | 664 addTestSource(''' |
| 614 import "/testB.dart"; | 665 import "/testB.dart"; |
| 615 class Y {Y.c(); Y._d(); z() {}} | 666 main() {A a; a.^}'''); |
| 616 main() {var ^}'''); | 667 computeFast(); |
| 668 return computeFull(true).then((_) { |
| 669 assertSuggestInvocationGetter('b', null); |
| 670 assertNotSuggested('_c'); |
| 671 assertSuggestInvocationGetter('d', 'X'); |
| 672 assertNotSuggested('_e'); |
| 673 assertSuggestInvocationGetter('f', 'X'); |
| 674 assertNotSuggested('_g'); |
| 675 assertSuggestInvocationSetter('s1'); |
| 676 assertNotSuggested('_s2'); |
| 677 assertSuggestInvocationMethod('m', 'A', null); |
| 678 assertNotSuggested('_n'); |
| 679 assertNotSuggested('a'); |
| 680 assertNotSuggested('A'); |
| 681 assertNotSuggested('X'); |
| 682 assertNotSuggested('Object'); |
| 683 }); |
| 684 } |
| 685 |
| 686 test_PrefixedIdentifier_class_local() { |
| 687 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 688 addTestSource(''' |
| 689 main() {A a; a.^} |
| 690 class I {X get f => new A();get _g => new A();} |
| 691 class A implements I { |
| 692 var b; X _c; |
| 693 X get d => new A();get _e => new A(); |
| 694 set s1(I x) {} set _s2(I x) {} |
| 695 m(X x) {} I _n(X x) {}} |
| 696 class X{}'''); |
| 697 computeFast(); |
| 698 return computeFull(true).then((_) { |
| 699 assertSuggestInvocationGetter('b', null); |
| 700 assertSuggestInvocationGetter('_c', 'X'); |
| 701 assertSuggestInvocationGetter('d', 'X'); |
| 702 assertSuggestInvocationGetter('_e', null); |
| 703 assertSuggestInvocationGetter('f', 'X'); |
| 704 assertSuggestInvocationGetter('_g', null); |
| 705 assertSuggestInvocationSetter('s1'); |
| 706 assertSuggestInvocationSetter('_s2'); |
| 707 assertSuggestInvocationMethod('m', 'A', null); |
| 708 assertSuggestInvocationMethod('_n', 'A', 'I'); |
| 709 assertNotSuggested('a'); |
| 710 assertNotSuggested('A'); |
| 711 assertNotSuggested('X'); |
| 712 assertNotSuggested('Object'); |
| 713 }); |
| 714 } |
| 715 |
| 716 test_PrefixedIdentifier_interpolation() { |
| 717 // SimpleIdentifier PrefixedIdentifier InterpolationExpression |
| 718 addTestSource('main() {String name; print("hello \${name.^}");}'); |
| 719 computeFast(); |
| 720 return computeFull(true).then((_) { |
| 721 assertSuggestInvocationGetter('length', 'int'); |
| 722 assertNotSuggested('name'); |
| 723 assertNotSuggested('Object'); |
| 724 }); |
| 725 } |
| 726 |
| 727 test_PrefixedIdentifier_library() { |
| 728 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 729 addSource('/testB.dart', ''' |
| 730 lib B; |
| 731 var T1; |
| 732 class X { } |
| 733 class Y { }'''); |
| 734 addTestSource(''' |
| 735 import "/testB.dart" as b; |
| 736 var T2; |
| 737 class A { } |
| 738 main() {b.^}'''); |
| 739 computeFast(); |
| 740 return computeFull(true).then((_) { |
| 741 assertSuggestInvocationClass('X'); |
| 742 assertSuggestInvocationClass('Y'); |
| 743 assertSuggestInvocationTopLevelVar('T1', null); |
| 744 assertNotSuggested('T2'); |
| 745 assertNotSuggested('Object'); |
| 746 assertNotSuggested('b'); |
| 747 assertNotSuggested('A'); |
| 748 }); |
| 749 } |
| 750 |
| 751 test_PrefixedIdentifier_parameter() { |
| 752 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 753 addSource('/testB.dart', ''' |
| 754 lib B; |
| 755 class _W {M y; var _z;} |
| 756 class X extends _W {} |
| 757 class M{}'''); |
| 758 addTestSource(''' |
| 759 import "/testB.dart"; |
| 760 foo(X x) {x.^}'''); |
| 761 computeFast(); |
| 762 return computeFull(true).then((_) { |
| 763 assertSuggestInvocationGetter('y', 'M'); |
| 764 assertNotSuggested('_z'); |
| 765 }); |
| 766 } |
| 767 |
| 768 test_PrefixedIdentifier_prefix() { |
| 769 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 770 addSource('/testA.dart', ''' |
| 771 class A {static int bar = 10;} |
| 772 _B() {}'''); |
| 773 addTestSource(''' |
| 774 import "/testA.dart"; |
| 775 class X {foo(){A^.bar}}'''); |
| 776 computeFast(); |
| 777 return computeFull(true).then((_) { |
| 778 assertSuggestImportedClass('A'); |
| 779 assertSuggestLocalClass('X'); |
| 780 assertSuggestLocalMethod('foo', 'X', null); |
| 781 assertNotSuggested('bar'); |
| 782 assertNotSuggested('_B'); |
| 783 }); |
| 784 } |
| 785 |
| 786 test_PrefixedIdentifier_prefix_interpolation() { |
| 787 // SimpleIdentifier PrefixedIdentifier InterpolationExpression |
| 788 addTestSource('main() {String name; print("hello \${nam^e.length}");}'); |
| 789 computeFast(); |
| 790 return computeFull(true).then((_) { |
| 791 assertSuggestLocalVariable('name', 'String'); |
| 792 assertSuggestImportedClass('Object'); |
| 793 assertNotSuggested('length'); |
| 794 }); |
| 795 } |
| 796 |
| 797 test_TopLevelVariableDeclaration_typed_name() { |
| 798 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 799 // TopLevelVariableDeclaration |
| 800 addTestSource('class A {} B ^'); |
| 617 computeFast(); | 801 computeFast(); |
| 618 return computeFull(true).then((_) { | 802 return computeFull(true).then((_) { |
| 619 assertNoSuggestions(); | 803 assertNoSuggestions(); |
| 804 }); |
| 805 } |
| 806 |
| 807 test_TopLevelVariableDeclaration_untyped_name() { |
| 808 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 809 // TopLevelVariableDeclaration |
| 810 addTestSource('class A {} var ^'); |
| 811 computeFast(); |
| 812 return computeFull(true).then((_) { |
| 813 assertNoSuggestions(); |
| 620 }); | 814 }); |
| 621 } | 815 } |
| 622 | 816 |
| 623 test_VariableDeclarationStatement_RHS() { | 817 test_VariableDeclarationStatement_RHS() { |
| 624 // SimpleIdentifier VariableDeclaration VariableDeclarationList | 818 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 625 // VariableDeclarationStatement | 819 // VariableDeclarationStatement |
| 626 addSource('/testB.dart', ''' | 820 addSource('/testB.dart', ''' |
| 627 lib B; | 821 lib B; |
| 628 foo() { } | 822 foo() { } |
| 629 class _B { } | 823 class _B { } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 660 return computeFull(true).then((_) { | 854 return computeFull(true).then((_) { |
| 661 assertSuggestImportedClass('X'); | 855 assertSuggestImportedClass('X'); |
| 662 assertNotSuggested('_B'); | 856 assertNotSuggested('_B'); |
| 663 assertSuggestLocalClass('Y'); | 857 assertSuggestLocalClass('Y'); |
| 664 assertSuggestLocalClass('C'); | 858 assertSuggestLocalClass('C'); |
| 665 assertSuggestLocalVariable('f', null); | 859 assertSuggestLocalVariable('f', null); |
| 666 assertNotSuggested('x'); | 860 assertNotSuggested('x'); |
| 667 assertNotSuggested('e'); | 861 assertNotSuggested('e'); |
| 668 }); | 862 }); |
| 669 } | 863 } |
| 864 |
| 865 test_VariableDeclaration_name() { |
| 866 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 867 // VariableDeclarationStatement Block |
| 868 addSource('/testB.dart', ''' |
| 869 lib B; |
| 870 foo() { } |
| 871 class _B { } |
| 872 class X {X.c(); X._d(); z() {}}'''); |
| 873 addTestSource(''' |
| 874 import "/testB.dart"; |
| 875 class Y {Y.c(); Y._d(); z() {}} |
| 876 main() {var ^}'''); |
| 877 computeFast(); |
| 878 return computeFull(true).then((_) { |
| 879 assertNoSuggestions(); |
| 880 }); |
| 881 } |
| 670 } | 882 } |
| OLD | NEW |