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 |
10 ElementKind; | 10 show Element, ElementKind; |
11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
12 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; | 12 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; |
13 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 13 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
14 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 14 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
15 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 15 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
16 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 16 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
17 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 17 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
18 import 'package:analysis_server/src/services/index/index.dart'; | 18 import 'package:analysis_server/src/services/index/index.dart'; |
19 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 19 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void addTestSource(String content) { | 55 void addTestSource(String content) { |
56 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); | 56 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
57 completionOffset = content.indexOf('^'); | 57 completionOffset = content.indexOf('^'); |
58 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 58 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
59 int nextOffset = content.indexOf('^', completionOffset + 1); | 59 int nextOffset = content.indexOf('^', completionOffset + 1); |
60 expect(nextOffset, equals(-1), reason: 'too many ^'); | 60 expect(nextOffset, equals(-1), reason: 'too many ^'); |
61 content = content.substring(0, completionOffset) + | 61 content = content.substring(0, completionOffset) + |
62 content.substring(completionOffset + 1); | 62 content.substring(completionOffset + 1); |
63 testSource = addSource(testFile, content); | 63 testSource = addSource(testFile, content); |
64 cache = new DartCompletionCache(context, testSource); | 64 cache = new DartCompletionCache(context, testSource); |
65 request = new DartCompletionRequest( | 65 request = new DartCompletionRequest(context, searchEngine, testSource, |
66 context, | 66 completionOffset, cache, new CompletionPerformance()); |
67 searchEngine, | |
68 testSource, | |
69 completionOffset, | |
70 cache, | |
71 new CompletionPerformance()); | |
72 } | 67 } |
73 | 68 |
74 void assertHasNoParameterInfo(CompletionSuggestion suggestion) { | 69 void assertHasNoParameterInfo(CompletionSuggestion suggestion) { |
75 expect(suggestion.parameterNames, isNull); | 70 expect(suggestion.parameterNames, isNull); |
76 expect(suggestion.parameterTypes, isNull); | 71 expect(suggestion.parameterTypes, isNull); |
77 expect(suggestion.requiredParameterCount, isNull); | 72 expect(suggestion.requiredParameterCount, isNull); |
78 expect(suggestion.hasNamedParameters, isNull); | 73 expect(suggestion.hasNamedParameters, isNull); |
79 } | 74 } |
80 | 75 |
81 void assertHasParameterInfo(CompletionSuggestion suggestion) { | 76 void assertHasParameterInfo(CompletionSuggestion suggestion) { |
82 expect(suggestion.parameterNames, isNotNull); | 77 expect(suggestion.parameterNames, isNotNull); |
83 expect(suggestion.parameterTypes, isNotNull); | 78 expect(suggestion.parameterTypes, isNotNull); |
84 expect(suggestion.parameterNames.length, suggestion.parameterTypes.length); | 79 expect(suggestion.parameterNames.length, suggestion.parameterTypes.length); |
85 expect( | 80 expect(suggestion.requiredParameterCount, |
86 suggestion.requiredParameterCount, | |
87 lessThanOrEqualTo(suggestion.parameterNames.length)); | 81 lessThanOrEqualTo(suggestion.parameterNames.length)); |
88 expect(suggestion.hasNamedParameters, isNotNull); | 82 expect(suggestion.hasNamedParameters, isNotNull); |
89 } | 83 } |
90 | 84 |
91 void assertNoSuggestions({CompletionSuggestionKind kind: null}) { | 85 void assertNoSuggestions({CompletionSuggestionKind kind: null}) { |
92 if (kind == null) { | 86 if (kind == null) { |
93 if (request.suggestions.length > 0) { | 87 if (request.suggestions.length > 0) { |
94 failedCompletion('Expected no suggestions', request.suggestions); | 88 failedCompletion('Expected no suggestions', request.suggestions); |
95 } | 89 } |
96 return; | 90 return; |
97 } | 91 } |
98 CompletionSuggestion suggestion = request.suggestions.firstWhere( | 92 CompletionSuggestion suggestion = request.suggestions.firstWhere( |
99 (CompletionSuggestion cs) => cs.kind == kind, | 93 (CompletionSuggestion cs) => cs.kind == kind, orElse: () => null); |
100 orElse: () => null); | |
101 if (suggestion != null) { | 94 if (suggestion != null) { |
102 failedCompletion('did not expect completion: $completion\n $suggestion'); | 95 failedCompletion('did not expect completion: $completion\n $suggestion'); |
103 } | 96 } |
104 } | 97 } |
105 | 98 |
106 CompletionSuggestion assertNotSuggested(String completion) { | 99 CompletionSuggestion assertNotSuggested(String completion) { |
107 CompletionSuggestion suggestion = request.suggestions.firstWhere( | 100 CompletionSuggestion suggestion = request.suggestions.firstWhere( |
108 (CompletionSuggestion cs) => cs.completion == completion, | 101 (CompletionSuggestion cs) => cs.completion == completion, |
109 orElse: () => null); | 102 orElse: () => null); |
110 if (suggestion != null) { | 103 if (suggestion != null) { |
111 failedCompletion('did not expect completion: $completion\n $suggestion'); | 104 failedCompletion('did not expect completion: $completion\n $suggestion'); |
112 } | 105 } |
113 return null; | 106 return null; |
114 } | 107 } |
115 | 108 |
116 CompletionSuggestion assertSuggest(String completion, | 109 CompletionSuggestion assertSuggest(String completion, |
117 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 110 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
118 int relevance: DART_RELEVANCE_DEFAULT, protocol.ElementKind elemKind: null
, | 111 int relevance: DART_RELEVANCE_DEFAULT, |
119 bool isDeprecated: false, bool isPotential: false}) { | 112 protocol.ElementKind elemKind: null, bool isDeprecated: false, |
| 113 bool isPotential: false}) { |
120 CompletionSuggestion cs = | 114 CompletionSuggestion cs = |
121 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 115 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
122 if (cs == null) { | 116 if (cs == null) { |
123 failedCompletion( | 117 failedCompletion( |
124 'expected $completion $csKind $elemKind', | 118 'expected $completion $csKind $elemKind', request.suggestions); |
125 request.suggestions); | |
126 } | 119 } |
127 expect(cs.kind, equals(csKind)); | 120 expect(cs.kind, equals(csKind)); |
128 if (isDeprecated) { | 121 if (isDeprecated) { |
129 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 122 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
130 } else { | 123 } else { |
131 expect(cs.relevance, equals(relevance)); | 124 expect(cs.relevance, equals(relevance)); |
132 } | 125 } |
133 expect(cs.selectionOffset, equals(completion.length)); | 126 expect(cs.selectionOffset, equals(completion.length)); |
134 expect(cs.selectionLength, equals(0)); | 127 expect(cs.selectionLength, equals(0)); |
135 expect(cs.isDeprecated, equals(isDeprecated)); | 128 expect(cs.isDeprecated, equals(isDeprecated)); |
136 expect(cs.isPotential, equals(isPotential)); | 129 expect(cs.isPotential, equals(isPotential)); |
137 return cs; | 130 return cs; |
138 } | 131 } |
139 | 132 |
140 void assertSuggestArgumentList(List<String> paramNames, | 133 void assertSuggestArgumentList( |
141 List<String> paramTypes) { | 134 List<String> paramNames, List<String> paramTypes) { |
142 CompletionSuggestionKind csKind = CompletionSuggestionKind.ARGUMENT_LIST; | 135 CompletionSuggestionKind csKind = CompletionSuggestionKind.ARGUMENT_LIST; |
143 CompletionSuggestion cs = getSuggest(csKind: csKind); | 136 CompletionSuggestion cs = getSuggest(csKind: csKind); |
144 if (cs == null) { | 137 if (cs == null) { |
145 failedCompletion('expected completion $csKind', request.suggestions); | 138 failedCompletion('expected completion $csKind', request.suggestions); |
146 } | 139 } |
147 assertSuggestArgumentList_params( | 140 assertSuggestArgumentList_params( |
148 paramNames, | 141 paramNames, paramTypes, cs.parameterNames, cs.parameterTypes); |
149 paramTypes, | |
150 cs.parameterNames, | |
151 cs.parameterTypes); | |
152 expect(cs.relevance, DART_RELEVANCE_HIGH); | 142 expect(cs.relevance, DART_RELEVANCE_HIGH); |
153 } | 143 } |
154 | 144 |
155 void assertSuggestArgumentList_params(List<String> expectedNames, | 145 void assertSuggestArgumentList_params(List<String> expectedNames, |
156 List<String> expectedTypes, List<String> actualNames, | 146 List<String> expectedTypes, List<String> actualNames, |
157 List<String> actualTypes) { | 147 List<String> actualTypes) { |
158 if (actualNames != null && | 148 if (actualNames != null && |
159 actualNames.length == expectedNames.length && | 149 actualNames.length == expectedNames.length && |
160 actualTypes != null && | 150 actualTypes != null && |
161 actualTypes.length == expectedTypes.length) { | 151 actualTypes.length == expectedTypes.length) { |
(...skipping 11 matching lines...) Expand all Loading... |
173 } | 163 } |
174 StringBuffer msg = new StringBuffer(); | 164 StringBuffer msg = new StringBuffer(); |
175 msg.writeln('Argument list not the same'); | 165 msg.writeln('Argument list not the same'); |
176 msg.writeln(' Expected names: $expectedNames'); | 166 msg.writeln(' Expected names: $expectedNames'); |
177 msg.writeln(' found: $actualNames'); | 167 msg.writeln(' found: $actualNames'); |
178 msg.writeln(' Expected types: $expectedTypes'); | 168 msg.writeln(' Expected types: $expectedTypes'); |
179 msg.writeln(' found: $actualTypes'); | 169 msg.writeln(' found: $actualTypes'); |
180 fail(msg.toString()); | 170 fail(msg.toString()); |
181 } | 171 } |
182 | 172 |
183 CompletionSuggestion assertSuggestClass(String name, {int relevance: | 173 CompletionSuggestion assertSuggestClass(String name, |
184 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind: | 174 {int relevance: DART_RELEVANCE_DEFAULT, |
185 CompletionSuggestionKind.INVOCATION, bool isDeprecated: false}) { | 175 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
186 CompletionSuggestion cs = assertSuggest( | 176 bool isDeprecated: false}) { |
187 name, | 177 CompletionSuggestion cs = assertSuggest(name, |
188 csKind: kind, | 178 csKind: kind, relevance: relevance, isDeprecated: isDeprecated); |
189 relevance: relevance, | |
190 isDeprecated: isDeprecated); | |
191 protocol.Element element = cs.element; | 179 protocol.Element element = cs.element; |
192 expect(element, isNotNull); | 180 expect(element, isNotNull); |
193 expect(element.kind, equals(protocol.ElementKind.CLASS)); | 181 expect(element.kind, equals(protocol.ElementKind.CLASS)); |
194 expect(element.name, equals(name)); | 182 expect(element.name, equals(name)); |
195 expect(element.parameters, isNull); | 183 expect(element.parameters, isNull); |
196 expect(element.returnType, isNull); | 184 expect(element.returnType, isNull); |
197 assertHasNoParameterInfo(cs); | 185 assertHasNoParameterInfo(cs); |
198 return cs; | 186 return cs; |
199 } | 187 } |
200 | 188 |
201 CompletionSuggestion assertSuggestClassTypeAlias(String name, [int relevance = | 189 CompletionSuggestion assertSuggestClassTypeAlias(String name, |
202 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 190 [int relevance = DART_RELEVANCE_DEFAULT, |
203 CompletionSuggestionKind.INVOCATION]) { | 191 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
204 CompletionSuggestion cs = | 192 CompletionSuggestion cs = |
205 assertSuggest(name, csKind: kind, relevance: relevance); | 193 assertSuggest(name, csKind: kind, relevance: relevance); |
206 protocol.Element element = cs.element; | 194 protocol.Element element = cs.element; |
207 expect(element, isNotNull); | 195 expect(element, isNotNull); |
208 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); | 196 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); |
209 expect(element.name, equals(name)); | 197 expect(element.name, equals(name)); |
210 expect(element.parameters, isNull); | 198 expect(element.parameters, isNull); |
211 expect(element.returnType, isNull); | 199 expect(element.returnType, isNull); |
212 assertHasNoParameterInfo(cs); | 200 assertHasNoParameterInfo(cs); |
213 return cs; | 201 return cs; |
214 } | 202 } |
215 | 203 |
216 CompletionSuggestion assertSuggestField(String name, String type, | 204 CompletionSuggestion assertSuggestField(String name, String type, |
217 {int relevance: DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind: | 205 {int relevance: DART_RELEVANCE_DEFAULT, |
218 CompletionSuggestionKind.INVOCATION, bool isDeprecated: false}) { | 206 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
219 CompletionSuggestion cs = assertSuggest( | 207 bool isDeprecated: false}) { |
220 name, | 208 CompletionSuggestion cs = assertSuggest(name, |
221 csKind: kind, | 209 csKind: kind, |
222 relevance: relevance, | 210 relevance: relevance, |
223 elemKind: protocol.ElementKind.FIELD, | 211 elemKind: protocol.ElementKind.FIELD, |
224 isDeprecated: isDeprecated); | 212 isDeprecated: isDeprecated); |
225 // The returnType represents the type of a field | 213 // The returnType represents the type of a field |
226 expect(cs.returnType, type != null ? type : 'dynamic'); | 214 expect(cs.returnType, type != null ? type : 'dynamic'); |
227 protocol.Element element = cs.element; | 215 protocol.Element element = cs.element; |
228 expect(element, isNotNull); | 216 expect(element, isNotNull); |
229 expect(element.kind, equals(protocol.ElementKind.FIELD)); | 217 expect(element.kind, equals(protocol.ElementKind.FIELD)); |
230 expect(element.name, equals(name)); | 218 expect(element.name, equals(name)); |
231 expect(element.parameters, isNull); | 219 expect(element.parameters, isNull); |
232 // The returnType represents the type of a field | 220 // The returnType represents the type of a field |
233 expect(element.returnType, type != null ? type : 'dynamic'); | 221 expect(element.returnType, type != null ? type : 'dynamic'); |
234 assertHasNoParameterInfo(cs); | 222 assertHasNoParameterInfo(cs); |
235 return cs; | 223 return cs; |
236 } | 224 } |
237 | 225 |
238 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 226 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
239 [bool isDeprecated = false, int relevance = DART_RELEVANCE_DEFAULT, | 227 [bool isDeprecated = false, int relevance = DART_RELEVANCE_DEFAULT, |
240 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 228 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
241 CompletionSuggestion cs = assertSuggest( | 229 CompletionSuggestion cs = assertSuggest(name, |
242 name, | 230 csKind: kind, relevance: relevance, isDeprecated: isDeprecated); |
243 csKind: kind, | |
244 relevance: relevance, | |
245 isDeprecated: isDeprecated); | |
246 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 231 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
247 protocol.Element element = cs.element; | 232 protocol.Element element = cs.element; |
248 expect(element, isNotNull); | 233 expect(element, isNotNull); |
249 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 234 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
250 expect(element.name, equals(name)); | 235 expect(element.name, equals(name)); |
251 expect(element.isDeprecated, equals(isDeprecated)); | 236 expect(element.isDeprecated, equals(isDeprecated)); |
252 String param = element.parameters; | 237 String param = element.parameters; |
253 expect(param, isNotNull); | 238 expect(param, isNotNull); |
254 expect(param[0], equals('(')); | 239 expect(param[0], equals('(')); |
255 expect(param[param.length - 1], equals(')')); | 240 expect(param[param.length - 1], equals(')')); |
256 expect( | 241 expect(element.returnType, |
257 element.returnType, | |
258 equals(returnType != null ? returnType : 'dynamic')); | 242 equals(returnType != null ? returnType : 'dynamic')); |
259 assertHasParameterInfo(cs); | 243 assertHasParameterInfo(cs); |
260 return cs; | 244 return cs; |
261 } | 245 } |
262 | 246 |
263 CompletionSuggestion assertSuggestFunctionTypeAlias(String name, | 247 CompletionSuggestion assertSuggestFunctionTypeAlias( |
264 String returnType, bool isDeprecated, [int relevance = DART_RELEVANCE_DEFA
ULT, | 248 String name, String returnType, bool isDeprecated, |
| 249 [int relevance = DART_RELEVANCE_DEFAULT, |
265 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 250 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
266 CompletionSuggestion cs = assertSuggest( | 251 CompletionSuggestion cs = assertSuggest(name, |
267 name, | 252 csKind: kind, relevance: relevance, isDeprecated: isDeprecated); |
268 csKind: kind, | |
269 relevance: relevance, | |
270 isDeprecated: isDeprecated); | |
271 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 253 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
272 protocol.Element element = cs.element; | 254 protocol.Element element = cs.element; |
273 expect(element, isNotNull); | 255 expect(element, isNotNull); |
274 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); | 256 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); |
275 expect(element.name, equals(name)); | 257 expect(element.name, equals(name)); |
276 expect(element.isDeprecated, equals(isDeprecated)); | 258 expect(element.isDeprecated, equals(isDeprecated)); |
277 // TODO (danrubel) Determine why params are null | 259 // TODO (danrubel) Determine why params are null |
278 // String param = element.parameters; | 260 // String param = element.parameters; |
279 // expect(param, isNotNull); | 261 // expect(param, isNotNull); |
280 // expect(param[0], equals('(')); | 262 // expect(param[0], equals('(')); |
281 // expect(param[param.length - 1], equals(')')); | 263 // expect(param[param.length - 1], equals(')')); |
282 expect( | 264 expect(element.returnType, |
283 element.returnType, | |
284 equals(returnType != null ? returnType : 'dynamic')); | 265 equals(returnType != null ? returnType : 'dynamic')); |
285 // TODO (danrubel) Determine why param info is missing | 266 // TODO (danrubel) Determine why param info is missing |
286 // assertHasParameterInfo(cs); | 267 // assertHasParameterInfo(cs); |
287 return cs; | 268 return cs; |
288 } | 269 } |
289 | 270 |
290 CompletionSuggestion assertSuggestGetter(String name, String returnType, | 271 CompletionSuggestion assertSuggestGetter(String name, String returnType, |
291 {int relevance: DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind: | 272 {int relevance: DART_RELEVANCE_DEFAULT, |
292 CompletionSuggestionKind.INVOCATION, bool isDeprecated: false}) { | 273 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
293 CompletionSuggestion cs = assertSuggest( | 274 bool isDeprecated: false}) { |
294 name, | 275 CompletionSuggestion cs = assertSuggest(name, |
295 csKind: kind, | 276 csKind: kind, |
296 relevance: relevance, | 277 relevance: relevance, |
297 elemKind: protocol.ElementKind.GETTER, | 278 elemKind: protocol.ElementKind.GETTER, |
298 isDeprecated: isDeprecated); | 279 isDeprecated: isDeprecated); |
299 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 280 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
300 protocol.Element element = cs.element; | 281 protocol.Element element = cs.element; |
301 expect(element, isNotNull); | 282 expect(element, isNotNull); |
302 expect(element.kind, equals(protocol.ElementKind.GETTER)); | 283 expect(element.kind, equals(protocol.ElementKind.GETTER)); |
303 expect(element.name, equals(name)); | 284 expect(element.name, equals(name)); |
304 expect(element.parameters, isNull); | 285 expect(element.parameters, isNull); |
305 expect( | 286 expect(element.returnType, |
306 element.returnType, | |
307 equals(returnType != null ? returnType : 'dynamic')); | 287 equals(returnType != null ? returnType : 'dynamic')); |
308 assertHasNoParameterInfo(cs); | 288 assertHasNoParameterInfo(cs); |
309 return cs; | 289 return cs; |
310 } | 290 } |
311 | 291 |
312 CompletionSuggestion assertSuggestLabel(String name, [int relevance = | 292 CompletionSuggestion assertSuggestLabel(String name, |
313 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 293 [int relevance = DART_RELEVANCE_DEFAULT, |
314 CompletionSuggestionKind.IDENTIFIER]) { | 294 CompletionSuggestionKind kind = CompletionSuggestionKind.IDENTIFIER]) { |
315 CompletionSuggestion cs = | 295 CompletionSuggestion cs = |
316 assertSuggest(name, csKind: kind, relevance: relevance); | 296 assertSuggest(name, csKind: kind, relevance: relevance); |
317 expect(cs.returnType, isNull); | 297 expect(cs.returnType, isNull); |
318 protocol.Element element = cs.element; | 298 protocol.Element element = cs.element; |
319 expect(element, isNotNull); | 299 expect(element, isNotNull); |
320 expect(element.flags, 0); | 300 expect(element.flags, 0); |
321 expect(element.kind, equals(protocol.ElementKind.LABEL)); | 301 expect(element.kind, equals(protocol.ElementKind.LABEL)); |
322 expect(element.name, equals(name)); | 302 expect(element.name, equals(name)); |
323 expect(element.parameters, isNull); | 303 expect(element.parameters, isNull); |
324 expect(element.returnType, isNull); | 304 expect(element.returnType, isNull); |
325 assertHasNoParameterInfo(cs); | 305 assertHasNoParameterInfo(cs); |
326 return cs; | 306 return cs; |
327 } | 307 } |
328 | 308 |
329 CompletionSuggestion assertSuggestLibraryPrefix(String prefix, [int relevance | 309 CompletionSuggestion assertSuggestLibraryPrefix(String prefix, |
330 = DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 310 [int relevance = DART_RELEVANCE_DEFAULT, |
331 CompletionSuggestionKind.INVOCATION]) { | 311 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
332 // Library prefix should only be suggested by ImportedComputer | 312 // Library prefix should only be suggested by ImportedComputer |
333 if (computer is ImportedComputer) { | 313 if (computer is ImportedComputer) { |
334 CompletionSuggestion cs = | 314 CompletionSuggestion cs = |
335 assertSuggest(prefix, csKind: kind, relevance: relevance); | 315 assertSuggest(prefix, csKind: kind, relevance: relevance); |
336 protocol.Element element = cs.element; | 316 protocol.Element element = cs.element; |
337 expect(element, isNotNull); | 317 expect(element, isNotNull); |
338 expect(element.kind, equals(protocol.ElementKind.LIBRARY)); | 318 expect(element.kind, equals(protocol.ElementKind.LIBRARY)); |
339 expect(element.parameters, isNull); | 319 expect(element.parameters, isNull); |
340 expect(element.returnType, isNull); | 320 expect(element.returnType, isNull); |
341 assertHasNoParameterInfo(cs); | 321 assertHasNoParameterInfo(cs); |
342 return cs; | 322 return cs; |
343 } else { | 323 } else { |
344 return assertNotSuggested(prefix); | 324 return assertNotSuggested(prefix); |
345 } | 325 } |
346 } | 326 } |
347 | 327 |
348 CompletionSuggestion assertSuggestMethod(String name, String declaringType, | 328 CompletionSuggestion assertSuggestMethod( |
349 String returnType, {int relevance: DART_RELEVANCE_DEFAULT, | 329 String name, String declaringType, String returnType, |
| 330 {int relevance: DART_RELEVANCE_DEFAULT, |
350 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 331 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
351 bool isDeprecated: false}) { | 332 bool isDeprecated: false}) { |
352 CompletionSuggestion cs = assertSuggest( | 333 CompletionSuggestion cs = assertSuggest(name, |
353 name, | 334 csKind: kind, relevance: relevance, isDeprecated: isDeprecated); |
354 csKind: kind, | |
355 relevance: relevance, | |
356 isDeprecated: isDeprecated); | |
357 expect(cs.declaringType, equals(declaringType)); | 335 expect(cs.declaringType, equals(declaringType)); |
358 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 336 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
359 protocol.Element element = cs.element; | 337 protocol.Element element = cs.element; |
360 expect(element, isNotNull); | 338 expect(element, isNotNull); |
361 expect(element.kind, equals(protocol.ElementKind.METHOD)); | 339 expect(element.kind, equals(protocol.ElementKind.METHOD)); |
362 expect(element.name, equals(name)); | 340 expect(element.name, equals(name)); |
363 String param = element.parameters; | 341 String param = element.parameters; |
364 expect(param, isNotNull); | 342 expect(param, isNotNull); |
365 expect(param[0], equals('(')); | 343 expect(param[0], equals('(')); |
366 expect(param[param.length - 1], equals(')')); | 344 expect(param[param.length - 1], equals(')')); |
367 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 345 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
368 assertHasParameterInfo(cs); | 346 assertHasParameterInfo(cs); |
369 return cs; | 347 return cs; |
370 } | 348 } |
371 | 349 |
372 CompletionSuggestion assertSuggestNamedConstructor(String name, | 350 CompletionSuggestion assertSuggestNamedConstructor( |
373 String returnType, [int relevance = DART_RELEVANCE_DEFAULT, | 351 String name, String returnType, [int relevance = DART_RELEVANCE_DEFAULT, |
374 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 352 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
375 if (computer is InvocationComputer) { | 353 if (computer is InvocationComputer) { |
376 CompletionSuggestion cs = | 354 CompletionSuggestion cs = |
377 assertSuggest(name, csKind: kind, relevance: relevance); | 355 assertSuggest(name, csKind: kind, relevance: relevance); |
378 protocol.Element element = cs.element; | 356 protocol.Element element = cs.element; |
379 expect(element, isNotNull); | 357 expect(element, isNotNull); |
380 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | 358 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); |
381 expect(element.name, equals(name)); | 359 expect(element.name, equals(name)); |
382 String param = element.parameters; | 360 String param = element.parameters; |
383 expect(param, isNotNull); | 361 expect(param, isNotNull); |
384 expect(param[0], equals('(')); | 362 expect(param[0], equals('(')); |
385 expect(param[param.length - 1], equals(')')); | 363 expect(param[param.length - 1], equals(')')); |
386 expect(element.returnType, equals(returnType)); | 364 expect(element.returnType, equals(returnType)); |
387 assertHasParameterInfo(cs); | 365 assertHasParameterInfo(cs); |
388 return cs; | 366 return cs; |
389 } else { | 367 } else { |
390 return assertNotSuggested(name); | 368 return assertNotSuggested(name); |
391 } | 369 } |
392 } | 370 } |
393 | 371 |
394 CompletionSuggestion assertSuggestParameter(String name, String returnType, | 372 CompletionSuggestion assertSuggestParameter(String name, String returnType, |
395 {int relevance: DART_RELEVANCE_PARAMETER}) { | 373 {int relevance: DART_RELEVANCE_PARAMETER}) { |
396 return assertNotSuggested(name); | 374 return assertNotSuggested(name); |
397 } | 375 } |
398 | 376 |
399 CompletionSuggestion assertSuggestSetter(String name, [int relevance = | 377 CompletionSuggestion assertSuggestSetter(String name, |
400 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 378 [int relevance = DART_RELEVANCE_DEFAULT, |
401 CompletionSuggestionKind.INVOCATION]) { | 379 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
402 CompletionSuggestion cs = assertSuggest( | 380 CompletionSuggestion cs = assertSuggest(name, |
403 name, | |
404 csKind: kind, | 381 csKind: kind, |
405 relevance: relevance, | 382 relevance: relevance, |
406 elemKind: protocol.ElementKind.SETTER); | 383 elemKind: protocol.ElementKind.SETTER); |
407 protocol.Element element = cs.element; | 384 protocol.Element element = cs.element; |
408 expect(element, isNotNull); | 385 expect(element, isNotNull); |
409 expect(element.kind, equals(protocol.ElementKind.SETTER)); | 386 expect(element.kind, equals(protocol.ElementKind.SETTER)); |
410 expect(element.name, equals(name)); | 387 expect(element.name, equals(name)); |
411 // TODO (danrubel) assert setter param | 388 // TODO (danrubel) assert setter param |
412 //expect(element.parameters, isNull); | 389 //expect(element.parameters, isNull); |
413 // TODO (danrubel) it would be better if this was always null | 390 // TODO (danrubel) it would be better if this was always null |
414 if (element.returnType != null) { | 391 if (element.returnType != null) { |
415 expect(element.returnType, 'dynamic'); | 392 expect(element.returnType, 'dynamic'); |
416 } | 393 } |
417 assertHasNoParameterInfo(cs); | 394 assertHasNoParameterInfo(cs); |
418 return cs; | 395 return cs; |
419 } | 396 } |
420 | 397 |
421 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, | 398 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, |
422 [int relevance = DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 399 [int relevance = DART_RELEVANCE_DEFAULT, |
423 CompletionSuggestionKind.INVOCATION]) { | 400 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
424 CompletionSuggestion cs = | 401 CompletionSuggestion cs = |
425 assertSuggest(name, csKind: kind, relevance: relevance); | 402 assertSuggest(name, csKind: kind, relevance: relevance); |
426 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 403 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
427 protocol.Element element = cs.element; | 404 protocol.Element element = cs.element; |
428 expect(element, isNotNull); | 405 expect(element, isNotNull); |
429 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); | 406 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); |
430 expect(element.name, equals(name)); | 407 expect(element.name, equals(name)); |
431 expect(element.parameters, isNull); | 408 expect(element.parameters, isNull); |
432 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 409 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
433 assertHasNoParameterInfo(cs); | 410 assertHasNoParameterInfo(cs); |
434 return cs; | 411 return cs; |
435 } | 412 } |
436 | 413 |
437 void assertSuggestTopLevelVarGetterSetter(String name, String returnType, | 414 void assertSuggestTopLevelVarGetterSetter(String name, String returnType, |
438 [int relevance = DART_RELEVANCE_DEFAULT]) { | 415 [int relevance = DART_RELEVANCE_DEFAULT]) { |
439 if (computer is ImportedComputer) { | 416 if (computer is ImportedComputer) { |
440 assertSuggestGetter(name, returnType); | 417 assertSuggestGetter(name, returnType); |
441 assertSuggestSetter(name); | 418 assertSuggestSetter(name); |
442 } else { | 419 } else { |
443 assertNotSuggested(name); | 420 assertNotSuggested(name); |
444 } | 421 } |
445 } | 422 } |
446 | 423 |
447 bool computeFast() { | 424 bool computeFast() { |
448 _computeFastCalled = true; | 425 _computeFastCalled = true; |
449 _completionManager = new DartCompletionManager( | 426 _completionManager = new DartCompletionManager(context, searchEngine, |
450 context, | 427 testSource, cache, [computer], new CommonUsageComputer({})); |
451 searchEngine, | |
452 testSource, | |
453 cache, | |
454 [computer], | |
455 new CommonUsageComputer({})); | |
456 var result = _completionManager.computeFast(request); | 428 var result = _completionManager.computeFast(request); |
457 expect(request.replacementOffset, isNotNull); | 429 expect(request.replacementOffset, isNotNull); |
458 expect(request.replacementLength, isNotNull); | 430 expect(request.replacementLength, isNotNull); |
459 return result.isEmpty; | 431 return result.isEmpty; |
460 } | 432 } |
461 | 433 |
462 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 434 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
463 if (!_computeFastCalled) { | 435 if (!_computeFastCalled) { |
464 expect(computeFast(), isFalse); | 436 expect(computeFast(), isFalse); |
465 } | 437 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 483 } |
512 return computer.computeFull(request).then(assertFunction); | 484 return computer.computeFull(request).then(assertFunction); |
513 } | 485 } |
514 | 486 |
515 void failedCompletion(String message, | 487 void failedCompletion(String message, |
516 [Iterable<CompletionSuggestion> completions]) { | 488 [Iterable<CompletionSuggestion> completions]) { |
517 StringBuffer sb = new StringBuffer(message); | 489 StringBuffer sb = new StringBuffer(message); |
518 if (completions != null) { | 490 if (completions != null) { |
519 sb.write('\n found'); | 491 sb.write('\n found'); |
520 completions.toList() | 492 completions.toList() |
521 ..sort(suggestionComparator) | 493 ..sort(suggestionComparator) |
522 ..forEach((CompletionSuggestion suggestion) { | 494 ..forEach((CompletionSuggestion suggestion) { |
523 sb.write('\n ${suggestion.completion} -> $suggestion'); | 495 sb.write('\n ${suggestion.completion} -> $suggestion'); |
524 }); | 496 }); |
525 } | 497 } |
526 if (completionNode != null) { | 498 if (completionNode != null) { |
527 sb.write('\n in'); | 499 sb.write('\n in'); |
528 AstNode node = completionNode; | 500 AstNode node = completionNode; |
529 while (node != null) { | 501 while (node != null) { |
530 sb.write('\n ${node.runtimeType}'); | 502 sb.write('\n ${node.runtimeType}'); |
531 node = node.parent; | 503 node = node.parent; |
532 } | 504 } |
533 } | 505 } |
534 fail(sb.toString()); | 506 fail(sb.toString()); |
535 } | 507 } |
536 | 508 |
537 CompletionSuggestion getSuggest({String completion: null, | 509 CompletionSuggestion getSuggest({String completion: null, |
538 CompletionSuggestionKind csKind: null, protocol.ElementKind elemKind: null
}) { | 510 CompletionSuggestionKind csKind: null, |
| 511 protocol.ElementKind elemKind: null}) { |
539 CompletionSuggestion cs; | 512 CompletionSuggestion cs; |
540 request.suggestions.forEach((CompletionSuggestion s) { | 513 request.suggestions.forEach((CompletionSuggestion s) { |
541 if (completion != null && completion != s.completion) { | 514 if (completion != null && completion != s.completion) { |
542 return; | 515 return; |
543 } | 516 } |
544 if (csKind != null && csKind != s.kind) { | 517 if (csKind != null && csKind != s.kind) { |
545 return; | 518 return; |
546 } | 519 } |
547 if (elemKind != null) { | 520 if (elemKind != null) { |
548 protocol.Element element = s.element; | 521 protocol.Element element = s.element; |
549 if (element == null || elemKind != element.kind) { | 522 if (element == null || elemKind != element.kind) { |
550 return; | 523 return; |
551 } | 524 } |
552 } | 525 } |
553 if (cs == null) { | 526 if (cs == null) { |
554 cs = s; | 527 cs = s; |
555 } else { | 528 } else { |
556 failedCompletion( | 529 failedCompletion('expected exactly one $cs', |
557 'expected exactly one $cs', | |
558 request.suggestions.where((s) => s.completion == completion)); | 530 request.suggestions.where((s) => s.completion == completion)); |
559 } | 531 } |
560 }); | 532 }); |
561 return cs; | 533 return cs; |
562 } | 534 } |
563 | 535 |
564 @override | 536 @override |
565 void setUp() { | 537 void setUp() { |
566 super.setUp(); | 538 super.setUp(); |
567 index = createLocalMemoryIndex(); | 539 index = createLocalMemoryIndex(); |
(...skipping 11 matching lines...) Expand all Loading... |
579 abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest { | 551 abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest { |
580 | 552 |
581 /** | 553 /** |
582 * Assert that the ImportedComputer uses cached results to produce identical | 554 * Assert that the ImportedComputer uses cached results to produce identical |
583 * suggestions to the original set of suggestions. | 555 * suggestions to the original set of suggestions. |
584 */ | 556 */ |
585 void assertCachedCompute(_) { | 557 void assertCachedCompute(_) { |
586 // Subclasses override | 558 // Subclasses override |
587 } | 559 } |
588 | 560 |
589 CompletionSuggestion assertSuggestImportedClass(String name, [int relevance = | 561 CompletionSuggestion assertSuggestImportedClass(String name, |
590 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 562 [int relevance = DART_RELEVANCE_DEFAULT, |
591 CompletionSuggestionKind.INVOCATION]) { | 563 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
592 if (computer is ImportedComputer) { | 564 if (computer is ImportedComputer) { |
593 return assertSuggestClass(name, relevance: relevance, kind: kind); | 565 return assertSuggestClass(name, relevance: relevance, kind: kind); |
594 } else { | 566 } else { |
595 return assertNotSuggested(name); | 567 return assertNotSuggested(name); |
596 } | 568 } |
597 } | 569 } |
598 | 570 |
599 CompletionSuggestion assertSuggestImportedField(String name, String type, | 571 CompletionSuggestion assertSuggestImportedField(String name, String type, |
600 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) { | 572 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) { |
601 return assertNotSuggested(name); | 573 return assertNotSuggested(name); |
602 } | 574 } |
603 | 575 |
604 CompletionSuggestion assertSuggestImportedFunction(String name, | 576 CompletionSuggestion assertSuggestImportedFunction( |
605 String returnType, [bool isDeprecated = false, int relevance = | 577 String name, String returnType, [bool isDeprecated = false, |
606 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 578 int relevance = DART_RELEVANCE_DEFAULT, |
607 CompletionSuggestionKind.INVOCATION]) { | 579 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
608 if (computer is ImportedComputer) { | 580 if (computer is ImportedComputer) { |
609 return assertSuggestFunction( | 581 return assertSuggestFunction( |
610 name, | 582 name, returnType, isDeprecated, relevance, kind); |
611 returnType, | |
612 isDeprecated, | |
613 relevance, | |
614 kind); | |
615 } else { | 583 } else { |
616 return assertNotSuggested(name); | 584 return assertNotSuggested(name); |
617 } | 585 } |
618 } | 586 } |
619 | 587 |
620 CompletionSuggestion assertSuggestImportedFunctionTypeAlias(String name, | 588 CompletionSuggestion assertSuggestImportedFunctionTypeAlias( |
621 String returnType, [bool isDeprecated = false, int relevance = | 589 String name, String returnType, [bool isDeprecated = false, |
622 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 590 int relevance = DART_RELEVANCE_DEFAULT, |
623 CompletionSuggestionKind.INVOCATION]) { | 591 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
624 if (computer is ImportedComputer) { | 592 if (computer is ImportedComputer) { |
625 return assertSuggestFunctionTypeAlias( | 593 return assertSuggestFunctionTypeAlias( |
626 name, | 594 name, returnType, isDeprecated, relevance, kind); |
627 returnType, | |
628 isDeprecated, | |
629 relevance, | |
630 kind); | |
631 } else { | 595 } else { |
632 return assertNotSuggested(name); | 596 return assertNotSuggested(name); |
633 } | 597 } |
634 } | 598 } |
635 | 599 |
636 CompletionSuggestion assertSuggestImportedGetter(String name, | 600 CompletionSuggestion assertSuggestImportedGetter( |
637 String returnType, {int relevance: DART_RELEVANCE_INHERITED_ACCESSOR}) { | 601 String name, String returnType, |
| 602 {int relevance: DART_RELEVANCE_INHERITED_ACCESSOR}) { |
638 return assertNotSuggested(name); | 603 return assertNotSuggested(name); |
639 } | 604 } |
640 | 605 |
641 CompletionSuggestion assertSuggestImportedMethod(String name, | 606 CompletionSuggestion assertSuggestImportedMethod( |
642 String declaringType, String returnType, {int relevance: | 607 String name, String declaringType, String returnType, |
643 DART_RELEVANCE_INHERITED_METHOD}) { | 608 {int relevance: DART_RELEVANCE_INHERITED_METHOD}) { |
644 return assertNotSuggested(name); | 609 return assertNotSuggested(name); |
645 } | 610 } |
646 | 611 |
647 CompletionSuggestion assertSuggestImportedSetter(String name, {int relevance: | 612 CompletionSuggestion assertSuggestImportedSetter(String name, |
648 DART_RELEVANCE_INHERITED_ACCESSOR}) { | 613 {int relevance: DART_RELEVANCE_INHERITED_ACCESSOR}) { |
649 return assertNotSuggested(name); | 614 return assertNotSuggested(name); |
650 } | 615 } |
651 | 616 |
652 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, | 617 CompletionSuggestion assertSuggestImportedTopLevelVar( |
653 String returnType, [int relevance = DART_RELEVANCE_DEFAULT, | 618 String name, String returnType, [int relevance = DART_RELEVANCE_DEFAULT, |
654 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 619 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
655 if (computer is ImportedComputer) { | 620 if (computer is ImportedComputer) { |
656 return assertSuggestTopLevelVar(name, returnType, relevance, kind); | 621 return assertSuggestTopLevelVar(name, returnType, relevance, kind); |
657 } else { | 622 } else { |
658 return assertNotSuggested(name); | 623 return assertNotSuggested(name); |
659 } | 624 } |
660 } | 625 } |
661 | 626 |
662 CompletionSuggestion assertSuggestInvocationClass(String name, [int relevance | 627 CompletionSuggestion assertSuggestInvocationClass(String name, |
663 = DART_RELEVANCE_DEFAULT]) { | 628 [int relevance = DART_RELEVANCE_DEFAULT]) { |
664 if (computer is InvocationComputer) { | 629 if (computer is InvocationComputer) { |
665 return assertSuggestClass(name, relevance: relevance); | 630 return assertSuggestClass(name, relevance: relevance); |
666 } else { | 631 } else { |
667 return assertNotSuggested(name); | 632 return assertNotSuggested(name); |
668 } | 633 } |
669 } | 634 } |
670 | 635 |
671 CompletionSuggestion assertSuggestInvocationField(String name, String type, | 636 CompletionSuggestion assertSuggestInvocationField(String name, String type, |
672 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 637 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
673 return assertNotSuggested(name); | 638 return assertNotSuggested(name); |
674 } | 639 } |
675 | 640 |
676 CompletionSuggestion assertSuggestInvocationGetter(String name, | 641 CompletionSuggestion assertSuggestInvocationGetter( |
677 String returnType, {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecat
ed: | 642 String name, String returnType, |
678 false}) { | 643 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
679 if (computer is InvocationComputer) { | 644 if (computer is InvocationComputer) { |
680 return assertSuggestGetter( | 645 return assertSuggestGetter(name, returnType, |
681 name, | 646 relevance: relevance, isDeprecated: isDeprecated); |
682 returnType, | |
683 relevance: relevance, | |
684 isDeprecated: isDeprecated); | |
685 } else { | 647 } else { |
686 return assertNotSuggested(name); | 648 return assertNotSuggested(name); |
687 } | 649 } |
688 } | 650 } |
689 | 651 |
690 CompletionSuggestion assertSuggestInvocationMethod(String name, | 652 CompletionSuggestion assertSuggestInvocationMethod( |
691 String declaringType, String returnType, [int relevance = | 653 String name, String declaringType, String returnType, |
692 DART_RELEVANCE_DEFAULT]) { | 654 [int relevance = DART_RELEVANCE_DEFAULT]) { |
693 if (computer is InvocationComputer) { | 655 if (computer is InvocationComputer) { |
694 return assertSuggestMethod( | 656 return assertSuggestMethod(name, declaringType, returnType, |
695 name, | |
696 declaringType, | |
697 returnType, | |
698 relevance: relevance); | 657 relevance: relevance); |
699 } else { | 658 } else { |
700 return assertNotSuggested(name); | 659 return assertNotSuggested(name); |
701 } | 660 } |
702 } | 661 } |
703 | 662 |
704 CompletionSuggestion assertSuggestInvocationSetter(String name, [int relevance | 663 CompletionSuggestion assertSuggestInvocationSetter(String name, |
705 = DART_RELEVANCE_DEFAULT]) { | 664 [int relevance = DART_RELEVANCE_DEFAULT]) { |
706 if (computer is InvocationComputer) { | 665 if (computer is InvocationComputer) { |
707 return assertSuggestSetter(name); | 666 return assertSuggestSetter(name); |
708 } else { | 667 } else { |
709 return assertNotSuggested(name); | 668 return assertNotSuggested(name); |
710 } | 669 } |
711 } | 670 } |
712 | 671 |
713 CompletionSuggestion assertSuggestInvocationTopLevelVar(String name, | 672 CompletionSuggestion assertSuggestInvocationTopLevelVar( |
714 String returnType, [int relevance = DART_RELEVANCE_DEFAULT]) { | 673 String name, String returnType, |
| 674 [int relevance = DART_RELEVANCE_DEFAULT]) { |
715 if (computer is InvocationComputer) { | 675 if (computer is InvocationComputer) { |
716 return assertSuggestTopLevelVar(name, returnType, relevance); | 676 return assertSuggestTopLevelVar(name, returnType, relevance); |
717 } else { | 677 } else { |
718 return assertNotSuggested(name); | 678 return assertNotSuggested(name); |
719 } | 679 } |
720 } | 680 } |
721 | 681 |
722 CompletionSuggestion assertSuggestLocalClass(String name, {int relevance: | 682 CompletionSuggestion assertSuggestLocalClass(String name, |
723 DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 683 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
724 return assertNotSuggested(name); | 684 return assertNotSuggested(name); |
725 } | 685 } |
726 | 686 |
727 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, | 687 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, |
728 {int relevance: DART_RELEVANCE_DEFAULT}) { | 688 {int relevance: DART_RELEVANCE_DEFAULT}) { |
729 return assertNotSuggested(name); | 689 return assertNotSuggested(name); |
730 } | 690 } |
731 | 691 |
732 CompletionSuggestion assertSuggestLocalField(String name, String type, | 692 CompletionSuggestion assertSuggestLocalField(String name, String type, |
733 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { | 693 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { |
734 return assertNotSuggested(name); | 694 return assertNotSuggested(name); |
735 } | 695 } |
736 | 696 |
737 CompletionSuggestion assertSuggestLocalFunction(String name, | 697 CompletionSuggestion assertSuggestLocalFunction( |
738 String returnType, {bool deprecated: false, int relevance: | 698 String name, String returnType, |
739 DART_RELEVANCE_LOCAL_FUNCTION}) { | 699 {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) { |
740 return assertNotSuggested(name); | 700 return assertNotSuggested(name); |
741 } | 701 } |
742 | 702 |
743 CompletionSuggestion assertSuggestLocalFunctionTypeAlias(String name, | 703 CompletionSuggestion assertSuggestLocalFunctionTypeAlias( |
744 String returnType, {bool deprecated: false, int relevance: | 704 String name, String returnType, |
745 DART_RELEVANCE_DEFAULT}) { | 705 {bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { |
746 return assertNotSuggested(name); | 706 return assertNotSuggested(name); |
747 } | 707 } |
748 | 708 |
749 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, | 709 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, |
750 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR, bool deprecated: false}) { | 710 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR, bool deprecated: false}) { |
751 return assertNotSuggested(name); | 711 return assertNotSuggested(name); |
752 } | 712 } |
753 | 713 |
754 CompletionSuggestion assertSuggestLocalMethod(String name, | 714 CompletionSuggestion assertSuggestLocalMethod( |
755 String declaringType, String returnType, {int relevance: | 715 String name, String declaringType, String returnType, |
756 DART_RELEVANCE_LOCAL_METHOD, bool deprecated: false}) { | 716 {int relevance: DART_RELEVANCE_LOCAL_METHOD, bool deprecated: false}) { |
757 return assertNotSuggested(name); | 717 return assertNotSuggested(name); |
758 } | 718 } |
759 | 719 |
760 CompletionSuggestion assertSuggestLocalSetter(String name, {int relevance: | 720 CompletionSuggestion assertSuggestLocalSetter(String name, |
761 DART_RELEVANCE_LOCAL_ACCESSOR}) { | 721 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR}) { |
762 return assertNotSuggested(name); | 722 return assertNotSuggested(name); |
763 } | 723 } |
764 | 724 |
765 CompletionSuggestion assertSuggestLocalTopLevelVar(String name, | 725 CompletionSuggestion assertSuggestLocalTopLevelVar( |
766 String returnType, {int relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE
}) { | 726 String name, String returnType, |
| 727 {int relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE}) { |
767 return assertNotSuggested(name); | 728 return assertNotSuggested(name); |
768 } | 729 } |
769 | 730 |
770 CompletionSuggestion assertSuggestLocalVariable(String name, | 731 CompletionSuggestion assertSuggestLocalVariable( |
771 String returnType, {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { | 732 String name, String returnType, |
| 733 {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { |
772 return assertNotSuggested(name); | 734 return assertNotSuggested(name); |
773 } | 735 } |
774 | 736 |
775 CompletionSuggestion assertSuggestNonLocalClass(String name, [int relevance = | 737 CompletionSuggestion assertSuggestNonLocalClass(String name, |
776 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 738 [int relevance = DART_RELEVANCE_DEFAULT, |
777 CompletionSuggestionKind.INVOCATION]) { | 739 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
778 return assertSuggestImportedClass(name, relevance, kind); | 740 return assertSuggestImportedClass(name, relevance, kind); |
779 } | 741 } |
780 | 742 |
781 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 743 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
782 return super.computeFull( | 744 return super |
783 assertFunction, | 745 .computeFull(assertFunction, fullAnalysis: fullAnalysis) |
784 fullAnalysis: fullAnalysis).then(assertCachedCompute); | 746 .then(assertCachedCompute); |
785 } | 747 } |
786 | 748 |
787 test_ArgumentList() { | 749 test_ArgumentList() { |
788 // ArgumentList MethodInvocation ExpressionStatement Block | 750 // ArgumentList MethodInvocation ExpressionStatement Block |
789 addSource('/libA.dart', ''' | 751 addSource('/libA.dart', ''' |
790 library A; | 752 library A; |
791 bool hasLength(int expected) { } | 753 bool hasLength(int expected) { } |
792 void baz() { }'''); | 754 void baz() { }'''); |
793 addTestSource(''' | 755 addTestSource(''' |
794 import '/libA.dart'; | 756 import '/libA.dart'; |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 class B { }'''); | 1414 class B { }'''); |
1453 addTestSource(''' | 1415 addTestSource(''' |
1454 import "testB.dart" as x; | 1416 import "testB.dart" as x; |
1455 @deprecated class A {^} | 1417 @deprecated class A {^} |
1456 class _B {} | 1418 class _B {} |
1457 A T;'''); | 1419 A T;'''); |
1458 computeFast(); | 1420 computeFast(); |
1459 return computeFull((bool result) { | 1421 return computeFull((bool result) { |
1460 expect(request.replacementOffset, completionOffset); | 1422 expect(request.replacementOffset, completionOffset); |
1461 expect(request.replacementLength, 0); | 1423 expect(request.replacementLength, 0); |
1462 CompletionSuggestion suggestionA = assertSuggestLocalClass( | 1424 CompletionSuggestion suggestionA = assertSuggestLocalClass('A', |
1463 'A', | 1425 relevance: DART_RELEVANCE_LOW, isDeprecated: true); |
1464 relevance: DART_RELEVANCE_LOW, | |
1465 isDeprecated: true); | |
1466 if (suggestionA != null) { | 1426 if (suggestionA != null) { |
1467 expect(suggestionA.element.isDeprecated, isTrue); | 1427 expect(suggestionA.element.isDeprecated, isTrue); |
1468 expect(suggestionA.element.isPrivate, isFalse); | 1428 expect(suggestionA.element.isPrivate, isFalse); |
1469 } | 1429 } |
1470 CompletionSuggestion suggestionB = assertSuggestLocalClass('_B'); | 1430 CompletionSuggestion suggestionB = assertSuggestLocalClass('_B'); |
1471 if (suggestionB != null) { | 1431 if (suggestionB != null) { |
1472 expect(suggestionB.element.isDeprecated, isFalse); | 1432 expect(suggestionB.element.isDeprecated, isFalse); |
1473 expect(suggestionB.element.isPrivate, isTrue); | 1433 expect(suggestionB.element.isPrivate, isTrue); |
1474 } | 1434 } |
1475 CompletionSuggestion suggestionO = assertSuggestImportedClass('Object'); | 1435 CompletionSuggestion suggestionO = assertSuggestImportedClass('Object'); |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); | 2332 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); |
2373 computeFast(); | 2333 computeFast(); |
2374 return computeFull((bool result) { | 2334 return computeFull((bool result) { |
2375 expect(request.replacementOffset, completionOffset); | 2335 expect(request.replacementOffset, completionOffset); |
2376 expect(request.replacementLength, 0); | 2336 expect(request.replacementLength, 0); |
2377 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z'); | 2337 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z'); |
2378 if (methodA != null) { | 2338 if (methodA != null) { |
2379 expect(methodA.element.isDeprecated, isFalse); | 2339 expect(methodA.element.isDeprecated, isFalse); |
2380 expect(methodA.element.isPrivate, isFalse); | 2340 expect(methodA.element.isPrivate, isFalse); |
2381 } | 2341 } |
2382 CompletionSuggestion getterF = assertSuggestLocalGetter( | 2342 CompletionSuggestion getterF = assertSuggestLocalGetter('f', 'X', |
2383 'f', | 2343 relevance: DART_RELEVANCE_LOW, deprecated: true); |
2384 'X', | |
2385 relevance: DART_RELEVANCE_LOW, | |
2386 deprecated: true); | |
2387 if (getterF != null) { | 2344 if (getterF != null) { |
2388 expect(getterF.element.isDeprecated, isTrue); | 2345 expect(getterF.element.isDeprecated, isTrue); |
2389 expect(getterF.element.isPrivate, isFalse); | 2346 expect(getterF.element.isPrivate, isFalse); |
2390 } | 2347 } |
2391 CompletionSuggestion getterG = assertSuggestLocalGetter('_g', null); | 2348 CompletionSuggestion getterG = assertSuggestLocalGetter('_g', null); |
2392 if (getterG != null) { | 2349 if (getterG != null) { |
2393 expect(getterG.element.isDeprecated, isFalse); | 2350 expect(getterG.element.isDeprecated, isFalse); |
2394 expect(getterG.element.isPrivate, isTrue); | 2351 expect(getterG.element.isPrivate, isTrue); |
2395 } | 2352 } |
2396 }); | 2353 }); |
2397 } | 2354 } |
2398 | 2355 |
2399 test_MethodDeclaration_members() { | 2356 test_MethodDeclaration_members() { |
2400 // Block BlockFunctionBody MethodDeclaration | 2357 // Block BlockFunctionBody MethodDeclaration |
2401 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); | 2358 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); |
2402 computeFast(); | 2359 computeFast(); |
2403 return computeFull((bool result) { | 2360 return computeFull((bool result) { |
2404 expect(request.replacementOffset, completionOffset); | 2361 expect(request.replacementOffset, completionOffset); |
2405 expect(request.replacementLength, 0); | 2362 expect(request.replacementLength, 0); |
2406 CompletionSuggestion methodA = assertSuggestLocalMethod('_a', 'A', 'Z'); | 2363 CompletionSuggestion methodA = assertSuggestLocalMethod('_a', 'A', 'Z'); |
2407 if (methodA != null) { | 2364 if (methodA != null) { |
2408 expect(methodA.element.isDeprecated, isFalse); | 2365 expect(methodA.element.isDeprecated, isFalse); |
2409 expect(methodA.element.isPrivate, isTrue); | 2366 expect(methodA.element.isPrivate, isTrue); |
2410 } | 2367 } |
2411 CompletionSuggestion getterF = assertSuggestLocalField( | 2368 CompletionSuggestion getterF = assertSuggestLocalField('f', 'X', |
2412 'f', | 2369 relevance: DART_RELEVANCE_LOW, deprecated: true); |
2413 'X', | |
2414 relevance: DART_RELEVANCE_LOW, | |
2415 deprecated: true); | |
2416 if (getterF != null) { | 2370 if (getterF != null) { |
2417 expect(getterF.element.isDeprecated, isTrue); | 2371 expect(getterF.element.isDeprecated, isTrue); |
2418 expect(getterF.element.isPrivate, isFalse); | 2372 expect(getterF.element.isPrivate, isFalse); |
2419 expect(getterF.element.parameters, isNull); | 2373 expect(getterF.element.parameters, isNull); |
2420 } | 2374 } |
2421 CompletionSuggestion getterG = assertSuggestLocalField('_g', null); | 2375 CompletionSuggestion getterG = assertSuggestLocalField('_g', null); |
2422 if (getterG != null) { | 2376 if (getterG != null) { |
2423 expect(getterG.element.isDeprecated, isFalse); | 2377 expect(getterG.element.isDeprecated, isFalse); |
2424 expect(getterG.element.isPrivate, isTrue); | 2378 expect(getterG.element.isPrivate, isTrue); |
2425 expect(getterF.element.parameters, isNull); | 2379 expect(getterF.element.parameters, isNull); |
2426 } | 2380 } |
2427 assertSuggestImportedClass('bool'); | 2381 assertSuggestImportedClass('bool'); |
2428 }); | 2382 }); |
2429 } | 2383 } |
2430 | 2384 |
2431 test_MethodDeclaration_parameters_named() { | 2385 test_MethodDeclaration_parameters_named() { |
2432 // Block BlockFunctionBody MethodDeclaration | 2386 // Block BlockFunctionBody MethodDeclaration |
2433 addTestSource('class A {@deprecated Z a(X x, _, b, {y: boo}) {^}}'); | 2387 addTestSource('class A {@deprecated Z a(X x, _, b, {y: boo}) {^}}'); |
2434 computeFast(); | 2388 computeFast(); |
2435 return computeFull((bool result) { | 2389 return computeFull((bool result) { |
2436 expect(request.replacementOffset, completionOffset); | 2390 expect(request.replacementOffset, completionOffset); |
2437 expect(request.replacementLength, 0); | 2391 expect(request.replacementLength, 0); |
2438 CompletionSuggestion methodA = assertSuggestLocalMethod( | 2392 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z', |
2439 'a', | 2393 relevance: DART_RELEVANCE_LOW, deprecated: true); |
2440 'A', | |
2441 'Z', | |
2442 relevance: DART_RELEVANCE_LOW, | |
2443 deprecated: true); | |
2444 if (methodA != null) { | 2394 if (methodA != null) { |
2445 expect(methodA.element.isDeprecated, isTrue); | 2395 expect(methodA.element.isDeprecated, isTrue); |
2446 expect(methodA.element.isPrivate, isFalse); | 2396 expect(methodA.element.isPrivate, isFalse); |
2447 } | 2397 } |
2448 assertSuggestParameter('x', 'X'); | 2398 assertSuggestParameter('x', 'X'); |
2449 assertSuggestParameter('y', null); | 2399 assertSuggestParameter('y', null); |
2450 assertSuggestParameter('b', null); | 2400 assertSuggestParameter('b', null); |
2451 assertSuggestImportedClass('int'); | 2401 assertSuggestImportedClass('int'); |
2452 assertNotSuggested('_'); | 2402 assertNotSuggested('_'); |
2453 }); | 2403 }); |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 assertNotSuggested('bar2'); | 3048 assertNotSuggested('bar2'); |
3099 assertNotSuggested('_B'); | 3049 assertNotSuggested('_B'); |
3100 assertSuggestLocalClass('Y'); | 3050 assertSuggestLocalClass('Y'); |
3101 assertSuggestLocalClass('C'); | 3051 assertSuggestLocalClass('C'); |
3102 assertSuggestLocalVariable('f', null); | 3052 assertSuggestLocalVariable('f', null); |
3103 assertNotSuggested('x'); | 3053 assertNotSuggested('x'); |
3104 assertNotSuggested('e'); | 3054 assertNotSuggested('e'); |
3105 }); | 3055 }); |
3106 } | 3056 } |
3107 } | 3057 } |
OLD | NEW |