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.dart.local; | 5 library test.services.completion.dart.local; |
6 | 6 |
7 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
8 show Element, ElementKind; | 8 show Element, ElementKind; |
9 import 'package:analysis_server/plugin/protocol/protocol.dart' | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' |
10 hide Element, ElementKind; | 10 hide Element, ElementKind; |
(...skipping 27 matching lines...) Expand all Loading... |
38 relevance: relevance); | 38 relevance: relevance); |
39 } | 39 } |
40 | 40 |
41 @override | 41 @override |
42 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, | 42 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, |
43 {int relevance: DART_RELEVANCE_DEFAULT}) { | 43 {int relevance: DART_RELEVANCE_DEFAULT}) { |
44 return assertSuggestClassTypeAlias(name, relevance); | 44 return assertSuggestClassTypeAlias(name, relevance); |
45 } | 45 } |
46 | 46 |
47 @override | 47 @override |
48 CompletionSuggestion assertSuggestLocalConstructor(String name, | |
49 {int elemOffset}) { | |
50 return assertSuggestConstructor(name, elemOffset: elemOffset); | |
51 } | |
52 | |
53 @override | |
54 CompletionSuggestion assertSuggestLocalField(String name, String type, | 48 CompletionSuggestion assertSuggestLocalField(String name, String type, |
55 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { | 49 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { |
56 return assertSuggestField(name, type, | 50 return assertSuggestField(name, type, |
57 relevance: relevance, isDeprecated: deprecated); | 51 relevance: relevance, isDeprecated: deprecated); |
58 } | 52 } |
59 | 53 |
60 @override | 54 @override |
61 CompletionSuggestion assertSuggestLocalFunction( | 55 CompletionSuggestion assertSuggestLocalFunction( |
62 String name, String returnType, | 56 String name, String returnType, |
63 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 57 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 } | 630 } |
637 | 631 |
638 test_InstanceCreationExpression() { | 632 test_InstanceCreationExpression() { |
639 addTestSource(''' | 633 addTestSource(''' |
640 class A {foo(){var f; {var x;}}} | 634 class A {foo(){var f; {var x;}}} |
641 class B {B(this.x, [String boo]) { } int x;} | 635 class B {B(this.x, [String boo]) { } int x;} |
642 class C {C.bar({boo: 'hoo', int z: 0}) { } } | 636 class C {C.bar({boo: 'hoo', int z: 0}) { } } |
643 main() {new ^ String x = "hello";}'''); | 637 main() {new ^ String x = "hello";}'''); |
644 computeFast(); | 638 computeFast(); |
645 return computeFull((bool result) { | 639 return computeFull((bool result) { |
646 CompletionSuggestion suggestion; | 640 // Suggested by ConstructorContributor |
647 | 641 assertNotSuggested('A'); |
648 suggestion = assertSuggestLocalConstructor('A', elemOffset: -1); | 642 assertNotSuggested('B'); |
649 expect(suggestion.element.parameters, '()'); | 643 assertNotSuggested('C.bar'); |
650 expect(suggestion.element.returnType, 'A'); | |
651 expect(suggestion.declaringType, 'A'); | |
652 expect(suggestion.parameterNames, hasLength(0)); | |
653 expect(suggestion.requiredParameterCount, 0); | |
654 expect(suggestion.hasNamedParameters, false); | |
655 | |
656 suggestion = assertSuggestLocalConstructor('B'); | |
657 expect(suggestion.element.parameters, '(int x, [String boo])'); | |
658 expect(suggestion.element.returnType, 'B'); | |
659 expect(suggestion.declaringType, 'B'); | |
660 expect(suggestion.parameterNames, hasLength(2)); | |
661 expect(suggestion.parameterNames[0], 'x'); | |
662 expect(suggestion.parameterTypes[0], 'int'); | |
663 expect(suggestion.parameterNames[1], 'boo'); | |
664 expect(suggestion.parameterTypes[1], 'String'); | |
665 expect(suggestion.requiredParameterCount, 1); | |
666 expect(suggestion.hasNamedParameters, false); | |
667 | |
668 suggestion = assertSuggestLocalConstructor('C.bar'); | |
669 expect(suggestion.element.parameters, '({dynamic boo, int z})'); | |
670 expect(suggestion.element.returnType, 'C'); | |
671 expect(suggestion.declaringType, 'C'); | |
672 expect(suggestion.parameterNames, hasLength(2)); | |
673 expect(suggestion.parameterNames[0], 'boo'); | |
674 expect(suggestion.parameterTypes[0], 'dynamic'); | |
675 expect(suggestion.parameterNames[1], 'z'); | |
676 expect(suggestion.parameterTypes[1], 'int'); | |
677 expect(suggestion.requiredParameterCount, 0); | |
678 expect(suggestion.hasNamedParameters, true); | |
679 }); | 644 }); |
680 } | 645 } |
681 | 646 |
682 test_method_parameters_mixed_required_and_named() { | 647 test_method_parameters_mixed_required_and_named() { |
683 addTestSource(''' | 648 addTestSource(''' |
684 class A { | 649 class A { |
685 void m(x, {int y}) {} | 650 void m(x, {int y}) {} |
686 } | 651 } |
687 class B extends A { | 652 class B extends A { |
688 main() {^} | 653 main() {^} |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 assertSuggestLocalVariable('ab', null); | 804 assertSuggestLocalVariable('ab', null); |
840 assertSuggestLocalVariable('_ab', null, relevance: DART_RELEVANCE_DEFAULT); | 805 assertSuggestLocalVariable('_ab', null, relevance: DART_RELEVANCE_DEFAULT); |
841 } | 806 } |
842 | 807 |
843 test_shadowed_name() { | 808 test_shadowed_name() { |
844 addTestSource('var a; class A { var a; m() { ^ } }'); | 809 addTestSource('var a; class A { var a; m() { ^ } }'); |
845 expect(computeFast(), isTrue); | 810 expect(computeFast(), isTrue); |
846 assertSuggestLocalField('a', null); | 811 assertSuggestLocalField('a', null); |
847 } | 812 } |
848 } | 813 } |
OLD | NEW |