| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 CompletionSuggestion assertSuggestImportedFunction(String name, | 397 CompletionSuggestion assertSuggestImportedFunction(String name, |
| 398 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = | 398 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 399 CompletionRelevance.DEFAULT]) { | 399 CompletionRelevance.DEFAULT]) { |
| 400 if (computer is ImportedComputer) { | 400 if (computer is ImportedComputer) { |
| 401 return assertSuggestFunction(name, returnType, isDeprecated, relevance); | 401 return assertSuggestFunction(name, returnType, isDeprecated, relevance); |
| 402 } else { | 402 } else { |
| 403 return assertNotSuggested(name); | 403 return assertNotSuggested(name); |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 CompletionSuggestion assertSuggestImportedGetter(String name, |
| 408 String returnType, [CompletionRelevance relevance = |
| 409 CompletionRelevance.DEFAULT]) { |
| 410 if (computer is ImportedComputer) { |
| 411 return assertSuggestGetter(name, returnType, relevance); |
| 412 } else { |
| 413 return assertNotSuggested(name); |
| 414 } |
| 415 } |
| 416 |
| 417 CompletionSuggestion assertSuggestImportedMethod(String name, |
| 418 String declaringType, String returnType, [CompletionRelevance relevance = |
| 419 CompletionRelevance.DEFAULT]) { |
| 420 if (computer is ImportedComputer) { |
| 421 return assertSuggestMethod(name, declaringType, returnType, relevance); |
| 422 } else { |
| 423 return assertNotSuggested(name); |
| 424 } |
| 425 } |
| 426 |
| 407 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, | 427 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, |
| 408 String returnType, [CompletionRelevance relevance = | 428 String returnType, [CompletionRelevance relevance = |
| 409 CompletionRelevance.DEFAULT]) { | 429 CompletionRelevance.DEFAULT]) { |
| 410 if (computer is ImportedComputer) { | 430 if (computer is ImportedComputer) { |
| 411 return assertSuggestTopLevelVar(name, returnType, relevance); | 431 return assertSuggestTopLevelVar(name, returnType, relevance); |
| 412 } else { | 432 } else { |
| 413 return assertNotSuggested(name); | 433 return assertNotSuggested(name); |
| 414 } | 434 } |
| 415 } | 435 } |
| 416 | 436 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 assertSuggestImportedTopLevelVar('T3', 'int', CompletionRelevance.LOW); | 672 assertSuggestImportedTopLevelVar('T3', 'int', CompletionRelevance.LOW); |
| 653 assertNotSuggested('_T4'); | 673 assertNotSuggested('_T4'); |
| 654 assertSuggestLocalTopLevelVar('T5', 'int'); | 674 assertSuggestLocalTopLevelVar('T5', 'int'); |
| 655 assertSuggestLocalTopLevelVar('_T6', null); | 675 assertSuggestLocalTopLevelVar('_T6', null); |
| 656 assertNotSuggested('=='); | 676 assertNotSuggested('=='); |
| 657 // TODO (danrubel) suggest HtmlElement as low relevance | 677 // TODO (danrubel) suggest HtmlElement as low relevance |
| 658 assertNotSuggested('HtmlElement'); | 678 assertNotSuggested('HtmlElement'); |
| 659 }); | 679 }); |
| 660 } | 680 } |
| 661 | 681 |
| 682 test_Block_inherited_local() { |
| 683 // Block BlockFunctionBody MethodDeclaration ClassDeclaration |
| 684 addTestSource(''' |
| 685 class F { var f1; f2() { } } |
| 686 class E extends F { var e1; e2() { } } |
| 687 class I { int i1; i2() { } } |
| 688 class M { var m1; int m2() { } } |
| 689 class A extends E implements I with M {a() {^}}'''); |
| 690 computeFast(); |
| 691 return computeFull(true).then((_) { |
| 692 assertSuggestLocalGetter('e1', null); |
| 693 assertSuggestLocalGetter('f1', null); |
| 694 assertSuggestLocalGetter('i1', 'int'); |
| 695 assertSuggestLocalGetter('m1', null); |
| 696 assertSuggestLocalMethod('e2', 'E', null); |
| 697 assertSuggestLocalMethod('f2', 'F', null); |
| 698 assertSuggestLocalMethod('i2', 'I', null); |
| 699 assertSuggestLocalMethod('m2', 'M', 'int'); |
| 700 }); |
| 701 } |
| 702 |
| 662 test_CascadeExpression_selector1() { | 703 test_CascadeExpression_selector1() { |
| 663 // PropertyAccess CascadeExpression ExpressionStatement Block | 704 // PropertyAccess CascadeExpression ExpressionStatement Block |
| 664 addSource('/testB.dart', ''' | 705 addSource('/testB.dart', ''' |
| 665 class B { }'''); | 706 class B { }'''); |
| 666 addTestSource(''' | 707 addTestSource(''' |
| 667 import "/testB.dart"; | 708 import "/testB.dart"; |
| 668 class A {var b; X _c;} | 709 class A {var b; X _c;} |
| 669 class X{} | 710 class X{} |
| 670 // looks like a cascade to the parser | 711 // looks like a cascade to the parser |
| 671 // but the user is trying to get completions for a non-cascade | 712 // but the user is trying to get completions for a non-cascade |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 assertSuggestLocalMethod('a', 'A', null); | 786 assertSuggestLocalMethod('a', 'A', null); |
| 746 assertSuggestImportedClass('Object'); | 787 assertSuggestImportedClass('Object'); |
| 747 assertNotSuggested('x'); | 788 assertNotSuggested('x'); |
| 748 }); | 789 }); |
| 749 } | 790 } |
| 750 | 791 |
| 751 test_ClassDeclaration_body() { | 792 test_ClassDeclaration_body() { |
| 752 // ClassDeclaration CompilationUnit | 793 // ClassDeclaration CompilationUnit |
| 753 addSource('/testB.dart', ''' | 794 addSource('/testB.dart', ''' |
| 754 class B { }'''); | 795 class B { }'''); |
| 755 addTestSource( // | 796 addTestSource(''' |
| 756 'import "testB.dart" as x;' // | 797 import "testB.dart" as x; |
| 757 ' @deprecated class A {^}' // | 798 @deprecated class A {^} |
| 758 ' class _B {}' // | 799 class _B {} |
| 759 ' A T;'); | 800 A T;'''); |
| 760 computeFast(); | 801 computeFast(); |
| 761 return computeFull(true).then((_) { | 802 return computeFull(true).then((_) { |
| 762 CompletionSuggestion suggestionA = assertSuggestLocalClass('A'); | 803 CompletionSuggestion suggestionA = assertSuggestLocalClass('A'); |
| 763 if (suggestionA != null) { | 804 if (suggestionA != null) { |
| 764 expect(suggestionA.element.isDeprecated, isTrue); | 805 expect(suggestionA.element.isDeprecated, isTrue); |
| 765 expect(suggestionA.element.isPrivate, isFalse); | 806 expect(suggestionA.element.isPrivate, isFalse); |
| 766 } | 807 } |
| 767 CompletionSuggestion suggestionB = assertSuggestLocalClass('_B'); | 808 CompletionSuggestion suggestionB = assertSuggestLocalClass('_B'); |
| 768 if (suggestionB != null) { | 809 if (suggestionB != null) { |
| 769 expect(suggestionB.element.isDeprecated, isFalse); | 810 expect(suggestionB.element.isDeprecated, isFalse); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 assertSuggestImportedClass('X'); | 1530 assertSuggestImportedClass('X'); |
| 1490 assertNotSuggested('_B'); | 1531 assertNotSuggested('_B'); |
| 1491 assertSuggestLocalClass('Y'); | 1532 assertSuggestLocalClass('Y'); |
| 1492 assertSuggestLocalClass('C'); | 1533 assertSuggestLocalClass('C'); |
| 1493 assertSuggestLocalVariable('f', null); | 1534 assertSuggestLocalVariable('f', null); |
| 1494 assertNotSuggested('x'); | 1535 assertNotSuggested('x'); |
| 1495 assertNotSuggested('e'); | 1536 assertNotSuggested('e'); |
| 1496 }); | 1537 }); |
| 1497 } | 1538 } |
| 1498 } | 1539 } |
| OLD | NEW |