Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: pkg/analysis_server/test/search/element_references_test.dart

Issue 946023003: Fix for searching constructor references. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.search.element_references; 5 library test.search.element_references;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/index/index.dart'; 10 import 'package:analysis_server/src/services/index/index.dart';
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 class A { 53 class A {
54 A.named(p); 54 A.named(p);
55 } 55 }
56 main() { 56 main() {
57 new A.named(1); 57 new A.named(1);
58 new A.named(2); 58 new A.named(2);
59 } 59 }
60 '''); 60 ''');
61 await findElementReferences('named(p)', false); 61 await findElementReferences('named(p)', false);
62 expect(searchElement.kind, ElementKind.CONSTRUCTOR); 62 expect(searchElement.kind, ElementKind.CONSTRUCTOR);
63 expect(results, hasLength(2));
63 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6); 64 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6);
64 assertHasResult(SearchResultKind.REFERENCE, '.named(2)', 6); 65 assertHasResult(SearchResultKind.REFERENCE, '.named(2)', 6);
65 } 66 }
66 67
67 test_constructor_named_potential() async { 68 test_constructor_named_potential() async {
68 // Constructors in other classes shouldn't be considered potential matches, 69 // Constructors in other classes shouldn't be considered potential matches,
69 // nor should unresolved method calls, since constructor call sites are 70 // nor should unresolved method calls, since constructor call sites are
70 // statically bound to their targets). 71 // statically bound to their targets).
71 addTestFile(''' 72 addTestFile('''
72 class A { 73 class A {
73 A.named(p); // A 74 A.named(p); // A
74 } 75 }
75 class B { 76 class B {
76 B.named(p); 77 B.named(p);
77 } 78 }
78 f(x) { 79 f(x) {
79 new A.named(1); 80 new A.named(1);
80 new B.named(2); 81 new B.named(2);
81 x.named(3); 82 x.named(3);
82 } 83 }
83 '''); 84 ''');
84 await findElementReferences('named(p); // A', true); 85 await findElementReferences('named(p); // A', true);
85 expect(searchElement.kind, ElementKind.CONSTRUCTOR); 86 expect(searchElement.kind, ElementKind.CONSTRUCTOR);
86 assertHasResult(SearchResultKind.DECLARATION, '.named(p)', 6); 87 expect(results, hasLength(1));
87 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6); 88 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6);
88 expect(results, hasLength(2));
89 } 89 }
90 90
91 test_constructor_unnamed() async { 91 test_constructor_unnamed() async {
92 addTestFile(''' 92 addTestFile('''
93 class A { 93 class A {
94 A(p); 94 A(p);
95 } 95 }
96 main() { 96 main() {
97 new A(1); 97 new A(1);
98 new A(2); 98 new A(2);
99 } 99 }
100 '''); 100 ''');
101 await findElementReferences('A(p)', false); 101 await findElementReferences('A(p)', false);
102 expect(searchElement.kind, ElementKind.CONSTRUCTOR); 102 expect(searchElement.kind, ElementKind.CONSTRUCTOR);
103 expect(results, hasLength(2));
103 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0); 104 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0);
104 assertHasResult(SearchResultKind.REFERENCE, '(2)', 0); 105 assertHasResult(SearchResultKind.REFERENCE, '(2)', 0);
105 } 106 }
106 107
107 test_constructor_unnamed_potential() async { 108 test_constructor_unnamed_potential() async {
108 // Constructors in other classes shouldn't be considered potential matches, 109 // Constructors in other classes shouldn't be considered potential matches,
109 // even if they are also unnamed (since constructor call sites are 110 // even if they are also unnamed (since constructor call sites are
110 // statically bound to their targets). 111 // statically bound to their targets).
111 // Also, assignments to local variables shouldn't be considered potential 112 // Also, assignments to local variables shouldn't be considered potential
112 // matches. 113 // matches.
113 addTestFile(''' 114 addTestFile('''
114 class A { 115 class A {
115 A(p); // A 116 A(p); // A
116 } 117 }
117 class B { 118 class B {
118 B(p); 119 B(p);
119 foo() { 120 foo() {
120 int k; 121 int k;
121 k = 3; 122 k = 3;
122 } 123 }
123 } 124 }
124 main() { 125 main() {
125 new A(1); 126 new A(1);
126 new B(2); 127 new B(2);
127 } 128 }
128 '''); 129 ''');
129 await findElementReferences('A(p)', true); 130 await findElementReferences('A(p)', true);
130 expect(searchElement.kind, ElementKind.CONSTRUCTOR); 131 expect(searchElement.kind, ElementKind.CONSTRUCTOR);
131 assertHasResult(SearchResultKind.DECLARATION, '(p); // A', 0); 132 expect(results, hasLength(1));
132 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0); 133 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0);
133 expect(results, hasLength(2));
134 } 134 }
135 135
136 test_field_explicit() async { 136 test_field_explicit() async {
137 addTestFile(''' 137 addTestFile('''
138 class A { 138 class A {
139 var fff; // declaration 139 var fff; // declaration
140 A(this.fff); // in constructor 140 A(this.fff); // in constructor
141 m() { 141 m() {
142 fff = 2; 142 fff = 2;
143 fff += 3; 143 fff += 3;
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 print(vvv); 722 print(vvv);
723 } 723 }
724 '''); 724 ''');
725 Request request = 725 Request request =
726 new SearchFindElementReferencesParams(testFile, 0, false).toRequest('0') ; 726 new SearchFindElementReferencesParams(testFile, 0, false).toRequest('0') ;
727 Response response = await waitResponse(request); 727 Response response = await waitResponse(request);
728 expect(response.error, isNotNull); 728 expect(response.error, isNotNull);
729 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); 729 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED);
730 } 730 }
731 } 731 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698