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

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

Issue 838053003: suggest fields rather than synthetic getters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 5 years, 11 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 assertSuggest(name, csKind: kind, relevance: relevance); 183 assertSuggest(name, csKind: kind, relevance: relevance);
184 protocol.Element element = cs.element; 184 protocol.Element element = cs.element;
185 expect(element, isNotNull); 185 expect(element, isNotNull);
186 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); 186 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS));
187 expect(element.name, equals(name)); 187 expect(element.name, equals(name));
188 expect(element.parameters, isNull); 188 expect(element.parameters, isNull);
189 expect(element.returnType, isNull); 189 expect(element.returnType, isNull);
190 return cs; 190 return cs;
191 } 191 }
192 192
193 CompletionSuggestion assertSuggestField(String name,
194 {CompletionRelevance relevance: CompletionRelevance.DEFAULT,
195 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
196 bool isDeprecated: false}) {
197 CompletionSuggestion cs = assertSuggest(
198 name,
199 csKind: kind,
200 relevance: relevance,
201 elemKind: protocol.ElementKind.FIELD,
202 isDeprecated: isDeprecated);
203 expect(cs.returnType, isNull);
204 protocol.Element element = cs.element;
205 expect(element, isNotNull);
206 expect(element.kind, equals(protocol.ElementKind.FIELD));
207 expect(element.name, equals(name));
208 expect(element.parameters, isNull);
209 // TODO (danrubel) return type should be null and there should be
210 // something that represents the type of the field
211 if (element.returnType != null) {
212 expect(element.returnType, 'dynamic');
213 }
214 return cs;
215 }
216
193 CompletionSuggestion assertSuggestFunction(String name, String returnType, 217 CompletionSuggestion assertSuggestFunction(String name, String returnType,
194 bool isDeprecated, [CompletionRelevance relevance = CompletionRelevance.DE FAULT, 218 bool isDeprecated, [CompletionRelevance relevance = CompletionRelevance.DE FAULT,
195 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { 219 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
196 CompletionSuggestion cs = assertSuggest( 220 CompletionSuggestion cs = assertSuggest(
197 name, 221 name,
198 csKind: kind, 222 csKind: kind,
199 relevance: relevance, 223 relevance: relevance,
200 isDeprecated: isDeprecated); 224 isDeprecated: isDeprecated);
201 expect(cs.returnType, equals(returnType)); 225 expect(cs.returnType, equals(returnType));
202 protocol.Element element = cs.element; 226 protocol.Element element = cs.element;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 CompletionSuggestion assertSuggestImportedClass(String name, 603 CompletionSuggestion assertSuggestImportedClass(String name,
580 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, 604 [CompletionRelevance relevance = CompletionRelevance.DEFAULT,
581 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { 605 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
582 if (computer is ImportedComputer) { 606 if (computer is ImportedComputer) {
583 return assertSuggestClass(name, relevance, kind); 607 return assertSuggestClass(name, relevance, kind);
584 } else { 608 } else {
585 return assertNotSuggested(name); 609 return assertNotSuggested(name);
586 } 610 }
587 } 611 }
588 612
613 CompletionSuggestion assertSuggestImportedField(String name,
614 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
615 if (computer is ImportedComputer) {
616 return assertSuggestField(name, relevance: relevance);
617 } else {
618 return assertNotSuggested(name);
619 }
620 }
621
589 CompletionSuggestion assertSuggestImportedFunction(String name, 622 CompletionSuggestion assertSuggestImportedFunction(String name,
590 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce = 623 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce =
591 CompletionRelevance.DEFAULT, CompletionSuggestionKind kind = 624 CompletionRelevance.DEFAULT, CompletionSuggestionKind kind =
592 CompletionSuggestionKind.INVOCATION]) { 625 CompletionSuggestionKind.INVOCATION]) {
593 if (computer is ImportedComputer) { 626 if (computer is ImportedComputer) {
594 return assertSuggestFunction( 627 return assertSuggestFunction(
595 name, 628 name,
596 returnType, 629 returnType,
597 isDeprecated, 630 isDeprecated,
598 relevance, 631 relevance,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 CompletionSuggestion assertSuggestImportedMethod(String name, 664 CompletionSuggestion assertSuggestImportedMethod(String name,
632 String declaringType, String returnType, [CompletionRelevance relevance = 665 String declaringType, String returnType, [CompletionRelevance relevance =
633 CompletionRelevance.DEFAULT]) { 666 CompletionRelevance.DEFAULT]) {
634 if (computer is ImportedComputer) { 667 if (computer is ImportedComputer) {
635 return assertSuggestMethod(name, declaringType, returnType, relevance); 668 return assertSuggestMethod(name, declaringType, returnType, relevance);
636 } else { 669 } else {
637 return assertNotSuggested(name); 670 return assertNotSuggested(name);
638 } 671 }
639 } 672 }
640 673
674 CompletionSuggestion assertSuggestImportedSetter(String name,
675 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
676 if (computer is ImportedComputer) {
677 return assertSuggestSetter(name, relevance);
678 } else {
679 return assertNotSuggested(name);
680 }
681 }
682
641 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, 683 CompletionSuggestion assertSuggestImportedTopLevelVar(String name,
642 String returnType, [CompletionRelevance relevance = CompletionRelevance.DE FAULT, 684 String returnType, [CompletionRelevance relevance = CompletionRelevance.DE FAULT,
643 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { 685 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
644 if (computer is ImportedComputer) { 686 if (computer is ImportedComputer) {
645 return assertSuggestTopLevelVar(name, returnType, relevance, kind); 687 return assertSuggestTopLevelVar(name, returnType, relevance, kind);
646 } else { 688 } else {
647 return assertNotSuggested(name); 689 return assertNotSuggested(name);
648 } 690 }
649 } 691 }
650 692
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 753
712 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, 754 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name,
713 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { 755 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
714 if (computer is LocalComputer) { 756 if (computer is LocalComputer) {
715 return assertSuggestClassTypeAlias(name, relevance); 757 return assertSuggestClassTypeAlias(name, relevance);
716 } else { 758 } else {
717 return assertNotSuggested(name); 759 return assertNotSuggested(name);
718 } 760 }
719 } 761 }
720 762
763 CompletionSuggestion assertSuggestLocalField(String name,
764 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
765 if (computer is LocalComputer) {
766 return assertSuggestField(name, relevance: relevance);
767 } else {
768 return assertNotSuggested(name);
769 }
770 }
771
721 CompletionSuggestion assertSuggestLocalFunction(String name, 772 CompletionSuggestion assertSuggestLocalFunction(String name,
722 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce = 773 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce =
723 CompletionRelevance.DEFAULT]) { 774 CompletionRelevance.DEFAULT]) {
724 if (computer is LocalComputer) { 775 if (computer is LocalComputer) {
725 return assertSuggestFunction(name, returnType, isDeprecated, relevance); 776 return assertSuggestFunction(name, returnType, isDeprecated, relevance);
726 } else { 777 } else {
727 return assertNotSuggested(name); 778 return assertNotSuggested(name);
728 } 779 }
729 } 780 }
730 781
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 assertNotSuggested('=='); 1289 assertNotSuggested('==');
1239 // TODO (danrubel) suggest HtmlElement as low relevance 1290 // TODO (danrubel) suggest HtmlElement as low relevance
1240 assertNotSuggested('HtmlElement'); 1291 assertNotSuggested('HtmlElement');
1241 }); 1292 });
1242 } 1293 }
1243 1294
1244 test_Block_inherited_imported() { 1295 test_Block_inherited_imported() {
1245 // Block BlockFunctionBody MethodDeclaration ClassDeclaration 1296 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
1246 addSource('/testB.dart', ''' 1297 addSource('/testB.dart', '''
1247 lib B; 1298 lib B;
1248 class F { var f1; f2() { } } 1299 class F { var f1; f2() { } get f3 => 0; set f4(fx) { } }
1249 class E extends F { var e1; e2() { } } 1300 class E extends F { var e1; e2() { } }
1250 class I { int i1; i2() { } } 1301 class I { int i1; i2() { } get e1; }
1251 class M { var m1; int m2() { } }'''); 1302 class M { var m1; int m2() { } }''');
1252 addTestSource(''' 1303 addTestSource('''
1253 import "/testB.dart"; 1304 import "/testB.dart";
1254 class A extends E implements I with M {a() {^}}'''); 1305 class A extends E implements I with M {a() {^}}''');
1255 computeFast(); 1306 computeFast();
1256 return computeFull((bool result) { 1307 return computeFull((bool result) {
1257 assertSuggestImportedGetter('e1', null); 1308 assertSuggestImportedField('e1');
1258 assertSuggestImportedGetter('f1', null); 1309 assertSuggestImportedField('f1');
1259 assertSuggestImportedGetter('i1', 'int'); 1310 assertSuggestImportedField('i1');
1260 assertSuggestImportedGetter('m1', null); 1311 assertSuggestImportedField('m1');
1312 assertSuggestImportedGetter('f3', null);
1313 assertSuggestImportedSetter('f4');
1261 //TODO (danrubel) include declared type in suggestion 1314 //TODO (danrubel) include declared type in suggestion
1262 assertSuggestImportedMethod('e2', null, null); 1315 assertSuggestImportedMethod('e2', null, null);
1263 assertSuggestImportedMethod('f2', null, null); 1316 assertSuggestImportedMethod('f2', null, null);
1264 assertSuggestImportedMethod('i2', null, null); 1317 assertSuggestImportedMethod('i2', null, null);
1265 //assertSuggestImportedMethod('m2', null, null); 1318 //assertSuggestImportedMethod('m2', null, null);
1266 assertNotSuggested('=='); 1319 assertNotSuggested('==');
1267 }); 1320 });
1268 } 1321 }
1269 1322
1270 test_Block_inherited_local() { 1323 test_Block_inherited_local() {
1271 // Block BlockFunctionBody MethodDeclaration ClassDeclaration 1324 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
1272 addTestSource(''' 1325 addTestSource('''
1273 class F { var f1; f2() { } } 1326 class F { var f1; f2() { } get f3 => 0; set f4(fx) { } }
1274 class E extends F { var e1; e2() { } } 1327 class E extends F { var e1; e2() { } }
1275 class I { int i1; i2() { } } 1328 class I { int i1; i2() { } }
1276 class M { var m1; int m2() { } } 1329 class M { var m1; int m2() { } }
1277 class A extends E implements I with M {a() {^}}'''); 1330 class A extends E implements I with M {a() {^}}''');
1278 computeFast(); 1331 computeFast();
1279 return computeFull((bool result) { 1332 return computeFull((bool result) {
1280 assertSuggestLocalGetter('e1', null); 1333 assertSuggestLocalField('e1');
1281 assertSuggestLocalGetter('f1', null); 1334 assertSuggestLocalField('f1');
1282 assertSuggestLocalGetter('i1', 'int'); 1335 assertSuggestLocalField('i1');
1283 assertSuggestLocalGetter('m1', null); 1336 assertSuggestLocalField('m1');
1337 assertSuggestLocalGetter('f3', null);
1338 assertSuggestLocalSetter('f4');
1284 assertSuggestLocalMethod('e2', 'E', null); 1339 assertSuggestLocalMethod('e2', 'E', null);
1285 assertSuggestLocalMethod('f2', 'F', null); 1340 assertSuggestLocalMethod('f2', 'F', null);
1286 assertSuggestLocalMethod('i2', 'I', null); 1341 assertSuggestLocalMethod('i2', 'I', null);
1287 assertSuggestLocalMethod('m2', 'M', 'int'); 1342 assertSuggestLocalMethod('m2', 'M', 'int');
1288 }); 1343 });
1289 } 1344 }
1290 1345
1291 test_CascadeExpression_selector1() { 1346 test_CascadeExpression_selector1() {
1292 // PropertyAccess CascadeExpression ExpressionStatement Block 1347 // PropertyAccess CascadeExpression ExpressionStatement Block
1293 addSource('/testB.dart', ''' 1348 addSource('/testB.dart', '''
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 assertNoSuggestions(); 1538 assertNoSuggestions();
1484 }); 1539 });
1485 } 1540 }
1486 1541
1487 test_ConditionalExpression_empty() { 1542 test_ConditionalExpression_empty() {
1488 // SimpleIdentifier PrefixIdentifier IfStatement 1543 // SimpleIdentifier PrefixIdentifier IfStatement
1489 addTestSource(''' 1544 addTestSource('''
1490 class A {var b; X _c; foo() {A a; if (^) something}}'''); 1545 class A {var b; X _c; foo() {A a; if (^) something}}''');
1491 computeFast(); 1546 computeFast();
1492 return computeFull((bool result) { 1547 return computeFull((bool result) {
1493 assertSuggestLocalGetter('b', null); 1548 assertSuggestLocalField('b');
1494 assertSuggestLocalGetter('_c', 'X'); 1549 assertSuggestLocalField('_c');
1495 assertSuggestImportedClass('Object'); 1550 assertSuggestImportedClass('Object');
1496 assertSuggestLocalClass('A'); 1551 assertSuggestLocalClass('A');
1497 assertNotSuggested('=='); 1552 assertNotSuggested('==');
1498 }); 1553 });
1499 } 1554 }
1500 1555
1501 test_ConditionalExpression_invocation() { 1556 test_ConditionalExpression_invocation() {
1502 // SimpleIdentifier PrefixIdentifier IfStatement 1557 // SimpleIdentifier PrefixIdentifier IfStatement
1503 addTestSource(''' 1558 addTestSource('''
1504 main() {var a; if (a.^) something}'''); 1559 main() {var a; if (a.^) something}''');
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 // Block BlockFunctionBody MethodDeclaration 2041 // Block BlockFunctionBody MethodDeclaration
1987 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); 2042 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}');
1988 computeFast(); 2043 computeFast();
1989 return computeFull((bool result) { 2044 return computeFull((bool result) {
1990 CompletionSuggestion methodA = assertSuggestLocalMethod('_a', 'A', 'Z'); 2045 CompletionSuggestion methodA = assertSuggestLocalMethod('_a', 'A', 'Z');
1991 if (methodA != null) { 2046 if (methodA != null) {
1992 expect(methodA.element.isDeprecated, isFalse); 2047 expect(methodA.element.isDeprecated, isFalse);
1993 expect(methodA.element.isPrivate, isTrue); 2048 expect(methodA.element.isPrivate, isTrue);
1994 } 2049 }
1995 CompletionSuggestion getterF = 2050 CompletionSuggestion getterF =
1996 assertSuggestLocalGetter('f', 'X', CompletionRelevance.LOW); 2051 assertSuggestLocalField('f', CompletionRelevance.LOW);
1997 if (getterF != null) { 2052 if (getterF != null) {
1998 expect(getterF.element.isDeprecated, isTrue); 2053 expect(getterF.element.isDeprecated, isTrue);
1999 expect(getterF.element.isPrivate, isFalse); 2054 expect(getterF.element.isPrivate, isFalse);
2000 expect(getterF.element.parameters, isNull); 2055 expect(getterF.element.parameters, isNull);
2001 } 2056 }
2002 CompletionSuggestion getterG = assertSuggestLocalGetter('_g', null); 2057 CompletionSuggestion getterG = assertSuggestLocalField('_g');
2003 if (getterG != null) { 2058 if (getterG != null) {
2004 expect(getterG.element.isDeprecated, isFalse); 2059 expect(getterG.element.isDeprecated, isFalse);
2005 expect(getterG.element.isPrivate, isTrue); 2060 expect(getterG.element.isPrivate, isTrue);
2006 expect(getterF.element.parameters, isNull); 2061 expect(getterF.element.parameters, isNull);
2007 } 2062 }
2008 assertSuggestImportedClass('bool'); 2063 assertSuggestImportedClass('bool');
2009 }); 2064 });
2010 } 2065 }
2011 2066
2012 test_MethodDeclaration_parameters_named() { 2067 test_MethodDeclaration_parameters_named() {
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 assertNotSuggested('bar2'); 2571 assertNotSuggested('bar2');
2517 assertNotSuggested('_B'); 2572 assertNotSuggested('_B');
2518 assertSuggestLocalClass('Y'); 2573 assertSuggestLocalClass('Y');
2519 assertSuggestLocalClass('C'); 2574 assertSuggestLocalClass('C');
2520 assertSuggestLocalVariable('f', null); 2575 assertSuggestLocalVariable('f', null);
2521 assertNotSuggested('x'); 2576 assertNotSuggested('x');
2522 assertNotSuggested('e'); 2577 assertNotSuggested('e');
2523 }); 2578 });
2524 } 2579 }
2525 } 2580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698