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

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

Issue 651953006: improve method invocation and string interpolation 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/local_computer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 CompletionSuggestion assertSuggestLocalTopLevelVar(String name, 503 CompletionSuggestion assertSuggestLocalTopLevelVar(String name,
504 String returnType, [CompletionRelevance relevance = 504 String returnType, [CompletionRelevance relevance =
505 CompletionRelevance.DEFAULT]) { 505 CompletionRelevance.DEFAULT]) {
506 if (computer is LocalComputer) { 506 if (computer is LocalComputer) {
507 return assertSuggestTopLevelVar(name, returnType, relevance); 507 return assertSuggestTopLevelVar(name, returnType, relevance);
508 } else { 508 } else {
509 return assertNotSuggested(name); 509 return assertNotSuggested(name);
510 } 510 }
511 } 511 }
512 512
513 test_AsExpression_target() { 513 test_AssignmentExpression_name() {
514 // IfStatement Block BlockFunctionBody 514 // SimpleIdentifier VariableDeclaration VariableDeclarationList
515 addTestSource(''' 515 // VariableDeclarationStatement Block
516 class A {int x; int y() => 0;} 516 addTestSource('class A {} main() {int a; int ^b = 1;}');
517 main(){var a; if (^ is A)}''');
518 computeFast(); 517 computeFast();
519 return computeFull(true).then((_) { 518 return computeFull(true).then((_) {
520 assertSuggestLocalVariable('a', null); 519 assertNoSuggestions();
521 assertSuggestLocalFunction('main', null);
522 assertSuggestLocalClass('A');
523 assertSuggestImportedClass('Object');
524 }); 520 });
525 } 521 }
526 522
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
541 test_AssignmentExpression_RHS() { 523 test_AssignmentExpression_RHS() {
542 // SimpleIdentifier VariableDeclaration VariableDeclarationList 524 // SimpleIdentifier VariableDeclaration VariableDeclarationList
543 // VariableDeclarationStatement Block 525 // VariableDeclarationStatement Block
544 addTestSource('class A {} main() {int a; int b = ^}'); 526 addTestSource('class A {} main() {int a; int b = ^}');
545 computeFast(); 527 computeFast();
546 return computeFull(true).then((_) { 528 return computeFull(true).then((_) {
547 assertSuggestLocalVariable('a', 'int'); 529 assertSuggestLocalVariable('a', 'int');
548 assertSuggestLocalFunction('main', null); 530 assertSuggestLocalFunction('main', null);
549 assertSuggestLocalClass('A'); 531 assertSuggestLocalClass('A');
550 assertSuggestImportedClass('Object'); 532 assertSuggestImportedClass('Object');
551 }); 533 });
552 } 534 }
553 535
554 test_AssignmentExpression_name() {
555 // SimpleIdentifier VariableDeclaration VariableDeclarationList
556 // VariableDeclarationStatement Block
557 addTestSource('class A {} main() {int a; int ^b = 1;}');
558 computeFast();
559 return computeFull(true).then((_) {
560 assertNoSuggestions();
561 });
562 }
563
564 test_AssignmentExpression_type() { 536 test_AssignmentExpression_type() {
565 // SimpleIdentifier TypeName VariableDeclarationList 537 // SimpleIdentifier TypeName VariableDeclarationList
566 // VariableDeclarationStatement Block 538 // VariableDeclarationStatement Block
567 addTestSource('class A {} main() {int a; int^ b = 1;}'); 539 addTestSource('class A {} main() {int a; int^ b = 1;}');
568 computeFast(); 540 computeFast();
569 return computeFull(true).then((_) { 541 return computeFull(true).then((_) {
570 assertSuggestLocalClass('A'); 542 assertSuggestLocalClass('A');
571 assertSuggestImportedClass('int'); 543 assertSuggestImportedClass('int');
572 assertNotSuggested('a'); 544 assertNotSuggested('a');
573 assertNotSuggested('main'); 545 assertNotSuggested('main');
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 assertNotSuggested('f'); 1070 assertNotSuggested('f');
1099 assertNotSuggested('x'); 1071 assertNotSuggested('x');
1100 assertNotSuggested('foo'); 1072 assertNotSuggested('foo');
1101 assertNotSuggested('F1'); 1073 assertNotSuggested('F1');
1102 assertNotSuggested('F2'); 1074 assertNotSuggested('F2');
1103 assertNotSuggested('T1'); 1075 assertNotSuggested('T1');
1104 assertNotSuggested('T2'); 1076 assertNotSuggested('T2');
1105 }); 1077 });
1106 } 1078 }
1107 1079
1108 // test_InterpolationExpression() { 1080 test_InterpolationExpression() {
1109 // // SimpleIdentifier InterpolationExpression StringInterpolation 1081 // SimpleIdentifier InterpolationExpression StringInterpolation
1110 // addTestSource('main() {String name; print("hello \$^");}'); 1082 addTestSource('main() {String name; print("hello \$^");}');
1111 // computeFast(); 1083 computeFast();
1112 // return computeFull(true).then((_) { 1084 return computeFull(true).then((_) {
1113 // assertSuggestLocalVariable('name', 'String'); 1085 assertSuggestLocalVariable('name', 'String');
1114 // assertSuggestImportedClass('Object'); 1086 assertSuggestImportedClass('Object');
1115 // }); 1087 });
1116 // } 1088 }
1117 1089
1118 // test_InterpolationExpression_block() { 1090 test_InterpolationExpression_block() {
1119 // // SimpleIdentifier InterpolationExpression StringInterpolation 1091 // SimpleIdentifier InterpolationExpression StringInterpolation
1120 // addTestSource('main() {String name; print("hello \${n^}");}'); 1092 addTestSource('main() {String name; print("hello \${n^}");}');
1121 // computeFast(); 1093 computeFast();
1122 // return computeFull(true).then((_) { 1094 return computeFull(true).then((_) {
1123 // assertSuggestLocalVariable('name', 'String'); 1095 assertSuggestLocalVariable('name', 'String');
1124 // assertSuggestImportedClass('Object'); 1096 assertSuggestImportedClass('Object');
1125 // }); 1097 });
1126 // } 1098 }
1127 1099
1128 test_InterpolationExpression_prefix_selector() { 1100 test_InterpolationExpression_prefix_selector() {
1129 // SimpleIdentifier PrefixedIdentifier InterpolationExpression 1101 // SimpleIdentifier PrefixedIdentifier InterpolationExpression
1130 addTestSource('main() {String name; print("hello \${name.^}");}'); 1102 addTestSource('main() {String name; print("hello \${name.^}");}');
1131 computeFast(); 1103 computeFast();
1132 return computeFull(true).then((_) { 1104 return computeFull(true).then((_) {
1133 assertSuggestInvocationGetter('length', 'int'); 1105 assertSuggestInvocationGetter('length', 'int');
1134 assertNotSuggested('name'); 1106 assertNotSuggested('name');
1135 assertNotSuggested('Object'); 1107 assertNotSuggested('Object');
1136 }); 1108 });
1137 } 1109 }
1138 1110
1139 // test_InterpolationExpression_prefix_target() { 1111 test_InterpolationExpression_prefix_target() {
1140 // // SimpleIdentifier PrefixedIdentifier InterpolationExpression 1112 // SimpleIdentifier PrefixedIdentifier InterpolationExpression
1141 // addTestSource('main() {String name; print("hello \${nam^e.length}");}'); 1113 addTestSource('main() {String name; print("hello \${nam^e.length}");}');
1142 // computeFast(); 1114 computeFast();
1143 // return computeFull(true).then((_) { 1115 return computeFull(true).then((_) {
1144 // assertSuggestLocalVariable('name', 'String'); 1116 assertSuggestLocalVariable('name', 'String');
1145 // assertSuggestImportedClass('Object'); 1117 assertSuggestImportedClass('Object');
1146 // assertNotSuggested('length'); 1118 assertNotSuggested('length');
1147 // }); 1119 });
1148 // } 1120 }
1149 1121
1150 test_IsExpression() { 1122 test_IsExpression() {
1151 // SimpleIdentifier TypeName IsExpression IfStatement 1123 // SimpleIdentifier TypeName IsExpression IfStatement
1152 addSource('/testB.dart', ''' 1124 addSource('/testB.dart', '''
1153 lib B; 1125 lib B;
1154 foo() { } 1126 foo() { }
1155 class X {X.c(); X._d(); z() {}}'''); 1127 class X {X.c(); X._d(); z() {}}''');
1156 addTestSource(''' 1128 addTestSource('''
1157 import "/testB.dart"; 1129 import "/testB.dart";
1158 class Y {Y.c(); Y._d(); z() {}} 1130 class Y {Y.c(); Y._d(); z() {}}
1159 main() {var x; if (x is ^) { }}'''); 1131 main() {var x; if (x is ^) { }}''');
1160 computeFast(); 1132 computeFast();
1161 return computeFull(true).then((_) { 1133 return computeFull(true).then((_) {
1162 assertSuggestImportedClass('X'); 1134 assertSuggestImportedClass('X');
1163 assertSuggestLocalClass('Y'); 1135 assertSuggestLocalClass('Y');
1164 assertNotSuggested('x'); 1136 assertNotSuggested('x');
1165 assertNotSuggested('main'); 1137 assertNotSuggested('main');
1166 assertNotSuggested('foo'); 1138 assertNotSuggested('foo');
1167 }); 1139 });
1168 } 1140 }
1169 1141
1142 test_IsExpression_target() {
1143 // IfStatement Block BlockFunctionBody
1144 addTestSource('''
1145 class A {int x; int y() => 0;}
1146 main(){var a; if (^ is A)}''');
1147 computeFast();
1148 return computeFull(true).then((_) {
1149 assertSuggestLocalVariable('a', null);
1150 assertSuggestLocalFunction('main', null);
1151 assertSuggestLocalClass('A');
1152 assertSuggestImportedClass('Object');
1153 });
1154 }
1155
1156 test_IsExpression_type() {
1157 // SimpleIdentifier TypeName IsExpression IfStatement
1158 addTestSource('''
1159 class A {int x; int y() => 0;}
1160 main(){var a; if (a is ^)}''');
1161 computeFast();
1162 return computeFull(true).then((_) {
1163 assertNotSuggested('a');
1164 assertNotSuggested('main');
1165 assertSuggestLocalClass('A');
1166 assertSuggestImportedClass('Object');
1167 });
1168 }
1169
1170 test_Literal_string() { 1170 test_Literal_string() {
1171 // SimpleStringLiteral ExpressionStatement Block 1171 // SimpleStringLiteral ExpressionStatement Block
1172 addTestSource('class A {a() {"hel^lo"}}'); 1172 addTestSource('class A {a() {"hel^lo"}}');
1173 computeFast(); 1173 computeFast();
1174 return computeFull(true).then((_) { 1174 return computeFull(true).then((_) {
1175 assertNoSuggestions(); 1175 assertNoSuggestions();
1176 }); 1176 });
1177 } 1177 }
1178 1178
1179 test_MethodDeclaration_body_getters() { 1179 test_MethodDeclaration_body_getters() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 computeFast(); 1366 computeFast();
1367 return computeFull(true).then((_) { 1367 return computeFull(true).then((_) {
1368 assertSuggestImportedClass('A'); 1368 assertSuggestImportedClass('A');
1369 assertSuggestLocalClass('X'); 1369 assertSuggestLocalClass('X');
1370 assertSuggestLocalMethod('foo', 'X', null); 1370 assertSuggestLocalMethod('foo', 'X', null);
1371 assertNotSuggested('bar'); 1371 assertNotSuggested('bar');
1372 assertNotSuggested('_B'); 1372 assertNotSuggested('_B');
1373 }); 1373 });
1374 } 1374 }
1375 1375
1376 test_PropertyAccess_expression() {
1377 // SimpleIdentifier MethodInvocation PropertyAccess ExpressionStatement
1378 addTestSource('class A {a() {"hello".to^String().length}}');
1379 computeFast();
1380 return computeFull(true).then((_) {
1381 assertSuggestInvocationGetter('length', 'int');
1382 assertNotSuggested('A');
1383 assertNotSuggested('a');
1384 assertNotSuggested('Object');
1385 });
1386 }
1387
1388 test_PropertyAccess_selector() {
1389 // SimpleIdentifier PropertyAccess ExpressionStatement Block
1390 addTestSource('class A {a() {"hello".length.^}}');
1391 computeFast();
1392 return computeFull(true).then((_) {
1393 assertSuggestInvocationGetter('isEven', 'bool');
1394 assertNotSuggested('A');
1395 assertNotSuggested('a');
1396 assertNotSuggested('Object');
1397 });
1398 }
1399
1376 test_TopLevelVariableDeclaration_typed_name() { 1400 test_TopLevelVariableDeclaration_typed_name() {
1377 // SimpleIdentifier VariableDeclaration VariableDeclarationList 1401 // SimpleIdentifier VariableDeclaration VariableDeclarationList
1378 // TopLevelVariableDeclaration 1402 // TopLevelVariableDeclaration
1379 addTestSource('class A {} B ^'); 1403 addTestSource('class A {} B ^');
1380 computeFast(); 1404 computeFast();
1381 return computeFull(true).then((_) { 1405 return computeFull(true).then((_) {
1382 assertNoSuggestions(); 1406 assertNoSuggestions();
1383 }); 1407 });
1384 } 1408 }
1385 1409
1386 test_TopLevelVariableDeclaration_untyped_name() { 1410 test_TopLevelVariableDeclaration_untyped_name() {
1387 // SimpleIdentifier VariableDeclaration VariableDeclarationList 1411 // SimpleIdentifier VariableDeclaration VariableDeclarationList
1388 // TopLevelVariableDeclaration 1412 // TopLevelVariableDeclaration
1389 addTestSource('class A {} var ^'); 1413 addTestSource('class A {} var ^');
1390 computeFast(); 1414 computeFast();
1391 return computeFull(true).then((_) { 1415 return computeFull(true).then((_) {
1392 assertNoSuggestions(); 1416 assertNoSuggestions();
1393 }); 1417 });
1394 } 1418 }
1395 1419
1396 test_VariableDeclarationStatement_RHS() { 1420 test_VariableDeclaration_name() {
1397 // SimpleIdentifier VariableDeclaration VariableDeclarationList 1421 // SimpleIdentifier VariableDeclaration VariableDeclarationList
1398 // VariableDeclarationStatement 1422 // VariableDeclarationStatement Block
1399 addSource('/testB.dart', ''' 1423 addSource('/testB.dart', '''
1400 lib B; 1424 lib B;
1401 foo() { } 1425 foo() { }
1402 class _B { } 1426 class _B { }
1403 class X {X.c(); X._d(); z() {}}'''); 1427 class X {X.c(); X._d(); z() {}}''');
1404 addTestSource(''' 1428 addTestSource('''
1405 import "/testB.dart"; 1429 import "/testB.dart";
1406 class Y {Y.c(); Y._d(); z() {}} 1430 class Y {Y.c(); Y._d(); z() {}}
1407 class C {bar(){var f; {var x;} var e = ^}}'''); 1431 main() {var ^}''');
1408 computeFast(); 1432 computeFast();
1409 return computeFull(true).then((_) { 1433 return computeFull(true).then((_) {
1410 assertSuggestImportedClass('X'); 1434 assertNoSuggestions();
1411 assertNotSuggested('_B');
1412 assertSuggestLocalClass('Y');
1413 assertSuggestLocalClass('C');
1414 assertSuggestLocalVariable('f', null);
1415 assertNotSuggested('x');
1416 assertNotSuggested('e');
1417 }); 1435 });
1418 } 1436 }
1419 1437
1420 test_VariableDeclarationStatement_RHS_missing_semicolon() { 1438 test_VariableDeclarationStatement_RHS() {
1421 // VariableDeclaration VariableDeclarationList 1439 // SimpleIdentifier VariableDeclaration VariableDeclarationList
1422 // VariableDeclarationStatement 1440 // VariableDeclarationStatement
1423 addSource('/testB.dart', ''' 1441 addSource('/testB.dart', '''
1424 lib B; 1442 lib B;
1425 foo() { } 1443 foo() { }
1426 class _B { } 1444 class _B { }
1427 class X {X.c(); X._d(); z() {}}'''); 1445 class X {X.c(); X._d(); z() {}}''');
1428 addTestSource(''' 1446 addTestSource('''
1429 import "/testB.dart"; 1447 import "/testB.dart";
1430 class Y {Y.c(); Y._d(); z() {}} 1448 class Y {Y.c(); Y._d(); z() {}}
1431 class C {bar(){var f; {var x;} var e = ^ var g}}'''); 1449 class C {bar(){var f; {var x;} var e = ^}}''');
1432 computeFast(); 1450 computeFast();
1433 return computeFull(true).then((_) { 1451 return computeFull(true).then((_) {
1434 assertSuggestImportedClass('X'); 1452 assertSuggestImportedClass('X');
1435 assertNotSuggested('_B'); 1453 assertNotSuggested('_B');
1436 assertSuggestLocalClass('Y'); 1454 assertSuggestLocalClass('Y');
1437 assertSuggestLocalClass('C'); 1455 assertSuggestLocalClass('C');
1438 assertSuggestLocalVariable('f', null); 1456 assertSuggestLocalVariable('f', null);
1439 assertNotSuggested('x'); 1457 assertNotSuggested('x');
1440 assertNotSuggested('e'); 1458 assertNotSuggested('e');
1441 }); 1459 });
1442 } 1460 }
1443 1461
1444 test_VariableDeclaration_name() { 1462 test_VariableDeclarationStatement_RHS_missing_semicolon() {
1445 // SimpleIdentifier VariableDeclaration VariableDeclarationList 1463 // VariableDeclaration VariableDeclarationList
1446 // VariableDeclarationStatement Block 1464 // VariableDeclarationStatement
1447 addSource('/testB.dart', ''' 1465 addSource('/testB.dart', '''
1448 lib B; 1466 lib B;
1449 foo() { } 1467 foo() { }
1450 class _B { } 1468 class _B { }
1451 class X {X.c(); X._d(); z() {}}'''); 1469 class X {X.c(); X._d(); z() {}}''');
1452 addTestSource(''' 1470 addTestSource('''
1453 import "/testB.dart"; 1471 import "/testB.dart";
1454 class Y {Y.c(); Y._d(); z() {}} 1472 class Y {Y.c(); Y._d(); z() {}}
1455 main() {var ^}'''); 1473 class C {bar(){var f; {var x;} var e = ^ var g}}''');
1456 computeFast(); 1474 computeFast();
1457 return computeFull(true).then((_) { 1475 return computeFull(true).then((_) {
1458 assertNoSuggestions(); 1476 assertSuggestImportedClass('X');
1477 assertNotSuggested('_B');
1478 assertSuggestLocalClass('Y');
1479 assertSuggestLocalClass('C');
1480 assertSuggestLocalVariable('f', null);
1481 assertNotSuggested('x');
1482 assertNotSuggested('e');
1459 }); 1483 });
1460 } 1484 }
1461
1462 // test_ConditionalExpression() {
1463 // fail('not implemented yet');
1464 // }
1465 //
1466 // test_FunctionExpression() {
1467 // fail('not implemented yet');
1468 // }
1469 //
1470 // test_FunctionExpressionInvocation() {
1471 // fail('not implemented yet');
1472 // }
1473 //
1474 // test_Identifier() {
1475 // fail('not implemented yet');
1476 // }
1477 //
1478 // test_IndexExpression() {
1479 // fail('not implemented yet');
1480 // }
1481 //
1482 // test_InstanceCreationExpression() {
1483 // fail('not implemented yet');
1484 // }
1485 //
1486 // test_Literal() {
1487 // fail('not implemented yet');
1488 // }
1489 //
1490 // test_MethodInvocation() {
1491 // fail('not implemented yet');
1492 // }
1493 //
1494 // test_NamedExpression() {
1495 // fail('not implemented yet');
1496 // }
1497 //
1498 // test_ParenthesizedExpression() {
1499 // fail('not implemented yet');
1500 // }
1501 //
1502 // test_PostfixExpression() {
1503 // fail('not implemented yet');
1504 // }
1505 //
1506 // test_PrefixedIdentifier() {
1507 // fail('not implemented yet');
1508 // }
1509 //
1510 // test_PrefixedExpression() {
1511 // fail('not implemented yet');
1512 // }
1513 //
1514 // test_PropertyAccess() {
1515 // fail('not implemented yet');
1516 // }
1517 //
1518 // test_RethrowExpression() {
1519 // fail('not implemented yet');
1520 // }
1521 //
1522 // test_SuperExpression() {
1523 // fail('not implemented yet');
1524 // }
1525 //
1526 // test_ThisExpression() {
1527 // fail('not implemented yet');
1528 // }
1529 //
1530 // test_ThrowExpression() {
1531 // fail('not implemented yet');
1532 // }
1533 } 1485 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/local_computer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698