| 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 show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 String param = element.parameters; | 129 String param = element.parameters; |
| 130 expect(param, isNotNull); | 130 expect(param, isNotNull); |
| 131 expect(param[0], equals('(')); | 131 expect(param[0], equals('(')); |
| 132 expect(param[param.length - 1], equals(')')); | 132 expect(param[param.length - 1], equals(')')); |
| 133 expect( | 133 expect( |
| 134 element.returnType, | 134 element.returnType, |
| 135 equals(returnType != null ? returnType : 'dynamic')); | 135 equals(returnType != null ? returnType : 'dynamic')); |
| 136 return cs; | 136 return cs; |
| 137 } | 137 } |
| 138 | 138 |
| 139 CompletionSuggestion assertSuggestFunctionTypeAlias(String name, |
| 140 String returnType, bool isDeprecated, [CompletionRelevance relevance = |
| 141 CompletionRelevance.DEFAULT]) { |
| 142 CompletionSuggestion cs = assertSuggest( |
| 143 CompletionSuggestionKind.FUNCTION_TYPE_ALIAS, |
| 144 name, |
| 145 relevance, |
| 146 isDeprecated); |
| 147 expect(cs.returnType, equals(returnType)); |
| 148 protocol.Element element = cs.element; |
| 149 expect(element, isNotNull); |
| 150 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); |
| 151 expect(element.name, equals(name)); |
| 152 expect(element.isDeprecated, equals(isDeprecated)); |
| 153 // TODO (danrubel) Determine why params are null |
| 154 // String param = element.parameters; |
| 155 // expect(param, isNotNull); |
| 156 // expect(param[0], equals('(')); |
| 157 // expect(param[param.length - 1], equals(')')); |
| 158 // TODO (danrubel) Determine why return type is null |
| 159 // expect( |
| 160 // element.returnType, |
| 161 // equals(returnType != null ? returnType : 'dynamic')); |
| 162 return cs; |
| 163 } |
| 164 |
| 139 CompletionSuggestion assertSuggestGetter(String name, String returnType, | 165 CompletionSuggestion assertSuggestGetter(String name, String returnType, |
| 140 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 166 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 141 CompletionSuggestion cs = | 167 CompletionSuggestion cs = |
| 142 assertSuggest(CompletionSuggestionKind.GETTER, name, relevance); | 168 assertSuggest(CompletionSuggestionKind.GETTER, name, relevance); |
| 143 expect(cs.returnType, equals(returnType)); | 169 expect(cs.returnType, equals(returnType)); |
| 144 protocol.Element element = cs.element; | 170 protocol.Element element = cs.element; |
| 145 expect(element, isNotNull); | 171 expect(element, isNotNull); |
| 146 expect(element.kind, equals(protocol.ElementKind.GETTER)); | 172 expect(element.kind, equals(protocol.ElementKind.GETTER)); |
| 147 expect(element.name, equals(name)); | 173 expect(element.name, equals(name)); |
| 148 //TODO (danrubel) getter should have parameters | 174 //TODO (danrubel) getter should have parameters |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 CompletionSuggestion assertSuggestImportedFunction(String name, | 445 CompletionSuggestion assertSuggestImportedFunction(String name, |
| 420 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = | 446 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 421 CompletionRelevance.DEFAULT]) { | 447 CompletionRelevance.DEFAULT]) { |
| 422 if (computer is ImportedComputer) { | 448 if (computer is ImportedComputer) { |
| 423 return assertSuggestFunction(name, returnType, isDeprecated, relevance); | 449 return assertSuggestFunction(name, returnType, isDeprecated, relevance); |
| 424 } else { | 450 } else { |
| 425 return assertNotSuggested(name); | 451 return assertNotSuggested(name); |
| 426 } | 452 } |
| 427 } | 453 } |
| 428 | 454 |
| 455 CompletionSuggestion assertSuggestImportedFunctionTypeAlias(String name, |
| 456 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 457 CompletionRelevance.DEFAULT]) { |
| 458 if (computer is ImportedComputer) { |
| 459 return assertSuggestFunctionTypeAlias( |
| 460 name, |
| 461 returnType, |
| 462 isDeprecated, |
| 463 relevance); |
| 464 } else { |
| 465 return assertNotSuggested(name); |
| 466 } |
| 467 } |
| 468 |
| 429 CompletionSuggestion assertSuggestImportedGetter(String name, | 469 CompletionSuggestion assertSuggestImportedGetter(String name, |
| 430 String returnType, [CompletionRelevance relevance = | 470 String returnType, [CompletionRelevance relevance = |
| 431 CompletionRelevance.DEFAULT]) { | 471 CompletionRelevance.DEFAULT]) { |
| 432 if (computer is ImportedComputer) { | 472 if (computer is ImportedComputer) { |
| 433 return assertSuggestGetter(name, returnType, relevance); | 473 return assertSuggestGetter(name, returnType, relevance); |
| 434 } else { | 474 } else { |
| 435 return assertNotSuggested(name); | 475 return assertNotSuggested(name); |
| 436 } | 476 } |
| 437 } | 477 } |
| 438 | 478 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 CompletionSuggestion assertSuggestLocalFunction(String name, | 556 CompletionSuggestion assertSuggestLocalFunction(String name, |
| 517 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = | 557 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 518 CompletionRelevance.DEFAULT]) { | 558 CompletionRelevance.DEFAULT]) { |
| 519 if (computer is LocalComputer) { | 559 if (computer is LocalComputer) { |
| 520 return assertSuggestFunction(name, returnType, isDeprecated, relevance); | 560 return assertSuggestFunction(name, returnType, isDeprecated, relevance); |
| 521 } else { | 561 } else { |
| 522 return assertNotSuggested(name); | 562 return assertNotSuggested(name); |
| 523 } | 563 } |
| 524 } | 564 } |
| 525 | 565 |
| 566 CompletionSuggestion assertSuggestLocalFunctionTypeAlias(String name, |
| 567 String returnType, [bool isDeprecated = false, CompletionRelevance relevan
ce = |
| 568 CompletionRelevance.DEFAULT]) { |
| 569 if (computer is LocalComputer) { |
| 570 return assertSuggestFunctionTypeAlias( |
| 571 name, |
| 572 returnType, |
| 573 isDeprecated, |
| 574 relevance); |
| 575 } else { |
| 576 return assertNotSuggested(name); |
| 577 } |
| 578 } |
| 579 |
| 526 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, | 580 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, |
| 527 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { | 581 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 528 if (computer is LocalComputer) { | 582 if (computer is LocalComputer) { |
| 529 return assertSuggestGetter(name, returnType, relevance); | 583 return assertSuggestGetter(name, returnType, relevance); |
| 530 } else { | 584 } else { |
| 531 return assertNotSuggested(name); | 585 return assertNotSuggested(name); |
| 532 } | 586 } |
| 533 } | 587 } |
| 534 | 588 |
| 535 CompletionSuggestion assertSuggestLocalMethod(String name, | 589 CompletionSuggestion assertSuggestLocalMethod(String name, |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 // SimpleIdentifier HideCombinator ImportDirective | 974 // SimpleIdentifier HideCombinator ImportDirective |
| 921 addSource('/testAB.dart', ''' | 975 addSource('/testAB.dart', ''' |
| 922 library libAB; | 976 library libAB; |
| 923 part '/partAB.dart'; | 977 part '/partAB.dart'; |
| 924 class A { } | 978 class A { } |
| 925 class B { }'''); | 979 class B { }'''); |
| 926 addSource('/partAB.dart', ''' | 980 addSource('/partAB.dart', ''' |
| 927 part of libAB; | 981 part of libAB; |
| 928 var T1; | 982 var T1; |
| 929 PB F1() => new PB(); | 983 PB F1() => new PB(); |
| 984 typedef PB2 F2(int blat); |
| 930 class PB { }'''); | 985 class PB { }'''); |
| 931 addSource('/testCD.dart', ''' | 986 addSource('/testCD.dart', ''' |
| 932 class C { } | 987 class C { } |
| 933 class D { }'''); | 988 class D { }'''); |
| 934 addTestSource(''' | 989 addTestSource(''' |
| 935 import "/testAB.dart" show ^; | 990 import "/testAB.dart" show ^; |
| 936 import "/testCD.dart"; | 991 import "/testCD.dart"; |
| 937 class X {}'''); | 992 class X {}'''); |
| 938 computeFast(); | 993 computeFast(); |
| 939 return computeFull(true).then((_) { | 994 return computeFull(true).then((_) { |
| 940 assertSuggestImportedClass('A'); | 995 assertSuggestImportedClass('A'); |
| 941 assertSuggestImportedClass('B'); | 996 assertSuggestImportedClass('B'); |
| 942 assertSuggestImportedClass('PB'); | 997 assertSuggestImportedClass('PB'); |
| 943 assertSuggestImportedTopLevelVar('T1', null); | 998 assertSuggestImportedTopLevelVar('T1', null); |
| 944 assertSuggestImportedFunction('F1', 'PB'); | 999 assertSuggestImportedFunction('F1', 'PB'); |
| 1000 assertSuggestImportedFunctionTypeAlias('F2', null); |
| 945 assertNotSuggested('C'); | 1001 assertNotSuggested('C'); |
| 946 assertNotSuggested('D'); | 1002 assertNotSuggested('D'); |
| 947 assertNotSuggested('X'); | 1003 assertNotSuggested('X'); |
| 948 assertNotSuggested('Object'); | 1004 assertNotSuggested('Object'); |
| 949 }); | 1005 }); |
| 950 } | 1006 } |
| 951 | 1007 |
| 952 test_ConstructorName_importedClass() { | 1008 test_ConstructorName_importedClass() { |
| 953 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName | 1009 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName |
| 954 // InstanceCreationExpression | 1010 // InstanceCreationExpression |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 } | 1048 } |
| 993 | 1049 |
| 994 test_ExpressionStatement_identifier() { | 1050 test_ExpressionStatement_identifier() { |
| 995 // SimpleIdentifier ExpressionStatement Block | 1051 // SimpleIdentifier ExpressionStatement Block |
| 996 addSource('/testA.dart', ''' | 1052 addSource('/testA.dart', ''' |
| 997 _B F1() { } | 1053 _B F1() { } |
| 998 class A {int x;} | 1054 class A {int x;} |
| 999 class _B { }'''); | 1055 class _B { }'''); |
| 1000 addTestSource(''' | 1056 addTestSource(''' |
| 1001 import "/testA.dart"; | 1057 import "/testA.dart"; |
| 1058 typedef int F2(int blat); |
| 1002 class C {foo(){O^} void bar() {}}'''); | 1059 class C {foo(){O^} void bar() {}}'''); |
| 1003 computeFast(); | 1060 computeFast(); |
| 1004 return computeFull(true).then((_) { | 1061 return computeFull(true).then((_) { |
| 1005 assertSuggestImportedClass('A'); | 1062 assertSuggestImportedClass('A'); |
| 1006 assertSuggestImportedFunction('F1', '_B', false); | 1063 assertSuggestImportedFunction('F1', '_B', false); |
| 1007 assertSuggestLocalClass('C'); | 1064 assertSuggestLocalClass('C'); |
| 1008 assertSuggestLocalMethod('foo', 'C', null); | 1065 assertSuggestLocalMethod('foo', 'C', null); |
| 1009 assertSuggestLocalMethod('bar', 'C', 'void'); | 1066 assertSuggestLocalMethod('bar', 'C', 'void'); |
| 1067 assertSuggestLocalFunctionTypeAlias('F2', 'int'); |
| 1010 assertSuggestLocalClass('C'); | 1068 assertSuggestLocalClass('C'); |
| 1011 assertNotSuggested('x'); | 1069 assertNotSuggested('x'); |
| 1012 assertNotSuggested('_B'); | 1070 assertNotSuggested('_B'); |
| 1013 }); | 1071 }); |
| 1014 } | 1072 } |
| 1015 | 1073 |
| 1016 test_ExpressionStatement_name() { | 1074 test_ExpressionStatement_name() { |
| 1017 // ExpressionStatement Block BlockFunctionBody MethodDeclaration | 1075 // ExpressionStatement Block BlockFunctionBody MethodDeclaration |
| 1018 addSource('/testA.dart', ''' | 1076 addSource('/testA.dart', ''' |
| 1019 B T1; | 1077 B T1; |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 assertNotSuggested('bar2'); | 1769 assertNotSuggested('bar2'); |
| 1712 assertNotSuggested('_B'); | 1770 assertNotSuggested('_B'); |
| 1713 assertSuggestLocalClass('Y'); | 1771 assertSuggestLocalClass('Y'); |
| 1714 assertSuggestLocalClass('C'); | 1772 assertSuggestLocalClass('C'); |
| 1715 assertSuggestLocalVariable('f', null); | 1773 assertSuggestLocalVariable('f', null); |
| 1716 assertNotSuggested('x'); | 1774 assertNotSuggested('x'); |
| 1717 assertNotSuggested('e'); | 1775 assertNotSuggested('e'); |
| 1718 }); | 1776 }); |
| 1719 } | 1777 } |
| 1720 } | 1778 } |
| OLD | NEW |