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

Side by Side Diff: pkg/analysis_server/test/services/correction/assist_test.dart

Issue 2144763002: Issue 26249. Quick Assist to convert getters into final fields. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Don't suggest when there is the corresponding setter in the class. Created 4 years, 5 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.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.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 DartAssistKind.CONVERT_TO_FIELD_PARAMETER, 1425 DartAssistKind.CONVERT_TO_FIELD_PARAMETER,
1426 ''' 1426 '''
1427 class A { 1427 class A {
1428 double aaa2; 1428 double aaa2;
1429 int bbb2; 1429 int bbb2;
1430 A(int aaa, this.bbb2) : aaa2 = aaa; 1430 A(int aaa, this.bbb2) : aaa2 = aaa;
1431 } 1431 }
1432 '''); 1432 ''');
1433 } 1433 }
1434 1434
1435 test_convertToFinalField_BAD_hasSetter_inThisClass() async {
1436 resolveTestUnit('''
1437 class A {
1438 int get foo => null;
1439 void set foo(_) {}
1440 }
1441 ''');
1442 await assertNoAssistAt('get foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
1443 }
1444
1445 test_convertToFinalField_BAD_notExpressionBody() async {
1446 resolveTestUnit('''
1447 class A {
1448 int get foo {
1449 int v = 1 + 2;
1450 return v + 3;
1451 }
1452 }
1453 ''');
1454 await assertNoAssistAt('get foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
1455 }
1456
1457 test_convertToFinalField_BAD_notGetter() async {
1458 resolveTestUnit('''
1459 class A {
1460 int foo() => 42;
1461 }
1462 ''');
1463 await assertNoAssistAt('foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
1464 }
1465
1466 test_convertToFinalField_OK_blockBody_onlyReturnStatement() async {
1467 resolveTestUnit('''
1468 class A {
1469 int get foo {
1470 return 1 + 2;
1471 }
1472 }
1473 ''');
1474 await assertHasAssistAt(
1475 'get foo',
1476 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1477 '''
1478 class A {
1479 final int foo = 1 + 2;
1480 }
1481 ''');
1482 }
1483
1484 test_convertToFinalField_OK_hasOverride() async {
1485 resolveTestUnit('''
1486 const myAnnotation = const Object();
1487 class A {
1488 @myAnnotation
1489 int get foo => 42;
1490 }
1491 ''');
1492 await assertHasAssistAt(
1493 'get foo',
1494 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1495 '''
1496 const myAnnotation = const Object();
1497 class A {
1498 @myAnnotation
1499 final int foo = 42;
1500 }
1501 ''');
1502 }
1503
1504 test_convertToFinalField_OK_hasSetter_inSuper() async {
1505 resolveTestUnit('''
1506 class A {
1507 void set foo(_) {}
1508 }
1509 class B extends A {
1510 int get foo => null;
1511 }
1512 ''');
1513 await assertHasAssistAt(
1514 'get foo',
1515 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1516 '''
1517 class A {
1518 void set foo(_) {}
1519 }
1520 class B extends A {
1521 final int foo;
1522 }
1523 ''');
1524 }
1525
1526 test_convertToFinalField_OK_notNull() async {
1527 resolveTestUnit('''
1528 class A {
1529 int get foo => 1 + 2;
1530 }
1531 ''');
1532 await assertHasAssistAt(
1533 'get foo',
1534 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1535 '''
1536 class A {
1537 final int foo = 1 + 2;
1538 }
1539 ''');
1540 }
1541
1542 test_convertToFinalField_OK_null() async {
1543 resolveTestUnit('''
1544 class A {
1545 int get foo => null;
1546 }
1547 ''');
1548 await assertHasAssistAt(
1549 'get foo',
1550 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1551 '''
1552 class A {
1553 final int foo;
1554 }
1555 ''');
1556 }
1557
1558 test_convertToFinalField_OK_onName() async {
1559 resolveTestUnit('''
1560 class A {
1561 int get foo => 42;
1562 }
1563 ''');
1564 await assertHasAssistAt(
1565 'foo',
1566 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1567 '''
1568 class A {
1569 final int foo = 42;
1570 }
1571 ''');
1572 }
1573
1574 test_convertToFinalField_OK_onReturnType_parameterized() async {
1575 resolveTestUnit('''
1576 class A {
1577 List<int> get foo => null;
1578 }
1579 ''');
1580 await assertHasAssistAt(
1581 'nt> get',
1582 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1583 '''
1584 class A {
1585 final List<int> foo;
1586 }
1587 ''');
1588 }
1589
1590 test_convertToFinalField_OK_onReturnType_simple() async {
1591 resolveTestUnit('''
1592 class A {
1593 int get foo => 42;
1594 }
1595 ''');
1596 await assertHasAssistAt(
1597 'int get',
1598 DartAssistKind.CONVERT_INTO_FINAL_FIELD,
1599 '''
1600 class A {
1601 final int foo = 42;
1602 }
1603 ''');
1604 }
1605
1435 test_convertToForIndex_BAD_bodyNotBlock() async { 1606 test_convertToForIndex_BAD_bodyNotBlock() async {
1436 resolveTestUnit(''' 1607 resolveTestUnit('''
1437 main(List<String> items) { 1608 main(List<String> items) {
1438 for (String item in items) print(item); 1609 for (String item in items) print(item);
1439 } 1610 }
1440 '''); 1611 ''');
1441 await assertNoAssistAt( 1612 await assertNoAssistAt(
1442 'for (String', DartAssistKind.CONVERT_INTO_FOR_INDEX); 1613 'for (String', DartAssistKind.CONVERT_INTO_FOR_INDEX);
1443 } 1614 }
1444 1615
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 positions.add(new Position(testFile, offset)); 4120 positions.add(new Position(testFile, offset));
3950 } 4121 }
3951 return positions; 4122 return positions;
3952 } 4123 }
3953 4124
3954 void _setStartEndSelection() { 4125 void _setStartEndSelection() {
3955 offset = findOffset('// start\n') + '// start\n'.length; 4126 offset = findOffset('// start\n') + '// start\n'.length;
3956 length = findOffset('// end') - offset; 4127 length = findOffset('// end') - offset;
3957 } 4128 }
3958 } 4129 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698