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/plugin/protocol/protocol.dart' as protocol | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
10 show Element, ElementKind; | 10 show Element, ElementKind; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 expect(element.name, equals(name)); | 349 expect(element.name, equals(name)); |
350 String param = element.parameters; | 350 String param = element.parameters; |
351 expect(param, isNotNull); | 351 expect(param, isNotNull); |
352 expect(param[0], equals('(')); | 352 expect(param[0], equals('(')); |
353 expect(param[param.length - 1], equals(')')); | 353 expect(param[param.length - 1], equals(')')); |
354 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 354 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
355 assertHasParameterInfo(cs); | 355 assertHasParameterInfo(cs); |
356 return cs; | 356 return cs; |
357 } | 357 } |
358 | 358 |
359 CompletionSuggestion assertSuggestNamedConstructor( | |
360 String name, String returnType, | |
361 [int relevance = DART_RELEVANCE_DEFAULT, | |
362 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | |
363 if (contributor is PrefixedElementContributor) { | |
364 CompletionSuggestion cs = | |
365 assertSuggest(name, csKind: kind, relevance: relevance); | |
366 protocol.Element element = cs.element; | |
367 expect(element, isNotNull); | |
368 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | |
369 expect(element.name, equals(name)); | |
370 String param = element.parameters; | |
371 expect(param, isNotNull); | |
372 expect(param[0], equals('(')); | |
373 expect(param[param.length - 1], equals(')')); | |
374 expect(element.returnType, equals(returnType)); | |
375 assertHasParameterInfo(cs); | |
376 return cs; | |
377 } else { | |
378 return assertNotSuggested(name); | |
379 } | |
380 } | |
381 | |
382 CompletionSuggestion assertSuggestParameter(String name, String returnType, | 359 CompletionSuggestion assertSuggestParameter(String name, String returnType, |
383 {int relevance: DART_RELEVANCE_PARAMETER}) { | 360 {int relevance: DART_RELEVANCE_PARAMETER}) { |
384 return assertNotSuggested(name); | 361 return assertNotSuggested(name); |
385 } | 362 } |
386 | 363 |
387 CompletionSuggestion assertSuggestSetter(String name, | 364 CompletionSuggestion assertSuggestSetter(String name, |
388 [int relevance = DART_RELEVANCE_DEFAULT, | 365 [int relevance = DART_RELEVANCE_DEFAULT, |
389 String importUri, | 366 String importUri, |
390 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 367 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
391 CompletionSuggestion cs = assertSuggest(name, | 368 CompletionSuggestion cs = assertSuggest(name, |
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2445 F1() { } | 2422 F1() { } |
2446 class X {X.c(); X._d(); z() {}}'''); | 2423 class X {X.c(); X._d(); z() {}}'''); |
2447 addTestSource(''' | 2424 addTestSource(''' |
2448 import "/testB.dart"; | 2425 import "/testB.dart"; |
2449 var m; | 2426 var m; |
2450 main() {new X.^}'''); | 2427 main() {new X.^}'''); |
2451 computeFast(); | 2428 computeFast(); |
2452 return computeFull((bool result) { | 2429 return computeFull((bool result) { |
2453 expect(request.replacementOffset, completionOffset); | 2430 expect(request.replacementOffset, completionOffset); |
2454 expect(request.replacementLength, 0); | 2431 expect(request.replacementLength, 0); |
2455 assertSuggestNamedConstructor('c', 'X'); | 2432 // Suggested by NamedConstructorContributor |
| 2433 assertNotSuggested('c'); |
2456 assertNotSuggested('F1'); | 2434 assertNotSuggested('F1'); |
2457 assertNotSuggested('T1'); | 2435 assertNotSuggested('T1'); |
2458 assertNotSuggested('_d'); | 2436 assertNotSuggested('_d'); |
2459 assertNotSuggested('z'); | 2437 assertNotSuggested('z'); |
2460 assertNotSuggested('m'); | 2438 assertNotSuggested('m'); |
2461 }); | 2439 }); |
2462 } | 2440 } |
2463 | 2441 |
2464 test_ConstructorName_importedFactory() { | 2442 test_ConstructorName_importedFactory() { |
2465 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 2443 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
2466 // InstanceCreationExpression | 2444 // InstanceCreationExpression |
2467 addSource( | 2445 addSource( |
2468 '/testB.dart', | 2446 '/testB.dart', |
2469 ''' | 2447 ''' |
2470 lib B; | 2448 lib B; |
2471 int T1; | 2449 int T1; |
2472 F1() { } | 2450 F1() { } |
2473 class X {factory X.c(); factory X._d(); z() {}}'''); | 2451 class X {factory X.c(); factory X._d(); z() {}}'''); |
2474 addTestSource(''' | 2452 addTestSource(''' |
2475 import "/testB.dart"; | 2453 import "/testB.dart"; |
2476 var m; | 2454 var m; |
2477 main() {new X.^}'''); | 2455 main() {new X.^}'''); |
2478 computeFast(); | 2456 computeFast(); |
2479 return computeFull((bool result) { | 2457 return computeFull((bool result) { |
2480 expect(request.replacementOffset, completionOffset); | 2458 expect(request.replacementOffset, completionOffset); |
2481 expect(request.replacementLength, 0); | 2459 expect(request.replacementLength, 0); |
2482 assertSuggestNamedConstructor('c', 'X'); | 2460 // Suggested by NamedConstructorContributor |
| 2461 assertNotSuggested('c'); |
2483 assertNotSuggested('F1'); | 2462 assertNotSuggested('F1'); |
2484 assertNotSuggested('T1'); | 2463 assertNotSuggested('T1'); |
2485 assertNotSuggested('_d'); | 2464 assertNotSuggested('_d'); |
2486 assertNotSuggested('z'); | 2465 assertNotSuggested('z'); |
2487 assertNotSuggested('m'); | 2466 assertNotSuggested('m'); |
2488 }); | 2467 }); |
2489 } | 2468 } |
2490 | 2469 |
2491 test_ConstructorName_importedFactory2() { | 2470 test_ConstructorName_importedFactory2() { |
2492 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 2471 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
2493 // InstanceCreationExpression | 2472 // InstanceCreationExpression |
2494 addTestSource(''' | 2473 addTestSource(''' |
2495 main() {new String.fr^omCharCodes([]);}'''); | 2474 main() {new String.fr^omCharCodes([]);}'''); |
2496 computeFast(); | 2475 computeFast(); |
2497 return computeFull((bool result) { | 2476 return computeFull((bool result) { |
2498 expect(request.replacementOffset, completionOffset - 2); | 2477 expect(request.replacementOffset, completionOffset - 2); |
2499 expect(request.replacementLength, 13); | 2478 expect(request.replacementLength, 13); |
2500 assertSuggestNamedConstructor('fromCharCodes', 'String'); | 2479 // Suggested by NamedConstructorContributor |
| 2480 assertNotSuggested('fromCharCodes'); |
2501 assertNotSuggested('isEmpty'); | 2481 assertNotSuggested('isEmpty'); |
2502 assertNotSuggested('isNotEmpty'); | 2482 assertNotSuggested('isNotEmpty'); |
2503 assertNotSuggested('length'); | 2483 assertNotSuggested('length'); |
2504 assertNotSuggested('Object'); | 2484 assertNotSuggested('Object'); |
2505 assertNotSuggested('String'); | 2485 assertNotSuggested('String'); |
2506 }); | 2486 }); |
2507 } | 2487 } |
2508 | 2488 |
2509 test_ConstructorName_localClass() { | 2489 test_ConstructorName_localClass() { |
2510 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 2490 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
2511 // InstanceCreationExpression | 2491 // InstanceCreationExpression |
2512 addTestSource(''' | 2492 addTestSource(''' |
2513 int T1; | 2493 int T1; |
2514 F1() { } | 2494 F1() { } |
2515 class X {X.c(); X._d(); z() {}} | 2495 class X {X.c(); X._d(); z() {}} |
2516 main() {new X.^}'''); | 2496 main() {new X.^}'''); |
2517 computeFast(); | 2497 computeFast(); |
2518 return computeFull((bool result) { | 2498 return computeFull((bool result) { |
2519 expect(request.replacementOffset, completionOffset); | 2499 expect(request.replacementOffset, completionOffset); |
2520 expect(request.replacementLength, 0); | 2500 expect(request.replacementLength, 0); |
2521 assertSuggestNamedConstructor('c', 'X'); | 2501 // Suggested by NamedConstructorContributor |
2522 assertSuggestNamedConstructor('_d', 'X'); | 2502 assertNotSuggested('c'); |
| 2503 assertNotSuggested('_d'); |
2523 assertNotSuggested('F1'); | 2504 assertNotSuggested('F1'); |
2524 assertNotSuggested('T1'); | 2505 assertNotSuggested('T1'); |
2525 assertNotSuggested('z'); | 2506 assertNotSuggested('z'); |
2526 assertNotSuggested('m'); | 2507 assertNotSuggested('m'); |
2527 }); | 2508 }); |
2528 } | 2509 } |
2529 | 2510 |
2530 test_ConstructorName_localFactory() { | 2511 test_ConstructorName_localFactory() { |
2531 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 2512 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
2532 // InstanceCreationExpression | 2513 // InstanceCreationExpression |
2533 addTestSource(''' | 2514 addTestSource(''' |
2534 int T1; | 2515 int T1; |
2535 F1() { } | 2516 F1() { } |
2536 class X {factory X.c(); factory X._d(); z() {}} | 2517 class X {factory X.c(); factory X._d(); z() {}} |
2537 main() {new X.^}'''); | 2518 main() {new X.^}'''); |
2538 computeFast(); | 2519 computeFast(); |
2539 return computeFull((bool result) { | 2520 return computeFull((bool result) { |
2540 expect(request.replacementOffset, completionOffset); | 2521 expect(request.replacementOffset, completionOffset); |
2541 expect(request.replacementLength, 0); | 2522 expect(request.replacementLength, 0); |
2542 assertSuggestNamedConstructor('c', 'X'); | 2523 // Suggested by NamedConstructorContributor |
2543 assertSuggestNamedConstructor('_d', 'X'); | 2524 assertNotSuggested('c'); |
| 2525 assertNotSuggested('_d'); |
2544 assertNotSuggested('F1'); | 2526 assertNotSuggested('F1'); |
2545 assertNotSuggested('T1'); | 2527 assertNotSuggested('T1'); |
2546 assertNotSuggested('z'); | 2528 assertNotSuggested('z'); |
2547 assertNotSuggested('m'); | 2529 assertNotSuggested('m'); |
2548 }); | 2530 }); |
2549 } | 2531 } |
2550 | 2532 |
2551 test_DefaultFormalParameter_named_expression() { | 2533 test_DefaultFormalParameter_named_expression() { |
2552 // DefaultFormalParameter FormalParameterList MethodDeclaration | 2534 // DefaultFormalParameter FormalParameterList MethodDeclaration |
2553 addTestSource(''' | 2535 addTestSource(''' |
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4713 assertNotSuggested('bar2'); | 4695 assertNotSuggested('bar2'); |
4714 assertNotSuggested('_B'); | 4696 assertNotSuggested('_B'); |
4715 assertSuggestLocalClass('Y'); | 4697 assertSuggestLocalClass('Y'); |
4716 assertSuggestLocalClass('C'); | 4698 assertSuggestLocalClass('C'); |
4717 assertSuggestLocalVariable('f', null); | 4699 assertSuggestLocalVariable('f', null); |
4718 assertNotSuggested('x'); | 4700 assertNotSuggested('x'); |
4719 assertNotSuggested('e'); | 4701 assertNotSuggested('e'); |
4720 }); | 4702 }); |
4721 } | 4703 } |
4722 } | 4704 } |
OLD | NEW |