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.util; | |
6 | |
7 import 'dart:async'; | 5 import 'dart:async'; |
8 | 6 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 7 import 'package:analysis_server/protocol/protocol_generated.dart'; |
10 show Element, ElementKind; | |
11 import 'package:analysis_server/plugin/protocol/protocol.dart' | |
12 hide Element, ElementKind; | |
13 import 'package:analysis_server/plugin/protocol/protocol.dart'; | |
14 import 'package:analysis_server/src/ide_options.dart'; | 8 import 'package:analysis_server/src/ide_options.dart'; |
15 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 9 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
16 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 10 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
17 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 11 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
18 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' | 12 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' |
19 show DartCompletionRequestImpl, ReplacementRange; | 13 show DartCompletionRequestImpl, ReplacementRange; |
20 import 'package:analysis_server/src/services/index/index.dart'; | 14 import 'package:analysis_server/src/services/index/index.dart'; |
21 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 15 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
22 import 'package:analyzer/file_system/file_system.dart'; | 16 import 'package:analyzer/file_system/file_system.dart'; |
23 import 'package:analyzer/source/package_map_resolver.dart'; | 17 import 'package:analyzer/source/package_map_resolver.dart'; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 orElse: () => null); | 100 orElse: () => null); |
107 if (suggestion != null) { | 101 if (suggestion != null) { |
108 failedCompletion('did not expect completion: $completion\n $suggestion'); | 102 failedCompletion('did not expect completion: $completion\n $suggestion'); |
109 } | 103 } |
110 } | 104 } |
111 | 105 |
112 CompletionSuggestion assertSuggest(String completion, | 106 CompletionSuggestion assertSuggest(String completion, |
113 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 107 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
114 int relevance: DART_RELEVANCE_DEFAULT, | 108 int relevance: DART_RELEVANCE_DEFAULT, |
115 String importUri, | 109 String importUri, |
116 protocol.ElementKind elemKind: null, | 110 ElementKind elemKind: null, |
117 bool isDeprecated: false, | 111 bool isDeprecated: false, |
118 bool isPotential: false, | 112 bool isPotential: false, |
119 String elemFile, | 113 String elemFile, |
120 int elemOffset, | 114 int elemOffset, |
121 String paramName, | 115 String paramName, |
122 String paramType, | 116 String paramType, |
123 String defaultArgListString: _UNCHECKED, | 117 String defaultArgListString: _UNCHECKED, |
124 List<int> defaultArgumentListTextRanges}) { | 118 List<int> defaultArgumentListTextRanges}) { |
125 CompletionSuggestion cs = | 119 CompletionSuggestion cs = |
126 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 String elemFile, | 169 String elemFile, |
176 String elemName, | 170 String elemName, |
177 int elemOffset}) { | 171 int elemOffset}) { |
178 CompletionSuggestion cs = assertSuggest(name, | 172 CompletionSuggestion cs = assertSuggest(name, |
179 csKind: kind, | 173 csKind: kind, |
180 relevance: relevance, | 174 relevance: relevance, |
181 importUri: importUri, | 175 importUri: importUri, |
182 isDeprecated: isDeprecated, | 176 isDeprecated: isDeprecated, |
183 elemFile: elemFile, | 177 elemFile: elemFile, |
184 elemOffset: elemOffset); | 178 elemOffset: elemOffset); |
185 protocol.Element element = cs.element; | 179 Element element = cs.element; |
186 expect(element, isNotNull); | 180 expect(element, isNotNull); |
187 expect(element.kind, equals(protocol.ElementKind.CLASS)); | 181 expect(element.kind, equals(ElementKind.CLASS)); |
188 expect(element.name, equals(elemName ?? name)); | 182 expect(element.name, equals(elemName ?? name)); |
189 expect(element.parameters, isNull); | 183 expect(element.parameters, isNull); |
190 expect(element.returnType, isNull); | 184 expect(element.returnType, isNull); |
191 assertHasNoParameterInfo(cs); | 185 assertHasNoParameterInfo(cs); |
192 return cs; | 186 return cs; |
193 } | 187 } |
194 | 188 |
195 CompletionSuggestion assertSuggestClassTypeAlias(String name, | 189 CompletionSuggestion assertSuggestClassTypeAlias(String name, |
196 {int relevance: DART_RELEVANCE_DEFAULT, | 190 {int relevance: DART_RELEVANCE_DEFAULT, |
197 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { | 191 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { |
198 CompletionSuggestion cs = | 192 CompletionSuggestion cs = |
199 assertSuggest(name, csKind: kind, relevance: relevance); | 193 assertSuggest(name, csKind: kind, relevance: relevance); |
200 protocol.Element element = cs.element; | 194 Element element = cs.element; |
201 expect(element, isNotNull); | 195 expect(element, isNotNull); |
202 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); | 196 expect(element.kind, equals(ElementKind.CLASS_TYPE_ALIAS)); |
203 expect(element.name, equals(name)); | 197 expect(element.name, equals(name)); |
204 expect(element.parameters, isNull); | 198 expect(element.parameters, isNull); |
205 expect(element.returnType, isNull); | 199 expect(element.returnType, isNull); |
206 assertHasNoParameterInfo(cs); | 200 assertHasNoParameterInfo(cs); |
207 return cs; | 201 return cs; |
208 } | 202 } |
209 | 203 |
210 CompletionSuggestion assertSuggestConstructor(String name, | 204 CompletionSuggestion assertSuggestConstructor(String name, |
211 {int relevance: DART_RELEVANCE_DEFAULT, | 205 {int relevance: DART_RELEVANCE_DEFAULT, |
212 String importUri, | 206 String importUri, |
213 int elemOffset, | 207 int elemOffset, |
214 String defaultArgListString: _UNCHECKED, | 208 String defaultArgListString: _UNCHECKED, |
215 List<int> defaultArgumentListTextRanges}) { | 209 List<int> defaultArgumentListTextRanges}) { |
216 CompletionSuggestion cs = assertSuggest(name, | 210 CompletionSuggestion cs = assertSuggest(name, |
217 relevance: relevance, | 211 relevance: relevance, |
218 importUri: importUri, | 212 importUri: importUri, |
219 elemOffset: elemOffset, | 213 elemOffset: elemOffset, |
220 defaultArgListString: defaultArgListString, | 214 defaultArgListString: defaultArgListString, |
221 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 215 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
222 protocol.Element element = cs.element; | 216 Element element = cs.element; |
223 expect(element, isNotNull); | 217 expect(element, isNotNull); |
224 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | 218 expect(element.kind, equals(ElementKind.CONSTRUCTOR)); |
225 int index = name.indexOf('.'); | 219 int index = name.indexOf('.'); |
226 expect(element.name, index >= 0 ? name.substring(index + 1) : ''); | 220 expect(element.name, index >= 0 ? name.substring(index + 1) : ''); |
227 return cs; | 221 return cs; |
228 } | 222 } |
229 | 223 |
230 CompletionSuggestion assertSuggestEnum(String completion, | 224 CompletionSuggestion assertSuggestEnum(String completion, |
231 {bool isDeprecated: false}) { | 225 {bool isDeprecated: false}) { |
232 CompletionSuggestion suggestion = | 226 CompletionSuggestion suggestion = |
233 assertSuggest(completion, isDeprecated: isDeprecated); | 227 assertSuggest(completion, isDeprecated: isDeprecated); |
234 expect(suggestion.isDeprecated, isDeprecated); | 228 expect(suggestion.isDeprecated, isDeprecated); |
235 expect(suggestion.element.kind, protocol.ElementKind.ENUM); | 229 expect(suggestion.element.kind, ElementKind.ENUM); |
236 return suggestion; | 230 return suggestion; |
237 } | 231 } |
238 | 232 |
239 CompletionSuggestion assertSuggestEnumConst(String completion, | 233 CompletionSuggestion assertSuggestEnumConst(String completion, |
240 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 234 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
241 CompletionSuggestion suggestion = assertSuggest(completion, | 235 CompletionSuggestion suggestion = assertSuggest(completion, |
242 relevance: relevance, isDeprecated: isDeprecated); | 236 relevance: relevance, isDeprecated: isDeprecated); |
243 expect(suggestion.completion, completion); | 237 expect(suggestion.completion, completion); |
244 expect(suggestion.isDeprecated, isDeprecated); | 238 expect(suggestion.isDeprecated, isDeprecated); |
245 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT); | 239 expect(suggestion.element.kind, ElementKind.ENUM_CONSTANT); |
246 return suggestion; | 240 return suggestion; |
247 } | 241 } |
248 | 242 |
249 CompletionSuggestion assertSuggestField(String name, String type, | 243 CompletionSuggestion assertSuggestField(String name, String type, |
250 {int relevance: DART_RELEVANCE_DEFAULT, | 244 {int relevance: DART_RELEVANCE_DEFAULT, |
251 String importUri, | 245 String importUri, |
252 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 246 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
253 bool isDeprecated: false}) { | 247 bool isDeprecated: false}) { |
254 CompletionSuggestion cs = assertSuggest(name, | 248 CompletionSuggestion cs = assertSuggest(name, |
255 csKind: kind, | 249 csKind: kind, |
256 relevance: relevance, | 250 relevance: relevance, |
257 importUri: importUri, | 251 importUri: importUri, |
258 elemKind: protocol.ElementKind.FIELD, | 252 elemKind: ElementKind.FIELD, |
259 isDeprecated: isDeprecated); | 253 isDeprecated: isDeprecated); |
260 // The returnType represents the type of a field | 254 // The returnType represents the type of a field |
261 expect(cs.returnType, type != null ? type : 'dynamic'); | 255 expect(cs.returnType, type != null ? type : 'dynamic'); |
262 protocol.Element element = cs.element; | 256 Element element = cs.element; |
263 expect(element, isNotNull); | 257 expect(element, isNotNull); |
264 expect(element.kind, equals(protocol.ElementKind.FIELD)); | 258 expect(element.kind, equals(ElementKind.FIELD)); |
265 expect(element.name, equals(name)); | 259 expect(element.name, equals(name)); |
266 expect(element.parameters, isNull); | 260 expect(element.parameters, isNull); |
267 // The returnType represents the type of a field | 261 // The returnType represents the type of a field |
268 expect(element.returnType, type != null ? type : 'dynamic'); | 262 expect(element.returnType, type != null ? type : 'dynamic'); |
269 assertHasNoParameterInfo(cs); | 263 assertHasNoParameterInfo(cs); |
270 return cs; | 264 return cs; |
271 } | 265 } |
272 | 266 |
273 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 267 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
274 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 268 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
275 bool isDeprecated: false, | 269 bool isDeprecated: false, |
276 int relevance: DART_RELEVANCE_DEFAULT, | 270 int relevance: DART_RELEVANCE_DEFAULT, |
277 String importUri, | 271 String importUri, |
278 String defaultArgListString: _UNCHECKED, | 272 String defaultArgListString: _UNCHECKED, |
279 List<int> defaultArgumentListTextRanges}) { | 273 List<int> defaultArgumentListTextRanges}) { |
280 CompletionSuggestion cs = assertSuggest(name, | 274 CompletionSuggestion cs = assertSuggest(name, |
281 csKind: kind, | 275 csKind: kind, |
282 relevance: relevance, | 276 relevance: relevance, |
283 importUri: importUri, | 277 importUri: importUri, |
284 isDeprecated: isDeprecated, | 278 isDeprecated: isDeprecated, |
285 defaultArgListString: defaultArgListString, | 279 defaultArgListString: defaultArgListString, |
286 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 280 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
287 if (returnType != null) { | 281 if (returnType != null) { |
288 expect(cs.returnType, returnType); | 282 expect(cs.returnType, returnType); |
289 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 283 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
290 expect(cs.returnType, 'dynamic'); | 284 expect(cs.returnType, 'dynamic'); |
291 } | 285 } |
292 protocol.Element element = cs.element; | 286 Element element = cs.element; |
293 expect(element, isNotNull); | 287 expect(element, isNotNull); |
294 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 288 expect(element.kind, equals(ElementKind.FUNCTION)); |
295 expect(element.name, equals(name)); | 289 expect(element.name, equals(name)); |
296 expect(element.isDeprecated, equals(isDeprecated)); | 290 expect(element.isDeprecated, equals(isDeprecated)); |
297 String param = element.parameters; | 291 String param = element.parameters; |
298 expect(param, isNotNull); | 292 expect(param, isNotNull); |
299 expect(param[0], equals('(')); | 293 expect(param[0], equals('(')); |
300 expect(param[param.length - 1], equals(')')); | 294 expect(param[param.length - 1], equals(')')); |
301 if (returnType != null) { | 295 if (returnType != null) { |
302 expect(element.returnType, returnType); | 296 expect(element.returnType, returnType); |
303 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 297 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
304 expect(element.returnType, 'dynamic'); | 298 expect(element.returnType, 'dynamic'); |
(...skipping 13 matching lines...) Expand all Loading... |
318 relevance: relevance, | 312 relevance: relevance, |
319 importUri: importUri, | 313 importUri: importUri, |
320 isDeprecated: isDeprecated); | 314 isDeprecated: isDeprecated); |
321 if (returnType != null) { | 315 if (returnType != null) { |
322 expect(cs.returnType, returnType); | 316 expect(cs.returnType, returnType); |
323 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 317 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
324 expect(cs.returnType, 'dynamic'); | 318 expect(cs.returnType, 'dynamic'); |
325 } else { | 319 } else { |
326 expect(cs.returnType, isNull); | 320 expect(cs.returnType, isNull); |
327 } | 321 } |
328 protocol.Element element = cs.element; | 322 Element element = cs.element; |
329 expect(element, isNotNull); | 323 expect(element, isNotNull); |
330 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); | 324 expect(element.kind, equals(ElementKind.FUNCTION_TYPE_ALIAS)); |
331 expect(element.name, equals(name)); | 325 expect(element.name, equals(name)); |
332 expect(element.isDeprecated, equals(isDeprecated)); | 326 expect(element.isDeprecated, equals(isDeprecated)); |
333 // TODO (danrubel) Determine why params are null | 327 // TODO (danrubel) Determine why params are null |
334 // String param = element.parameters; | 328 // String param = element.parameters; |
335 // expect(param, isNotNull); | 329 // expect(param, isNotNull); |
336 // expect(param[0], equals('(')); | 330 // expect(param[0], equals('(')); |
337 // expect(param[param.length - 1], equals(')')); | 331 // expect(param[param.length - 1], equals(')')); |
338 expect(element.returnType, | 332 expect(element.returnType, |
339 equals(returnType != null ? returnType : 'dynamic')); | 333 equals(returnType != null ? returnType : 'dynamic')); |
340 // TODO (danrubel) Determine why param info is missing | 334 // TODO (danrubel) Determine why param info is missing |
341 // assertHasParameterInfo(cs); | 335 // assertHasParameterInfo(cs); |
342 return cs; | 336 return cs; |
343 } | 337 } |
344 | 338 |
345 CompletionSuggestion assertSuggestGetter(String name, String returnType, | 339 CompletionSuggestion assertSuggestGetter(String name, String returnType, |
346 {int relevance: DART_RELEVANCE_DEFAULT, | 340 {int relevance: DART_RELEVANCE_DEFAULT, |
347 String importUri, | 341 String importUri, |
348 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 342 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
349 bool isDeprecated: false}) { | 343 bool isDeprecated: false}) { |
350 CompletionSuggestion cs = assertSuggest(name, | 344 CompletionSuggestion cs = assertSuggest(name, |
351 csKind: kind, | 345 csKind: kind, |
352 relevance: relevance, | 346 relevance: relevance, |
353 importUri: importUri, | 347 importUri: importUri, |
354 elemKind: protocol.ElementKind.GETTER, | 348 elemKind: ElementKind.GETTER, |
355 isDeprecated: isDeprecated); | 349 isDeprecated: isDeprecated); |
356 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 350 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
357 protocol.Element element = cs.element; | 351 Element element = cs.element; |
358 expect(element, isNotNull); | 352 expect(element, isNotNull); |
359 expect(element.kind, equals(protocol.ElementKind.GETTER)); | 353 expect(element.kind, equals(ElementKind.GETTER)); |
360 expect(element.name, equals(name)); | 354 expect(element.name, equals(name)); |
361 expect(element.parameters, isNull); | 355 expect(element.parameters, isNull); |
362 expect(element.returnType, | 356 expect(element.returnType, |
363 equals(returnType != null ? returnType : 'dynamic')); | 357 equals(returnType != null ? returnType : 'dynamic')); |
364 assertHasNoParameterInfo(cs); | 358 assertHasNoParameterInfo(cs); |
365 return cs; | 359 return cs; |
366 } | 360 } |
367 | 361 |
368 CompletionSuggestion assertSuggestMethod( | 362 CompletionSuggestion assertSuggestMethod( |
369 String name, String declaringType, String returnType, | 363 String name, String declaringType, String returnType, |
370 {int relevance: DART_RELEVANCE_DEFAULT, | 364 {int relevance: DART_RELEVANCE_DEFAULT, |
371 String importUri, | 365 String importUri, |
372 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 366 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
373 bool isDeprecated: false, | 367 bool isDeprecated: false, |
374 String defaultArgListString: _UNCHECKED, | 368 String defaultArgListString: _UNCHECKED, |
375 List<int> defaultArgumentListTextRanges}) { | 369 List<int> defaultArgumentListTextRanges}) { |
376 CompletionSuggestion cs = assertSuggest(name, | 370 CompletionSuggestion cs = assertSuggest(name, |
377 csKind: kind, | 371 csKind: kind, |
378 relevance: relevance, | 372 relevance: relevance, |
379 importUri: importUri, | 373 importUri: importUri, |
380 isDeprecated: isDeprecated, | 374 isDeprecated: isDeprecated, |
381 defaultArgListString: defaultArgListString, | 375 defaultArgListString: defaultArgListString, |
382 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 376 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
383 expect(cs.declaringType, equals(declaringType)); | 377 expect(cs.declaringType, equals(declaringType)); |
384 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 378 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
385 protocol.Element element = cs.element; | 379 Element element = cs.element; |
386 expect(element, isNotNull); | 380 expect(element, isNotNull); |
387 expect(element.kind, equals(protocol.ElementKind.METHOD)); | 381 expect(element.kind, equals(ElementKind.METHOD)); |
388 expect(element.name, equals(name)); | 382 expect(element.name, equals(name)); |
389 String param = element.parameters; | 383 String param = element.parameters; |
390 expect(param, isNotNull); | 384 expect(param, isNotNull); |
391 expect(param[0], equals('(')); | 385 expect(param[0], equals('(')); |
392 expect(param[param.length - 1], equals(')')); | 386 expect(param[param.length - 1], equals(')')); |
393 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 387 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
394 assertHasParameterInfo(cs); | 388 assertHasParameterInfo(cs); |
395 return cs; | 389 return cs; |
396 } | 390 } |
397 | 391 |
(...skipping 14 matching lines...) Expand all Loading... |
412 } | 406 } |
413 | 407 |
414 CompletionSuggestion assertSuggestSetter(String name, | 408 CompletionSuggestion assertSuggestSetter(String name, |
415 {int relevance: DART_RELEVANCE_DEFAULT, | 409 {int relevance: DART_RELEVANCE_DEFAULT, |
416 String importUri, | 410 String importUri, |
417 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { | 411 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { |
418 CompletionSuggestion cs = assertSuggest(name, | 412 CompletionSuggestion cs = assertSuggest(name, |
419 csKind: kind, | 413 csKind: kind, |
420 relevance: relevance, | 414 relevance: relevance, |
421 importUri: importUri, | 415 importUri: importUri, |
422 elemKind: protocol.ElementKind.SETTER); | 416 elemKind: ElementKind.SETTER); |
423 protocol.Element element = cs.element; | 417 Element element = cs.element; |
424 expect(element, isNotNull); | 418 expect(element, isNotNull); |
425 expect(element.kind, equals(protocol.ElementKind.SETTER)); | 419 expect(element.kind, equals(ElementKind.SETTER)); |
426 expect(element.name, equals(name)); | 420 expect(element.name, equals(name)); |
427 // TODO (danrubel) assert setter param | 421 // TODO (danrubel) assert setter param |
428 //expect(element.parameters, isNull); | 422 //expect(element.parameters, isNull); |
429 // TODO (danrubel) it would be better if this was always null | 423 // TODO (danrubel) it would be better if this was always null |
430 if (element.returnType != null) { | 424 if (element.returnType != null) { |
431 expect(element.returnType, 'dynamic'); | 425 expect(element.returnType, 'dynamic'); |
432 } | 426 } |
433 assertHasNoParameterInfo(cs); | 427 assertHasNoParameterInfo(cs); |
434 return cs; | 428 return cs; |
435 } | 429 } |
436 | 430 |
437 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, | 431 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, |
438 {int relevance: DART_RELEVANCE_DEFAULT, | 432 {int relevance: DART_RELEVANCE_DEFAULT, |
439 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 433 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
440 String importUri}) { | 434 String importUri}) { |
441 CompletionSuggestion cs = assertSuggest(name, | 435 CompletionSuggestion cs = assertSuggest(name, |
442 csKind: kind, relevance: relevance, importUri: importUri); | 436 csKind: kind, relevance: relevance, importUri: importUri); |
443 if (returnType != null) { | 437 if (returnType != null) { |
444 expect(cs.returnType, returnType); | 438 expect(cs.returnType, returnType); |
445 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 439 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
446 expect(cs.returnType, 'dynamic'); | 440 expect(cs.returnType, 'dynamic'); |
447 } | 441 } |
448 protocol.Element element = cs.element; | 442 Element element = cs.element; |
449 expect(element, isNotNull); | 443 expect(element, isNotNull); |
450 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); | 444 expect(element.kind, equals(ElementKind.TOP_LEVEL_VARIABLE)); |
451 expect(element.name, equals(name)); | 445 expect(element.name, equals(name)); |
452 expect(element.parameters, isNull); | 446 expect(element.parameters, isNull); |
453 if (returnType != null) { | 447 if (returnType != null) { |
454 expect(element.returnType, returnType); | 448 expect(element.returnType, returnType); |
455 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 449 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
456 expect(element.returnType, 'dynamic'); | 450 expect(element.returnType, 'dynamic'); |
457 } | 451 } |
458 assertHasNoParameterInfo(cs); | 452 assertHasNoParameterInfo(cs); |
459 return cs; | 453 return cs; |
460 } | 454 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 ..forEach((CompletionSuggestion suggestion) { | 564 ..forEach((CompletionSuggestion suggestion) { |
571 sb.write('\n ${suggestion.completion} -> $suggestion'); | 565 sb.write('\n ${suggestion.completion} -> $suggestion'); |
572 }); | 566 }); |
573 } | 567 } |
574 fail(sb.toString()); | 568 fail(sb.toString()); |
575 } | 569 } |
576 | 570 |
577 CompletionSuggestion getSuggest( | 571 CompletionSuggestion getSuggest( |
578 {String completion: null, | 572 {String completion: null, |
579 CompletionSuggestionKind csKind: null, | 573 CompletionSuggestionKind csKind: null, |
580 protocol.ElementKind elemKind: null}) { | 574 ElementKind elemKind: null}) { |
581 CompletionSuggestion cs; | 575 CompletionSuggestion cs; |
582 if (suggestions != null) { | 576 if (suggestions != null) { |
583 suggestions.forEach((CompletionSuggestion s) { | 577 suggestions.forEach((CompletionSuggestion s) { |
584 if (completion != null && completion != s.completion) { | 578 if (completion != null && completion != s.completion) { |
585 return; | 579 return; |
586 } | 580 } |
587 if (csKind != null && csKind != s.kind) { | 581 if (csKind != null && csKind != s.kind) { |
588 return; | 582 return; |
589 } | 583 } |
590 if (elemKind != null) { | 584 if (elemKind != null) { |
591 protocol.Element element = s.element; | 585 Element element = s.element; |
592 if (element == null || elemKind != element.kind) { | 586 if (element == null || elemKind != element.kind) { |
593 return; | 587 return; |
594 } | 588 } |
595 } | 589 } |
596 if (cs == null) { | 590 if (cs == null) { |
597 cs = s; | 591 cs = s; |
598 } else { | 592 } else { |
599 failedCompletion('expected exactly one $cs', | 593 failedCompletion('expected exactly one $cs', |
600 suggestions.where((s) => s.completion == completion)); | 594 suggestions.where((s) => s.completion == completion)); |
601 } | 595 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 629 |
636 @override | 630 @override |
637 void setUp() { | 631 void setUp() { |
638 super.setUp(); | 632 super.setUp(); |
639 index = createMemoryIndex(); | 633 index = createMemoryIndex(); |
640 searchEngine = | 634 searchEngine = |
641 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); | 635 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); |
642 contributor = createContributor(); | 636 contributor = createContributor(); |
643 } | 637 } |
644 } | 638 } |
OLD | NEW |