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

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

Issue 1097973002: suggest types in var declaration when partial type name supplied (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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 9 import 'package:analysis_server/src/protocol.dart' as protocol
10 show Element, ElementKind; 10 show Element, ElementKind;
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 assertSuggestLocalGetter('clog', 'int'); 1266 assertSuggestLocalGetter('clog', 'int');
1267 assertSuggestLocalSetter('blog'); 1267 assertSuggestLocalSetter('blog');
1268 // TODO (danrubel) suggest HtmlElement as low relevance 1268 // TODO (danrubel) suggest HtmlElement as low relevance
1269 assertNotSuggested('HtmlElement'); 1269 assertNotSuggested('HtmlElement');
1270 assertSuggestImportedClass('Uri'); 1270 assertSuggestImportedClass('Uri');
1271 assertNotSuggested('parseIPv6Address'); 1271 assertNotSuggested('parseIPv6Address');
1272 assertNotSuggested('parseHex'); 1272 assertNotSuggested('parseHex');
1273 }); 1273 });
1274 } 1274 }
1275 1275
1276 test_Block_final() {
1277 // Block BlockFunctionBody MethodDeclaration
1278 addSource('/testAB.dart', '''
1279 export "dart:math" hide max;
1280 class A {int x;}
1281 @deprecated D1() {int x;}
1282 class _B {boo() { partBoo() {}} }''');
1283 addSource('/testCD.dart', '''
1284 String T1;
1285 var _T2;
1286 class C { }
1287 class D { }''');
1288 addSource('/testEEF.dart', '''
1289 class EE { }
1290 class F { }''');
1291 addSource('/testG.dart', 'class G { }');
1292 addSource('/testH.dart', '''
1293 class H { }
1294 int T3;
1295 var _T4;'''); // not imported
1296 addTestSource('''
1297 import "/testAB.dart";
1298 import "/testCD.dart" hide D;
1299 import "/testEEF.dart" show EE;
1300 import "/testG.dart" as g;
1301 int T5;
1302 var _T6;
1303 String get T7 => 'hello';
1304 set T8(int value) { partT8() {} }
1305 Z D2() {int x;}
1306 class X {
1307 int get clog => 8;
1308 set blog(value) { }
1309 a() {
1310 var f;
1311 localF(int arg1) { }
1312 {var x;}
1313 final ^
1314 }
1315 void b() { }}
1316 class Z { }''');
1317 computeFast();
1318 return computeFull((bool result) {
1319 expect(request.replacementOffset, completionOffset);
1320 expect(request.replacementLength, 0);
1321
1322 assertSuggestLocalClass('X');
1323 assertSuggestLocalClass('Z');
1324 assertNotSuggested('a');
1325 assertNotSuggested('b');
1326 assertNotSuggested('localF');
1327 assertNotSuggested('f');
1328 // Don't suggest locals out of scope
1329 assertNotSuggested('r');
1330 assertNotSuggested('x');
1331 assertNotSuggested('partT8');
1332
1333 assertSuggestImportedClass('A');
1334 assertNotSuggested('_B');
1335 assertSuggestImportedClass('C');
1336 assertNotSuggested('partBoo');
1337 // hidden element suggested as low relevance
1338 // but imported results are partially filtered
1339 //assertSuggestImportedClass('D', COMPLETION_RELEVANCE_LOW);
1340 //assertSuggestImportedFunction(
1341 // 'D1', null, true, COMPLETION_RELEVANCE_LOW);
1342 assertNotSuggested('D2');
1343 assertSuggestImportedClass('EE');
1344 // hidden element suggested as low relevance
1345 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
1346 assertSuggestLibraryPrefix('g');
1347 assertNotSuggested('G');
1348 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
1349 assertSuggestImportedClass('Object');
1350 assertNotSuggested('min');
1351 //assertSuggestImportedFunction(
1352 // 'max',
1353 // 'num',
1354 // false,
1355 // COMPLETION_RELEVANCE_LOW);
1356 assertNotSuggested('T1');
1357 assertNotSuggested('_T2');
1358 //assertSuggestImportedTopLevelVar('T3', 'int', COMPLETION_RELEVANCE_LOW);
1359 assertNotSuggested('_T4');
1360 assertNotSuggested('T5');
1361 assertNotSuggested('_T6');
1362 assertNotSuggested('==');
1363 assertNotSuggested('T7');
1364 assertNotSuggested('T8');
1365 assertNotSuggested('clog');
1366 assertNotSuggested('blog');
1367 // TODO (danrubel) suggest HtmlElement as low relevance
1368 assertNotSuggested('HtmlElement');
1369 assertSuggestImportedClass('Uri');
1370 assertNotSuggested('parseIPv6Address');
1371 assertNotSuggested('parseHex');
1372 });
1373 }
1374
1375 test_Block_final2() {
1376 addTestSource('main() {final S^ v;}');
1377 computeFast();
1378 return computeFull((bool result) {
1379 assertSuggestImportedClass('String');
1380 });
1381 }
1382
1383 test_Block_final3() {
1384 addTestSource('main() {final ^ v;}');
1385 computeFast();
1386 return computeFull((bool result) {
1387 assertSuggestImportedClass('String');
1388 });
1389 }
1390
1391 test_Block_final_final() {
1392 // Block BlockFunctionBody MethodDeclaration
1393 addSource('/testAB.dart', '''
1394 export "dart:math" hide max;
1395 class A {int x;}
1396 @deprecated D1() {int x;}
1397 class _B {boo() { partBoo() {}} }''');
1398 addSource('/testCD.dart', '''
1399 String T1;
1400 var _T2;
1401 class C { }
1402 class D { }''');
1403 addSource('/testEEF.dart', '''
1404 class EE { }
1405 class F { }''');
1406 addSource('/testG.dart', 'class G { }');
1407 addSource('/testH.dart', '''
1408 class H { }
1409 int T3;
1410 var _T4;'''); // not imported
1411 addTestSource('''
1412 import "/testAB.dart";
1413 import "/testCD.dart" hide D;
1414 import "/testEEF.dart" show EE;
1415 import "/testG.dart" as g;
1416 int T5;
1417 var _T6;
1418 String get T7 => 'hello';
1419 set T8(int value) { partT8() {} }
1420 Z D2() {int x;}
1421 class X {
1422 int get clog => 8;
1423 set blog(value) { }
1424 a() {
1425 final ^
1426 final var f;
1427 localF(int arg1) { }
1428 {var x;}
1429 }
1430 void b() { }}
1431 class Z { }''');
1432 computeFast();
1433 return computeFull((bool result) {
1434 expect(request.replacementOffset, completionOffset);
1435 expect(request.replacementLength, 0);
1436
1437 assertSuggestLocalClass('X');
1438 assertSuggestLocalClass('Z');
1439 assertNotSuggested('a');
1440 assertNotSuggested('b');
1441 assertNotSuggested('localF');
1442 assertNotSuggested('f');
1443 // Don't suggest locals out of scope
1444 assertNotSuggested('r');
1445 assertNotSuggested('x');
1446 assertNotSuggested('partT8');
1447
1448 assertSuggestImportedClass('A');
1449 assertNotSuggested('_B');
1450 assertSuggestImportedClass('C');
1451 assertNotSuggested('partBoo');
1452 // hidden element suggested as low relevance
1453 // but imported results are partially filtered
1454 //assertSuggestImportedClass('D', COMPLETION_RELEVANCE_LOW);
1455 //assertSuggestImportedFunction(
1456 // 'D1', null, true, COMPLETION_RELEVANCE_LOW);
1457 assertNotSuggested('D2');
1458 assertSuggestImportedClass('EE');
1459 // hidden element suggested as low relevance
1460 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
1461 assertSuggestLibraryPrefix('g');
1462 assertNotSuggested('G');
1463 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
1464 assertSuggestImportedClass('Object');
1465 assertNotSuggested('min');
1466 //assertSuggestImportedFunction(
1467 // 'max',
1468 // 'num',
1469 // false,
1470 // COMPLETION_RELEVANCE_LOW);
1471 assertNotSuggested('T1');
1472 assertNotSuggested('_T2');
1473 //assertSuggestImportedTopLevelVar('T3', 'int', COMPLETION_RELEVANCE_LOW);
1474 assertNotSuggested('_T4');
1475 assertNotSuggested('T5');
1476 assertNotSuggested('_T6');
1477 assertNotSuggested('==');
1478 assertNotSuggested('T7');
1479 assertNotSuggested('T8');
1480 assertNotSuggested('clog');
1481 assertNotSuggested('blog');
1482 // TODO (danrubel) suggest HtmlElement as low relevance
1483 assertNotSuggested('HtmlElement');
1484 assertSuggestImportedClass('Uri');
1485 assertNotSuggested('parseIPv6Address');
1486 assertNotSuggested('parseHex');
1487 });
1488 }
1489
1490 test_Block_final_var() {
1491 // Block BlockFunctionBody MethodDeclaration
1492 addSource('/testAB.dart', '''
1493 export "dart:math" hide max;
1494 class A {int x;}
1495 @deprecated D1() {int x;}
1496 class _B {boo() { partBoo() {}} }''');
1497 addSource('/testCD.dart', '''
1498 String T1;
1499 var _T2;
1500 class C { }
1501 class D { }''');
1502 addSource('/testEEF.dart', '''
1503 class EE { }
1504 class F { }''');
1505 addSource('/testG.dart', 'class G { }');
1506 addSource('/testH.dart', '''
1507 class H { }
1508 int T3;
1509 var _T4;'''); // not imported
1510 addTestSource('''
1511 import "/testAB.dart";
1512 import "/testCD.dart" hide D;
1513 import "/testEEF.dart" show EE;
1514 import "/testG.dart" as g;
1515 int T5;
1516 var _T6;
1517 String get T7 => 'hello';
1518 set T8(int value) { partT8() {} }
1519 Z D2() {int x;}
1520 class X {
1521 int get clog => 8;
1522 set blog(value) { }
1523 a() {
1524 final ^
1525 var f;
1526 localF(int arg1) { }
1527 {var x;}
1528 }
1529 void b() { }}
1530 class Z { }''');
1531 computeFast();
1532 return computeFull((bool result) {
1533 expect(request.replacementOffset, completionOffset);
1534 expect(request.replacementLength, 0);
1535
1536 assertSuggestLocalClass('X');
1537 assertSuggestLocalClass('Z');
1538 assertNotSuggested('a');
1539 assertNotSuggested('b');
1540 assertNotSuggested('localF');
1541 assertNotSuggested('f');
1542 // Don't suggest locals out of scope
1543 assertNotSuggested('r');
1544 assertNotSuggested('x');
1545 assertNotSuggested('partT8');
1546
1547 assertSuggestImportedClass('A');
1548 assertNotSuggested('_B');
1549 assertSuggestImportedClass('C');
1550 assertNotSuggested('partBoo');
1551 // hidden element suggested as low relevance
1552 // but imported results are partially filtered
1553 //assertSuggestImportedClass('D', COMPLETION_RELEVANCE_LOW);
1554 //assertSuggestImportedFunction(
1555 // 'D1', null, true, COMPLETION_RELEVANCE_LOW);
1556 assertNotSuggested('D2');
1557 assertSuggestImportedClass('EE');
1558 // hidden element suggested as low relevance
1559 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
1560 assertSuggestLibraryPrefix('g');
1561 assertNotSuggested('G');
1562 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
1563 assertSuggestImportedClass('Object');
1564 assertNotSuggested('min');
1565 //assertSuggestImportedFunction(
1566 // 'max',
1567 // 'num',
1568 // false,
1569 // COMPLETION_RELEVANCE_LOW);
1570 assertNotSuggested('T1');
1571 assertNotSuggested('_T2');
1572 //assertSuggestImportedTopLevelVar('T3', 'int', COMPLETION_RELEVANCE_LOW);
1573 assertNotSuggested('_T4');
1574 assertNotSuggested('T5');
1575 assertNotSuggested('_T6');
1576 assertNotSuggested('==');
1577 assertNotSuggested('T7');
1578 assertNotSuggested('T8');
1579 assertNotSuggested('clog');
1580 assertNotSuggested('blog');
1581 // TODO (danrubel) suggest HtmlElement as low relevance
1582 assertNotSuggested('HtmlElement');
1583 assertSuggestImportedClass('Uri');
1584 assertNotSuggested('parseIPv6Address');
1585 assertNotSuggested('parseHex');
1586 });
1587 }
1588
1276 test_Block_identifier_partial() { 1589 test_Block_identifier_partial() {
1277 addSource('/testAB.dart', ''' 1590 addSource('/testAB.dart', '''
1278 export "dart:math" hide max; 1591 export "dart:math" hide max;
1279 class A {int x;} 1592 class A {int x;}
1280 @deprecated D1() {int x;} 1593 @deprecated D1() {int x;}
1281 class _B { }'''); 1594 class _B { }''');
1282 addSource('/testCD.dart', ''' 1595 addSource('/testCD.dart', '''
1283 String T1; 1596 String T1;
1284 var _T2; 1597 var _T2;
1285 class C { } 1598 class C { }
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 CompletionSuggestion suggestionO = assertSuggestImportedClass('Object'); 1965 CompletionSuggestion suggestionO = assertSuggestImportedClass('Object');
1653 if (suggestionO != null) { 1966 if (suggestionO != null) {
1654 expect(suggestionO.element.isDeprecated, isFalse); 1967 expect(suggestionO.element.isDeprecated, isFalse);
1655 expect(suggestionO.element.isPrivate, isFalse); 1968 expect(suggestionO.element.isPrivate, isFalse);
1656 } 1969 }
1657 assertNotSuggested('T'); 1970 assertNotSuggested('T');
1658 assertSuggestLibraryPrefix('x'); 1971 assertSuggestLibraryPrefix('x');
1659 }); 1972 });
1660 } 1973 }
1661 1974
1975 test_ClassDeclaration_body_final() {
1976 // ClassDeclaration CompilationUnit
1977 addSource('/testB.dart', '''
1978 class B { }''');
1979 addTestSource('''
1980 import "testB.dart" as x;
1981 class A {final ^}
1982 class _B {}
1983 A T;''');
1984 computeFast();
1985 return computeFull((bool result) {
1986 expect(request.replacementOffset, completionOffset);
1987 expect(request.replacementLength, 0);
1988 assertSuggestLocalClass('A');
1989 assertSuggestLocalClass('_B');
1990 assertSuggestImportedClass('Object');
1991 assertNotSuggested('T');
1992 assertSuggestLibraryPrefix('x');
1993 });
1994 }
1995
1996 test_ClassDeclaration_body_final_final() {
1997 // ClassDeclaration CompilationUnit
1998 addSource('/testB.dart', '''
1999 class B { }''');
2000 addTestSource('''
2001 import "testB.dart" as x;
2002 class A {final ^ final foo;}
2003 class _B {}
2004 A T;''');
2005 computeFast();
2006 return computeFull((bool result) {
2007 expect(request.replacementOffset, completionOffset);
2008 expect(request.replacementLength, 0);
2009 assertSuggestLocalClass('A');
2010 assertSuggestLocalClass('_B');
2011 assertSuggestImportedClass('Object');
2012 assertNotSuggested('T');
2013 assertSuggestLibraryPrefix('x');
2014 });
2015 }
2016
2017 test_ClassDeclaration_body_final_var() {
2018 // ClassDeclaration CompilationUnit
2019 addSource('/testB.dart', '''
2020 class B { }''');
2021 addTestSource('''
2022 import "testB.dart" as x;
2023 class A {final ^ var foo;}
2024 class _B {}
2025 A T;''');
2026 computeFast();
2027 return computeFull((bool result) {
2028 expect(request.replacementOffset, completionOffset);
2029 expect(request.replacementLength, 0);
2030 assertSuggestLocalClass('A');
2031 assertSuggestLocalClass('_B');
2032 assertSuggestImportedClass('Object');
2033 assertNotSuggested('T');
2034 assertSuggestLibraryPrefix('x');
2035 });
2036 }
2037
1662 test_Combinator_hide() { 2038 test_Combinator_hide() {
1663 // SimpleIdentifier HideCombinator ImportDirective 2039 // SimpleIdentifier HideCombinator ImportDirective
1664 addSource('/testAB.dart', ''' 2040 addSource('/testAB.dart', '''
1665 library libAB; 2041 library libAB;
1666 part '/partAB.dart'; 2042 part '/partAB.dart';
1667 class A { } 2043 class A { }
1668 class B { }'''); 2044 class B { }''');
1669 addSource('/partAB.dart', ''' 2045 addSource('/partAB.dart', '''
1670 part of libAB; 2046 part of libAB;
1671 var T1; 2047 var T1;
(...skipping 2273 matching lines...) Expand 10 before | Expand all | Expand 10 after
3945 assertNotSuggested('bar2'); 4321 assertNotSuggested('bar2');
3946 assertNotSuggested('_B'); 4322 assertNotSuggested('_B');
3947 assertSuggestLocalClass('Y'); 4323 assertSuggestLocalClass('Y');
3948 assertSuggestLocalClass('C'); 4324 assertSuggestLocalClass('C');
3949 assertSuggestLocalVariable('f', null); 4325 assertSuggestLocalVariable('f', null);
3950 assertNotSuggested('x'); 4326 assertNotSuggested('x');
3951 assertNotSuggested('e'); 4327 assertNotSuggested('e');
3952 }); 4328 });
3953 } 4329 }
3954 } 4330 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/completion_test.dart ('k') | pkg/analysis_server/test/services/completion/optype_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698