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

Side by Side Diff: pkg/analysis_server/test/services/completion/completion_test_util.dart

Issue 642973002: add if statement condition suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 CompletionSuggestion assertSuggestLocalFunction(String name, 474 CompletionSuggestion assertSuggestLocalFunction(String name,
475 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce = 475 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce =
476 CompletionRelevance.DEFAULT]) { 476 CompletionRelevance.DEFAULT]) {
477 if (computer is LocalComputer) { 477 if (computer is LocalComputer) {
478 return assertSuggestFunction(name, returnType, isDeprecated, relevance); 478 return assertSuggestFunction(name, returnType, isDeprecated, relevance);
479 } else { 479 } else {
480 return assertNotSuggested(name); 480 return assertNotSuggested(name);
481 } 481 }
482 } 482 }
483 483
484 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType,
485 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
486 if (computer is LocalComputer) {
487 return assertSuggestGetter(name, returnType, relevance);
488 } else {
489 return assertNotSuggested(name);
490 }
491 }
492
484 CompletionSuggestion assertSuggestLocalMethod(String name, 493 CompletionSuggestion assertSuggestLocalMethod(String name,
485 String declaringType, String returnType, [CompletionRelevance relevance = 494 String declaringType, String returnType, [CompletionRelevance relevance =
486 CompletionRelevance.DEFAULT]) { 495 CompletionRelevance.DEFAULT]) {
487 if (computer is LocalComputer) { 496 if (computer is LocalComputer) {
488 return assertSuggestMethod(name, declaringType, returnType, relevance); 497 return assertSuggestMethod(name, declaringType, returnType, relevance);
489 } else { 498 } else {
490 return assertNotSuggested(name); 499 return assertNotSuggested(name);
491 } 500 }
492 } 501 }
493 502
494 CompletionSuggestion assertSuggestLocalTopLevelVar(String name, 503 CompletionSuggestion assertSuggestLocalTopLevelVar(String name,
495 String returnType, [CompletionRelevance relevance = 504 String returnType, [CompletionRelevance relevance =
496 CompletionRelevance.DEFAULT]) { 505 CompletionRelevance.DEFAULT]) {
497 if (computer is LocalComputer) { 506 if (computer is LocalComputer) {
498 return assertSuggestTopLevelVar(name, returnType, relevance); 507 return assertSuggestTopLevelVar(name, returnType, relevance);
499 } else { 508 } else {
500 return assertNotSuggested(name); 509 return assertNotSuggested(name);
501 } 510 }
502 } 511 }
503 512
513 test_AsExpression_target() {
514 // IfStatement Block BlockFunctionBody
515 addTestSource('''
516 class A {int x; int y() => 0;}
517 main(){var a; if (^ is A)}''');
518 computeFast();
519 return computeFull(true).then((_) {
520 assertSuggestLocalVariable('a', null);
521 assertSuggestLocalFunction('main', null);
522 assertSuggestLocalClass('A');
523 assertSuggestImportedClass('Object');
524 });
525 }
526
527 test_AsExpression_type() {
528 // SimpleIdentifier TypeName IsExpression IfStatement
529 addTestSource('''
530 class A {int x; int y() => 0;}
531 main(){var a; if (a is ^)}''');
532 computeFast();
533 return computeFull(true).then((_) {
534 assertNotSuggested('a');
535 assertNotSuggested('main');
536 assertSuggestLocalClass('A');
537 assertSuggestImportedClass('Object');
538 });
539 }
540
504 test_BinaryExpression_LHS() { 541 test_BinaryExpression_LHS() {
505 // SimpleIdentifier BinaryExpression VariableDeclaration 542 // SimpleIdentifier BinaryExpression VariableDeclaration
506 // VariableDeclarationList VariableDeclarationStatement 543 // VariableDeclarationList VariableDeclarationStatement
507 addTestSource('main() {int a = 1, b = ^ + 2;}'); 544 addTestSource('main() {int a = 1, b = ^ + 2;}');
508 computeFast(); 545 computeFast();
509 return computeFull(true).then((_) { 546 return computeFull(true).then((_) {
510 assertSuggestLocalVariable('a', 'int'); 547 assertSuggestLocalVariable('a', 'int');
511 assertSuggestImportedClass('Object'); 548 assertSuggestImportedClass('Object');
512 assertNotSuggested('b'); 549 assertNotSuggested('b');
513 }); 550 });
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 980
944 test_ForStatement_updaters_prefix_expression() { 981 test_ForStatement_updaters_prefix_expression() {
945 // SimpleIdentifier PrefixExpression ForStatement 982 // SimpleIdentifier PrefixExpression ForStatement
946 addTestSource('main() {for (int index = 0; index < 10; ++i^)}'); 983 addTestSource('main() {for (int index = 0; index < 10; ++i^)}');
947 computeFast(); 984 computeFast();
948 return computeFull(true).then((_) { 985 return computeFull(true).then((_) {
949 assertSuggestLocalVariable('index', 'int'); 986 assertSuggestLocalVariable('index', 'int');
950 }); 987 });
951 } 988 }
952 989
990 test_FunctionExpression_body_function() {
991 // Block BlockFunctionBody FunctionExpression
992 addTestSource('String foo(List args) {x.then((R b) {^});}');
993 computeFast();
994 return computeFull(true).then((_) {
995 var f = assertSuggestLocalFunction('foo', 'String', false);
996 if (f != null) {
997 expect(f.element.isPrivate, isFalse);
998 }
999 assertSuggestParameter('args', 'List');
1000 assertSuggestParameter('b', 'R');
1001 assertSuggestImportedClass('Object');
1002 });
1003 }
1004
1005 test_IfStatement_condition() {
1006 // SimpleIdentifier IfStatement Block BlockFunctionBody
1007 addTestSource('''
1008 class A {int x; int y() => 0;}
1009 main(){var a; if (^)}''');
1010 computeFast();
1011 return computeFull(true).then((_) {
1012 assertSuggestLocalVariable('a', null);
1013 assertSuggestLocalFunction('main', null);
1014 assertSuggestLocalClass('A');
1015 assertSuggestImportedClass('Object');
1016 });
1017 }
1018
953 test_ImportDirective_dart() { 1019 test_ImportDirective_dart() {
954 // SimpleStringLiteral ImportDirective 1020 // SimpleStringLiteral ImportDirective
955 addTestSource(''' 1021 addTestSource('''
956 import "dart^"; 1022 import "dart^";
957 main() {}'''); 1023 main() {}''');
958 computeFast(); 1024 computeFast();
959 return computeFull(true).then((_) { 1025 return computeFull(true).then((_) {
960 assertNoSuggestions(); 1026 assertNoSuggestions();
961 }); 1027 });
962 } 1028 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 computeFast(); 1110 computeFast();
1045 return computeFull(true).then((_) { 1111 return computeFull(true).then((_) {
1046 assertSuggestImportedClass('X'); 1112 assertSuggestImportedClass('X');
1047 assertSuggestLocalClass('Y'); 1113 assertSuggestLocalClass('Y');
1048 assertNotSuggested('x'); 1114 assertNotSuggested('x');
1049 assertNotSuggested('main'); 1115 assertNotSuggested('main');
1050 assertNotSuggested('foo'); 1116 assertNotSuggested('foo');
1051 }); 1117 });
1052 } 1118 }
1053 1119
1120 test_MethodDeclaration_body_getters() {
1121 // Block BlockFunctionBody MethodDeclaration
1122 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}');
1123 computeFast();
1124 return computeFull(true).then((_) {
1125 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z');
1126 if (methodA != null) {
1127 expect(methodA.element.isDeprecated, isFalse);
1128 expect(methodA.element.isPrivate, isFalse);
1129 }
1130 CompletionSuggestion getterF = assertSuggestLocalGetter('f', 'X');
1131 if (getterF != null) {
1132 expect(getterF.element.isDeprecated, isTrue);
1133 expect(getterF.element.isPrivate, isFalse);
1134 }
1135 CompletionSuggestion getterG = assertSuggestLocalGetter('_g', null);
1136 if (getterG != null) {
1137 expect(getterG.element.isDeprecated, isFalse);
1138 expect(getterG.element.isPrivate, isTrue);
1139 }
1140 });
1141 }
1142
1143 test_MethodDeclaration_members() {
1144 // Block BlockFunctionBody MethodDeclaration
1145 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}');
1146 computeFast();
1147 return computeFull(true).then((_) {
1148 CompletionSuggestion methodA = assertSuggestLocalMethod('_a', 'A', 'Z');
1149 if (methodA != null) {
1150 expect(methodA.element.isDeprecated, isFalse);
1151 expect(methodA.element.isPrivate, isTrue);
1152 }
1153 CompletionSuggestion getterF = assertSuggestLocalGetter('f', 'X');
1154 if (getterF != null) {
1155 expect(getterF.element.isDeprecated, isTrue);
1156 expect(getterF.element.isPrivate, isFalse);
1157 }
1158 CompletionSuggestion getterG = assertSuggestLocalGetter('_g', null);
1159 if (getterG != null) {
1160 expect(getterG.element.isDeprecated, isFalse);
1161 expect(getterG.element.isPrivate, isTrue);
1162 }
1163 assertSuggestImportedClass('bool');
1164 });
1165 }
1166
1167 test_MethodDeclaration_parameters_named() {
1168 // Block BlockFunctionBody MethodDeclaration
1169 addTestSource('class A {@deprecated Z a(X x, {y: boo}) {^}}');
1170 computeFast();
1171 return computeFull(true).then((_) {
1172 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z');
1173 if (methodA != null) {
1174 expect(methodA.element.isDeprecated, isTrue);
1175 expect(methodA.element.isPrivate, isFalse);
1176 }
1177 assertSuggestParameter('x', 'X');
1178 assertSuggestParameter('y', null);
1179 assertSuggestImportedClass('int');
1180 });
1181 }
1182
1183 test_MethodDeclaration_parameters_positional() {
1184 // Block BlockFunctionBody MethodDeclaration
1185 addTestSource('class A {Z a(X x, [int y=1]) {^}}');
1186 computeFast();
1187 return computeFull(true).then((_) {
1188 assertSuggestLocalMethod('a', 'A', 'Z');
1189 assertSuggestParameter('x', 'X');
1190 assertSuggestParameter('y', 'int');
1191 assertSuggestImportedClass('String');
1192 });
1193 }
1194
1054 test_PrefixedIdentifier_class_imported() { 1195 test_PrefixedIdentifier_class_imported() {
1055 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 1196 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
1056 addSource('/testB.dart', ''' 1197 addSource('/testB.dart', '''
1057 lib B; 1198 lib B;
1058 class I {X get f => new A();get _g => new A();} 1199 class I {X get f => new A();get _g => new A();}
1059 class A implements I { 1200 class A implements I {
1060 var b; X _c; 1201 var b; X _c;
1061 X get d => new A();get _e => new A(); 1202 X get d => new A();get _e => new A();
1062 set s1(I x) {} set _s2(I x) {} 1203 set s1(I x) {} set _s2(I x) {}
1063 m(X x) {} I _n(X x) {}} 1204 m(X x) {} I _n(X x) {}}
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 addTestSource(''' 1393 addTestSource('''
1253 import "/testB.dart"; 1394 import "/testB.dart";
1254 class Y {Y.c(); Y._d(); z() {}} 1395 class Y {Y.c(); Y._d(); z() {}}
1255 main() {var ^}'''); 1396 main() {var ^}''');
1256 computeFast(); 1397 computeFast();
1257 return computeFull(true).then((_) { 1398 return computeFull(true).then((_) {
1258 assertNoSuggestions(); 1399 assertNoSuggestions();
1259 }); 1400 });
1260 } 1401 }
1261 } 1402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698