|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Sebastian Davids <sdavids@gmx.de> - testInvertEquals1-23 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.ui.tests.quickfix; |
12 |
package org.eclipse.jdt.ui.tests.quickfix; |
| 12 |
|
13 |
|
|
Lines 1333-1336
Link Here
|
| 1333 |
assertEqualString(preview, buf.toString()); |
1334 |
assertEqualString(preview, buf.toString()); |
| 1334 |
} |
1335 |
} |
| 1335 |
|
1336 |
|
|
|
1337 |
public void testInvertEquals() throws Exception { |
| 1338 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1339 |
StringBuffer buf= new StringBuffer(); |
| 1340 |
buf.append("package test1;\n"); |
| 1341 |
buf.append("public class E {\n"); |
| 1342 |
buf.append(" public void foo() {\n"); |
| 1343 |
buf.append(" \"a\".equals(\"b\");\n"); |
| 1344 |
buf.append(" }\n"); |
| 1345 |
buf.append("}\n"); |
| 1346 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1347 |
|
| 1348 |
String str= "equals"; |
| 1349 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1350 |
List proposals= collectAssists(context, false); |
| 1351 |
|
| 1352 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1353 |
assertCorrectLabels(proposals); |
| 1354 |
|
| 1355 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1356 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1357 |
|
| 1358 |
buf= new StringBuffer(); |
| 1359 |
buf.append("package test1;\n"); |
| 1360 |
buf.append("public class E {\n"); |
| 1361 |
buf.append(" public void foo() {\n"); |
| 1362 |
buf.append(" \"b\".equals(\"a\");\n"); |
| 1363 |
buf.append(" }\n"); |
| 1364 |
buf.append("}\n"); |
| 1365 |
assertEqualString(preview, buf.toString()); |
| 1366 |
|
| 1367 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1368 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1369 |
proposals= collectAssists(context, false); |
| 1370 |
|
| 1371 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1372 |
assertCorrectLabels(proposals); |
| 1373 |
|
| 1374 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1375 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1376 |
|
| 1377 |
buf= new StringBuffer(); |
| 1378 |
buf.append("package test1;\n"); |
| 1379 |
buf.append("public class E {\n"); |
| 1380 |
buf.append(" public void foo() {\n"); |
| 1381 |
buf.append(" \"a\".equals(\"b\");\n"); |
| 1382 |
buf.append(" }\n"); |
| 1383 |
buf.append("}\n"); |
| 1384 |
assertEqualString(preview, buf.toString()); |
| 1385 |
} |
| 1386 |
|
| 1387 |
public void testInvertEquals2() throws Exception { |
| 1388 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1389 |
StringBuffer buf= new StringBuffer(); |
| 1390 |
buf.append("package test1;\n"); |
| 1391 |
buf.append("public class E {\n"); |
| 1392 |
buf.append(" public void foo() {\n"); |
| 1393 |
buf.append(" String s= \"a\";\n"); |
| 1394 |
buf.append(" s.equals(\"a\");\n"); |
| 1395 |
buf.append(" }\n"); |
| 1396 |
buf.append("}\n"); |
| 1397 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1398 |
|
| 1399 |
String str= "equals"; |
| 1400 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1401 |
List proposals= collectAssists(context, false); |
| 1402 |
|
| 1403 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1404 |
assertCorrectLabels(proposals); |
| 1405 |
|
| 1406 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1407 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1408 |
|
| 1409 |
buf= new StringBuffer(); |
| 1410 |
buf.append("package test1;\n"); |
| 1411 |
buf.append("public class E {\n"); |
| 1412 |
buf.append(" public void foo() {\n"); |
| 1413 |
buf.append(" String s= \"a\";\n"); |
| 1414 |
buf.append(" \"a\".equals(s);\n"); |
| 1415 |
buf.append(" }\n"); |
| 1416 |
buf.append("}\n"); |
| 1417 |
assertEqualString(preview, buf.toString()); |
| 1418 |
|
| 1419 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1420 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1421 |
proposals= collectAssists(context, false); |
| 1422 |
|
| 1423 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1424 |
assertCorrectLabels(proposals); |
| 1425 |
|
| 1426 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1427 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1428 |
|
| 1429 |
buf= new StringBuffer(); |
| 1430 |
buf.append("package test1;\n"); |
| 1431 |
buf.append("public class E {\n"); |
| 1432 |
buf.append(" public void foo() {\n"); |
| 1433 |
buf.append(" String s= \"a\";\n"); |
| 1434 |
buf.append(" s.equals(\"a\");\n"); |
| 1435 |
buf.append(" }\n"); |
| 1436 |
buf.append("}\n"); |
| 1437 |
assertEqualString(preview, buf.toString()); |
| 1438 |
} |
| 1439 |
|
| 1440 |
public void testInvertEquals3() throws Exception { |
| 1441 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1442 |
StringBuffer buf= new StringBuffer(); |
| 1443 |
buf.append("package test1;\n"); |
| 1444 |
buf.append("public class E {\n"); |
| 1445 |
buf.append(" private String a= \"a\";\n"); |
| 1446 |
buf.append(" private String b= \"b\";\n"); |
| 1447 |
buf.append(" public void foo() {\n"); |
| 1448 |
buf.append(" a.equals(b);\n"); |
| 1449 |
buf.append(" }\n"); |
| 1450 |
buf.append("}\n"); |
| 1451 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1452 |
|
| 1453 |
String str= "equals"; |
| 1454 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1455 |
List proposals= collectAssists(context, false); |
| 1456 |
|
| 1457 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1458 |
assertCorrectLabels(proposals); |
| 1459 |
|
| 1460 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1461 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1462 |
|
| 1463 |
buf= new StringBuffer(); |
| 1464 |
buf.append("package test1;\n"); |
| 1465 |
buf.append("public class E {\n"); |
| 1466 |
buf.append(" private String a= \"a\";\n"); |
| 1467 |
buf.append(" private String b= \"b\";\n"); |
| 1468 |
buf.append(" public void foo() {\n"); |
| 1469 |
buf.append(" b.equals(a);\n"); |
| 1470 |
buf.append(" }\n"); |
| 1471 |
buf.append("}\n"); |
| 1472 |
assertEqualString(preview, buf.toString()); |
| 1473 |
|
| 1474 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1475 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1476 |
proposals= collectAssists(context, false); |
| 1477 |
|
| 1478 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1479 |
assertCorrectLabels(proposals); |
| 1480 |
|
| 1481 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1482 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1483 |
|
| 1484 |
buf= new StringBuffer(); |
| 1485 |
buf.append("package test1;\n"); |
| 1486 |
buf.append("public class E {\n"); |
| 1487 |
buf.append(" private String a= \"a\";\n"); |
| 1488 |
buf.append(" private String b= \"b\";\n"); |
| 1489 |
buf.append(" public void foo() {\n"); |
| 1490 |
buf.append(" a.equals(b);\n"); |
| 1491 |
buf.append(" }\n"); |
| 1492 |
buf.append("}\n"); |
| 1493 |
assertEqualString(preview, buf.toString()); |
| 1494 |
} |
| 1495 |
|
| 1496 |
public void testInvertEquals4() throws Exception { |
| 1497 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1498 |
StringBuffer buf= new StringBuffer(); |
| 1499 |
buf.append("package test1;\n"); |
| 1500 |
buf.append("class S {\n"); |
| 1501 |
buf.append(" protected String sup= \"a\";\n"); |
| 1502 |
buf.append("}\n"); |
| 1503 |
buf.append("public class E extends S {\n"); |
| 1504 |
buf.append(" private String a= \"a\";\n"); |
| 1505 |
buf.append(" public void foo() {\n"); |
| 1506 |
buf.append(" sup.equals(this.a);\n"); |
| 1507 |
buf.append(" }\n"); |
| 1508 |
buf.append("}\n"); |
| 1509 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1510 |
|
| 1511 |
String str= "equals"; |
| 1512 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1513 |
List proposals= collectAssists(context, false); |
| 1514 |
|
| 1515 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1516 |
assertCorrectLabels(proposals); |
| 1517 |
|
| 1518 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1519 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1520 |
|
| 1521 |
buf= new StringBuffer(); |
| 1522 |
buf.append("package test1;\n"); |
| 1523 |
buf.append("class S {\n"); |
| 1524 |
buf.append(" protected String sup= \"a\";\n"); |
| 1525 |
buf.append("}\n"); |
| 1526 |
buf.append("public class E extends S {\n"); |
| 1527 |
buf.append(" private String a= \"a\";\n"); |
| 1528 |
buf.append(" public void foo() {\n"); |
| 1529 |
buf.append(" this.a.equals(sup);\n"); |
| 1530 |
buf.append(" }\n"); |
| 1531 |
buf.append("}\n"); |
| 1532 |
assertEqualString(preview, buf.toString()); |
| 1533 |
|
| 1534 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1535 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1536 |
proposals= collectAssists(context, false); |
| 1537 |
|
| 1538 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1539 |
assertCorrectLabels(proposals); |
| 1540 |
|
| 1541 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1542 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1543 |
|
| 1544 |
buf= new StringBuffer(); |
| 1545 |
buf.append("package test1;\n"); |
| 1546 |
buf.append("class S {\n"); |
| 1547 |
buf.append(" protected String sup= \"a\";\n"); |
| 1548 |
buf.append("}\n"); |
| 1549 |
buf.append("public class E extends S {\n"); |
| 1550 |
buf.append(" private String a= \"a\";\n"); |
| 1551 |
buf.append(" public void foo() {\n"); |
| 1552 |
buf.append(" sup.equals(this.a);\n"); |
| 1553 |
buf.append(" }\n"); |
| 1554 |
buf.append("}\n"); |
| 1555 |
assertEqualString(preview, buf.toString()); |
| 1556 |
} |
| 1557 |
|
| 1558 |
public void testInvertEquals5() throws Exception { |
| 1559 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1560 |
StringBuffer buf= new StringBuffer(); |
| 1561 |
buf.append("package test1;\n"); |
| 1562 |
buf.append("class A {\n"); |
| 1563 |
buf.append(" static String A= \"a\";\n"); |
| 1564 |
buf.append("}\n"); |
| 1565 |
buf.append("public class E {\n"); |
| 1566 |
buf.append(" public void foo() {\n"); |
| 1567 |
buf.append(" \"a\".equals(A.A);\n"); |
| 1568 |
buf.append(" }\n"); |
| 1569 |
buf.append("}\n"); |
| 1570 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1571 |
|
| 1572 |
String str= "equals"; |
| 1573 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1574 |
List proposals= collectAssists(context, false); |
| 1575 |
|
| 1576 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1577 |
assertCorrectLabels(proposals); |
| 1578 |
|
| 1579 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1580 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1581 |
|
| 1582 |
buf= new StringBuffer(); |
| 1583 |
buf.append("package test1;\n"); |
| 1584 |
buf.append("class A {\n"); |
| 1585 |
buf.append(" static String A= \"a\";\n"); |
| 1586 |
buf.append("}\n"); |
| 1587 |
buf.append("public class E {\n"); |
| 1588 |
buf.append(" public void foo() {\n"); |
| 1589 |
buf.append(" A.A.equals(\"a\");\n"); |
| 1590 |
buf.append(" }\n"); |
| 1591 |
buf.append("}\n"); |
| 1592 |
assertEqualString(preview, buf.toString()); |
| 1593 |
|
| 1594 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1595 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1596 |
proposals= collectAssists(context, false); |
| 1597 |
|
| 1598 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1599 |
assertCorrectLabels(proposals); |
| 1600 |
|
| 1601 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1602 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1603 |
|
| 1604 |
buf= new StringBuffer(); |
| 1605 |
buf.append("package test1;\n"); |
| 1606 |
buf.append("class A {\n"); |
| 1607 |
buf.append(" static String A= \"a\";\n"); |
| 1608 |
buf.append("}\n"); |
| 1609 |
buf.append("public class E {\n"); |
| 1610 |
buf.append(" public void foo() {\n"); |
| 1611 |
buf.append(" \"a\".equals(A.A);\n"); |
| 1612 |
buf.append(" }\n"); |
| 1613 |
buf.append("}\n"); |
| 1614 |
assertEqualString(preview, buf.toString()); |
| 1615 |
} |
| 1616 |
|
| 1617 |
public void testInvertEquals6() throws Exception { |
| 1618 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1619 |
StringBuffer buf= new StringBuffer(); |
| 1620 |
buf.append("package test1;\n"); |
| 1621 |
buf.append("class A {\n"); |
| 1622 |
buf.append(" static String get() {\n"); |
| 1623 |
buf.append(" return \"a\";\n"); |
| 1624 |
buf.append(" }\n"); |
| 1625 |
buf.append("}\n"); |
| 1626 |
buf.append("public class E {\n"); |
| 1627 |
buf.append(" public void foo() {\n"); |
| 1628 |
buf.append(" \"a\".equals(A.get());\n"); |
| 1629 |
buf.append(" }\n"); |
| 1630 |
buf.append("}\n"); |
| 1631 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1632 |
|
| 1633 |
String str= "equals"; |
| 1634 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1635 |
List proposals= collectAssists(context, false); |
| 1636 |
|
| 1637 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1638 |
assertCorrectLabels(proposals); |
| 1639 |
|
| 1640 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1641 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1642 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1643 |
|
| 1644 |
buf= new StringBuffer(); |
| 1645 |
buf.append("package test1;\n"); |
| 1646 |
buf.append("class A {\n"); |
| 1647 |
buf.append(" static String get() {\n"); |
| 1648 |
buf.append(" return \"a\";\n"); |
| 1649 |
buf.append(" }\n"); |
| 1650 |
buf.append("}\n"); |
| 1651 |
buf.append("public class E {\n"); |
| 1652 |
buf.append(" public void foo() {\n"); |
| 1653 |
buf.append(" A.get().equals(\"a\");\n"); |
| 1654 |
buf.append(" }\n"); |
| 1655 |
buf.append("}\n"); |
| 1656 |
assertEqualString(preview, buf.toString()); |
| 1657 |
|
| 1658 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1659 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1660 |
proposals= collectAssists(context, false); |
| 1661 |
|
| 1662 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1663 |
assertCorrectLabels(proposals); |
| 1664 |
|
| 1665 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1666 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1667 |
|
| 1668 |
buf= new StringBuffer(); |
| 1669 |
buf.append("package test1;\n"); |
| 1670 |
buf.append("class A {\n"); |
| 1671 |
buf.append(" static String get() {\n"); |
| 1672 |
buf.append(" return \"a\";\n"); |
| 1673 |
buf.append(" }\n"); |
| 1674 |
buf.append("}\n"); |
| 1675 |
buf.append("public class E {\n"); |
| 1676 |
buf.append(" public void foo() {\n"); |
| 1677 |
buf.append(" \"a\".equals(A.get());\n"); |
| 1678 |
buf.append(" }\n"); |
| 1679 |
buf.append("}\n"); |
| 1680 |
assertEqualString(preview, buf.toString()); |
| 1681 |
} |
| 1682 |
|
| 1683 |
public void testInvertEquals7() throws Exception { |
| 1684 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1685 |
StringBuffer buf= new StringBuffer(); |
| 1686 |
buf.append("package test1;\n"); |
| 1687 |
buf.append("public class E {\n"); |
| 1688 |
buf.append(" public void foo() {\n"); |
| 1689 |
buf.append(" \"a\".getClass().equals(String.class);\n"); |
| 1690 |
buf.append(" }\n"); |
| 1691 |
buf.append("}\n"); |
| 1692 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1693 |
|
| 1694 |
String str= "equals"; |
| 1695 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1696 |
List proposals= collectAssists(context, false); |
| 1697 |
|
| 1698 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1699 |
assertCorrectLabels(proposals); |
| 1700 |
|
| 1701 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1702 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1703 |
|
| 1704 |
buf= new StringBuffer(); |
| 1705 |
buf.append("package test1;\n"); |
| 1706 |
buf.append("public class E {\n"); |
| 1707 |
buf.append(" public void foo() {\n"); |
| 1708 |
buf.append(" String.class.equals(\"a\".getClass());\n"); |
| 1709 |
buf.append(" }\n"); |
| 1710 |
buf.append("}\n"); |
| 1711 |
assertEqualString(preview, buf.toString()); |
| 1712 |
|
| 1713 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1714 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1715 |
proposals= collectAssists(context, false); |
| 1716 |
|
| 1717 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1718 |
assertCorrectLabels(proposals); |
| 1719 |
|
| 1720 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1721 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1722 |
|
| 1723 |
buf= new StringBuffer(); |
| 1724 |
buf.append("package test1;\n"); |
| 1725 |
buf.append("public class E {\n"); |
| 1726 |
buf.append(" public void foo() {\n"); |
| 1727 |
buf.append(" \"a\".getClass().equals(String.class);\n"); |
| 1728 |
buf.append(" }\n"); |
| 1729 |
buf.append("}\n"); |
| 1730 |
assertEqualString(preview, buf.toString()); |
| 1731 |
} |
| 1732 |
|
| 1733 |
public void testInvertEquals8() throws Exception { |
| 1734 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1735 |
StringBuffer buf= new StringBuffer(); |
| 1736 |
buf.append("package test1;\n"); |
| 1737 |
buf.append("public class E {\n"); |
| 1738 |
buf.append(" public void foo() {\n"); |
| 1739 |
buf.append(" boolean x = false && \"a\".equals(get());\n"); |
| 1740 |
buf.append(" }\n"); |
| 1741 |
buf.append(" String get() {\n"); |
| 1742 |
buf.append(" return \"a\";\n"); |
| 1743 |
buf.append(" }\n"); |
| 1744 |
buf.append("}\n"); |
| 1745 |
|
| 1746 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1747 |
|
| 1748 |
String str= "equals"; |
| 1749 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1750 |
List proposals= collectAssists(context, false); |
| 1751 |
|
| 1752 |
assertNumberOf("proposals", proposals.size(), 1); |
| 1753 |
assertCorrectLabels(proposals); |
| 1754 |
|
| 1755 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); |
| 1756 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1757 |
|
| 1758 |
buf= new StringBuffer(); |
| 1759 |
buf.append("package test1;\n"); |
| 1760 |
buf.append("public class E {\n"); |
| 1761 |
buf.append(" public void foo() {\n"); |
| 1762 |
buf.append(" boolean x = false && get().equals(\"a\");\n"); |
| 1763 |
buf.append(" }\n"); |
| 1764 |
buf.append(" String get() {\n"); |
| 1765 |
buf.append(" return \"a\";\n"); |
| 1766 |
buf.append(" }\n"); |
| 1767 |
buf.append("}\n"); |
| 1768 |
assertEqualString(preview, buf.toString()); |
| 1769 |
|
| 1770 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1771 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1772 |
proposals= collectAssists(context, false); |
| 1773 |
|
| 1774 |
assertNumberOf("proposals", proposals.size(), 1); |
| 1775 |
assertCorrectLabels(proposals); |
| 1776 |
|
| 1777 |
proposal= (CUCorrectionProposal) proposals.get(0); |
| 1778 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1779 |
|
| 1780 |
buf= new StringBuffer(); |
| 1781 |
buf.append("package test1;\n"); |
| 1782 |
buf.append("public class E {\n"); |
| 1783 |
buf.append(" public void foo() {\n"); |
| 1784 |
buf.append(" boolean x = false && \"a\".equals(get());\n"); |
| 1785 |
buf.append(" }\n"); |
| 1786 |
buf.append(" String get() {\n"); |
| 1787 |
buf.append(" return \"a\";\n"); |
| 1788 |
buf.append(" }\n"); |
| 1789 |
buf.append("}\n"); |
| 1790 |
assertEqualString(preview, buf.toString()); |
| 1791 |
} |
| 1792 |
|
| 1793 |
public void testInvertEquals9() throws Exception { |
| 1794 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1795 |
StringBuffer buf= new StringBuffer(); |
| 1796 |
buf.append("package test1;\n"); |
| 1797 |
buf.append("public class E {\n"); |
| 1798 |
buf.append(" public void foo() {\n"); |
| 1799 |
buf.append(" equals(new E());\n"); |
| 1800 |
buf.append(" }\n"); |
| 1801 |
buf.append("}\n"); |
| 1802 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1803 |
|
| 1804 |
String str= "equals"; |
| 1805 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1806 |
List proposals= collectAssists(context, false); |
| 1807 |
|
| 1808 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1809 |
assertCorrectLabels(proposals); |
| 1810 |
|
| 1811 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 1812 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1813 |
|
| 1814 |
buf= new StringBuffer(); |
| 1815 |
buf.append("package test1;\n"); |
| 1816 |
buf.append("public class E {\n"); |
| 1817 |
buf.append(" public void foo() {\n"); |
| 1818 |
buf.append(" new E().equals(this);\n"); |
| 1819 |
buf.append(" }\n"); |
| 1820 |
buf.append("}\n"); |
| 1821 |
assertEqualString(preview, buf.toString()); |
| 1822 |
|
| 1823 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 1824 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1825 |
proposals= collectAssists(context, false); |
| 1826 |
|
| 1827 |
assertNumberOf("proposals", proposals.size(), 3); |
| 1828 |
assertCorrectLabels(proposals); |
| 1829 |
|
| 1830 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 1831 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 1832 |
|
| 1833 |
buf= new StringBuffer(); |
| 1834 |
buf.append("package test1;\n"); |
| 1835 |
buf.append("public class E {\n"); |
| 1836 |
buf.append(" public void foo() {\n"); |
| 1837 |
buf.append(" equals(new E());\n"); |
| 1838 |
buf.append(" }\n"); |
| 1839 |
buf.append("}\n"); |
| 1840 |
assertEqualString(preview, buf.toString()); |
| 1841 |
} |
| 1842 |
|
| 1843 |
public void testInvertEquals10() throws Exception { |
| 1844 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1845 |
StringBuffer buf= new StringBuffer(); |
| 1846 |
buf.append("package test1;\n"); |
| 1847 |
buf.append("public class E {\n"); |
| 1848 |
buf.append(" public void foo() {\n"); |
| 1849 |
buf.append(" \"a\".equals(null);\n"); |
| 1850 |
buf.append(" }\n"); |
| 1851 |
buf.append("}\n"); |
| 1852 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1853 |
|
| 1854 |
String str= "equals"; |
| 1855 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1856 |
List proposals= collectAssists(context, false); |
| 1857 |
|
| 1858 |
assertNumberOf("proposals", proposals.size(), 2); |
| 1859 |
assertCorrectLabels(proposals); |
| 1860 |
} |
| 1861 |
|
| 1862 |
public void testInvertEquals11() throws Exception { |
| 1863 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1864 |
StringBuffer buf= new StringBuffer(); |
| 1865 |
buf.append("package test1;\n"); |
| 1866 |
buf.append("public class E {\n"); |
| 1867 |
buf.append(" boolean equals(Object o, boolean a) {\n"); |
| 1868 |
buf.append(" return false;\n"); |
| 1869 |
buf.append(" }\n"); |
| 1870 |
buf.append(" public void foo() {\n"); |
| 1871 |
buf.append(" new E().equals(\"a\", false);\n"); |
| 1872 |
buf.append(" }\n"); |
| 1873 |
buf.append("}\n"); |
| 1874 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1875 |
|
| 1876 |
String str= "equals"; |
| 1877 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1878 |
List proposals= collectAssists(context, false); |
| 1879 |
|
| 1880 |
assertNumberOf("proposals", proposals.size(), 0); |
| 1881 |
assertCorrectLabels(proposals); |
| 1882 |
|
| 1883 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 1884 |
proposals= collectAssists(context, false); |
| 1885 |
|
| 1886 |
assertNumberOf("proposals", proposals.size(), 2); |
| 1887 |
assertCorrectLabels(proposals); |
| 1888 |
} |
| 1889 |
|
| 1890 |
public void testInvertEquals12() throws Exception { |
| 1891 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1892 |
StringBuffer buf= new StringBuffer(); |
| 1893 |
buf.append("package test1;\n"); |
| 1894 |
buf.append("public class E {\n"); |
| 1895 |
buf.append(" boolean equals(boolean b) {\n"); |
| 1896 |
buf.append(" return false;\n"); |
| 1897 |
buf.append(" }\n"); |
| 1898 |
buf.append(" public void foo() {\n"); |
| 1899 |
buf.append(" new E().equals(false);\n"); |
| 1900 |
buf.append(" }\n"); |
| 1901 |
buf.append("}\n"); |
| 1902 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1903 |
|
| 1904 |
String str= "equals"; |
| 1905 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1906 |
List proposals= collectAssists(context, false); |
| 1907 |
|
| 1908 |
assertNumberOf("proposals", proposals.size(), 0); |
| 1909 |
assertCorrectLabels(proposals); |
| 1910 |
|
| 1911 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 1912 |
proposals= collectAssists(context, false); |
| 1913 |
|
| 1914 |
assertNumberOf("proposals", proposals.size(), 2); |
| 1915 |
assertCorrectLabels(proposals); |
| 1916 |
} |
| 1917 |
|
| 1918 |
public void testInvertEquals13() throws Exception { |
| 1919 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1920 |
StringBuffer buf= new StringBuffer(); |
| 1921 |
buf.append("package test1;\n"); |
| 1922 |
buf.append("public class E {\n"); |
| 1923 |
buf.append(" boolean equals(boolean b) {\n"); |
| 1924 |
buf.append(" return false;\n"); |
| 1925 |
buf.append(" }\n"); |
| 1926 |
buf.append(" public void foo() {\n"); |
| 1927 |
buf.append(" new E().equals(true ? true : false);\n"); |
| 1928 |
buf.append(" }\n"); |
| 1929 |
buf.append("}\n"); |
| 1930 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1931 |
|
| 1932 |
String str= "equals"; |
| 1933 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1934 |
List proposals= collectAssists(context, false); |
| 1935 |
|
| 1936 |
assertNumberOf("proposals", proposals.size(), 0); |
| 1937 |
assertCorrectLabels(proposals); |
| 1938 |
|
| 1939 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 1940 |
proposals= collectAssists(context, false); |
| 1941 |
|
| 1942 |
assertNumberOf("proposals", proposals.size(), 2); |
| 1943 |
assertCorrectLabels(proposals); |
| 1944 |
} |
| 1945 |
|
| 1946 |
public void testInvertEquals14() throws Exception { |
| 1947 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1948 |
StringBuffer buf= new StringBuffer(); |
| 1949 |
buf.append("package test1;\n"); |
| 1950 |
buf.append("class Super {\n"); |
| 1951 |
buf.append(" protected boolean sBool= false;\n"); |
| 1952 |
buf.append("}\n"); |
| 1953 |
buf.append("public class E extends Super {\n"); |
| 1954 |
buf.append(" boolean equals(boolean b) {\n"); |
| 1955 |
buf.append(" return false;\n"); |
| 1956 |
buf.append(" }\n"); |
| 1957 |
buf.append(" public void foo() {\n"); |
| 1958 |
buf.append(" new E().equals(sBool);\n"); |
| 1959 |
buf.append(" }\n"); |
| 1960 |
buf.append("}\n"); |
| 1961 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1962 |
|
| 1963 |
String str= "equals"; |
| 1964 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1965 |
List proposals= collectAssists(context, false); |
| 1966 |
|
| 1967 |
assertNumberOf("proposals", proposals.size(), 0); |
| 1968 |
assertCorrectLabels(proposals); |
| 1969 |
|
| 1970 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 1971 |
proposals= collectAssists(context, false); |
| 1972 |
|
| 1973 |
assertNumberOf("proposals", proposals.size(), 2); |
| 1974 |
assertCorrectLabels(proposals); |
| 1975 |
} |
| 1976 |
|
| 1977 |
public void testInvertEquals15() throws Exception { |
| 1978 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 1979 |
StringBuffer buf= new StringBuffer(); |
| 1980 |
buf.append("package test1;\n"); |
| 1981 |
buf.append("public class E {\n"); |
| 1982 |
buf.append(" boolean equals(int i) {\n"); |
| 1983 |
buf.append(" return false;\n"); |
| 1984 |
buf.append(" }\n"); |
| 1985 |
buf.append(" public void foo() {\n"); |
| 1986 |
buf.append(" new E().equals(1 + 1);\n"); |
| 1987 |
buf.append(" }\n"); |
| 1988 |
buf.append("}\n"); |
| 1989 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 1990 |
|
| 1991 |
String str= "equals"; |
| 1992 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 1993 |
List proposals= collectAssists(context, false); |
| 1994 |
|
| 1995 |
assertNumberOf("proposals", proposals.size(), 0); |
| 1996 |
assertCorrectLabels(proposals); |
| 1997 |
|
| 1998 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 1999 |
proposals= collectAssists(context, false); |
| 2000 |
|
| 2001 |
assertNumberOf("proposals", proposals.size(), 2); |
| 2002 |
assertCorrectLabels(proposals); |
| 2003 |
} |
| 2004 |
|
| 2005 |
public void testInvertEquals16() throws Exception { |
| 2006 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2007 |
StringBuffer buf= new StringBuffer(); |
| 2008 |
buf.append("package test1;\n"); |
| 2009 |
buf.append("public class E {\n"); |
| 2010 |
buf.append(" boolean equals(int i) {\n"); |
| 2011 |
buf.append(" return false;\n"); |
| 2012 |
buf.append(" }\n"); |
| 2013 |
buf.append(" public void foo() {\n"); |
| 2014 |
buf.append(" int i= 1;\n"); |
| 2015 |
buf.append(" new E().equals(i + i);\n"); |
| 2016 |
buf.append(" }\n"); |
| 2017 |
buf.append("}\n"); |
| 2018 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2019 |
|
| 2020 |
String str= "equals"; |
| 2021 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2022 |
List proposals= collectAssists(context, false); |
| 2023 |
|
| 2024 |
assertNumberOf("proposals", proposals.size(), 0); |
| 2025 |
assertCorrectLabels(proposals); |
| 2026 |
|
| 2027 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 2028 |
proposals= collectAssists(context, false); |
| 2029 |
|
| 2030 |
assertNumberOf("proposals", proposals.size(), 2); |
| 2031 |
assertCorrectLabels(proposals); |
| 2032 |
} |
| 2033 |
|
| 2034 |
public void testInvertEquals17() throws Exception { |
| 2035 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2036 |
StringBuffer buf= new StringBuffer(); |
| 2037 |
buf.append("package test1;\n"); |
| 2038 |
buf.append("public class E {\n"); |
| 2039 |
buf.append(" public void foo() {\n"); |
| 2040 |
buf.append(" \"a\".equals(null);\n"); |
| 2041 |
buf.append(" }\n"); |
| 2042 |
buf.append("}\n"); |
| 2043 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2044 |
|
| 2045 |
String str= "equals"; |
| 2046 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2047 |
List proposals= collectAssists(context, false); |
| 2048 |
|
| 2049 |
assertNumberOf("proposals", proposals.size(), 2); |
| 2050 |
assertCorrectLabels(proposals); |
| 2051 |
} |
| 2052 |
|
| 2053 |
public void testInvertEquals18() throws Exception { |
| 2054 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2055 |
StringBuffer buf= new StringBuffer(); |
| 2056 |
buf.append("package test1;\n"); |
| 2057 |
buf.append("public class E {\n"); |
| 2058 |
buf.append(" public boolean equals(Object o) {\n"); |
| 2059 |
buf.append(" return super.equals(o);\n"); |
| 2060 |
buf.append(" }\n"); |
| 2061 |
buf.append("}\n"); |
| 2062 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2063 |
|
| 2064 |
String str= "equals"; |
| 2065 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2066 |
List proposals= collectAssists(context, false); |
| 2067 |
|
| 2068 |
assertNumberOf("proposals", proposals.size(), 0); |
| 2069 |
assertCorrectLabels(proposals); |
| 2070 |
|
| 2071 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
| 2072 |
proposals= collectAssists(context, false); |
| 2073 |
|
| 2074 |
assertNumberOf("proposals", proposals.size(), 0); |
| 2075 |
assertCorrectLabels(proposals); |
| 2076 |
} |
| 2077 |
|
| 2078 |
public void testInvertEquals19() throws Exception { |
| 2079 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2080 |
StringBuffer buf= new StringBuffer(); |
| 2081 |
buf.append("package test1;\n"); |
| 2082 |
buf.append("public class E {\n"); |
| 2083 |
buf.append(" private String a= \"a\";\n"); |
| 2084 |
buf.append(" public void foo() {\n"); |
| 2085 |
buf.append(" a.equals((Object) \"a\");\n"); |
| 2086 |
buf.append(" }\n"); |
| 2087 |
buf.append("}\n"); |
| 2088 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2089 |
|
| 2090 |
String str= "equals"; |
| 2091 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2092 |
List proposals= collectAssists(context, false); |
| 2093 |
|
| 2094 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2095 |
assertCorrectLabels(proposals); |
| 2096 |
|
| 2097 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 2098 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2099 |
|
| 2100 |
buf= new StringBuffer(); |
| 2101 |
buf.append("package test1;\n"); |
| 2102 |
buf.append("public class E {\n"); |
| 2103 |
buf.append(" private String a= \"a\";\n"); |
| 2104 |
buf.append(" public void foo() {\n"); |
| 2105 |
buf.append(" ((Object) \"a\").equals(a);\n"); |
| 2106 |
buf.append(" }\n"); |
| 2107 |
buf.append("}\n"); |
| 2108 |
assertEqualString(preview, buf.toString()); |
| 2109 |
|
| 2110 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 2111 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2112 |
proposals= collectAssists(context, false); |
| 2113 |
|
| 2114 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2115 |
assertCorrectLabels(proposals); |
| 2116 |
|
| 2117 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 2118 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2119 |
|
| 2120 |
buf= new StringBuffer(); |
| 2121 |
buf.append("package test1;\n"); |
| 2122 |
buf.append("public class E {\n"); |
| 2123 |
buf.append(" private String a= \"a\";\n"); |
| 2124 |
buf.append(" public void foo() {\n"); |
| 2125 |
buf.append(" a.equals((Object) \"a\");\n"); |
| 2126 |
buf.append(" }\n"); |
| 2127 |
buf.append("}\n"); |
| 2128 |
assertEqualString(preview, buf.toString()); |
| 2129 |
} |
| 2130 |
|
| 2131 |
public void testInvertEquals20() throws Exception { |
| 2132 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2133 |
StringBuffer buf= new StringBuffer(); |
| 2134 |
buf.append("package test1;\n"); |
| 2135 |
buf.append("public class E {\n"); |
| 2136 |
buf.append(" public void foo() {\n"); |
| 2137 |
buf.append(" String s= null;\n"); |
| 2138 |
buf.append(" \"a\".equals(s = \"a\");\n"); |
| 2139 |
buf.append(" }\n"); |
| 2140 |
buf.append("}\n"); |
| 2141 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2142 |
|
| 2143 |
String str= "equals"; |
| 2144 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2145 |
List proposals= collectAssists(context, false); |
| 2146 |
|
| 2147 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2148 |
assertCorrectLabels(proposals); |
| 2149 |
|
| 2150 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 2151 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2152 |
|
| 2153 |
buf= new StringBuffer(); |
| 2154 |
buf.append("package test1;\n"); |
| 2155 |
buf.append("public class E {\n"); |
| 2156 |
buf.append(" public void foo() {\n"); |
| 2157 |
buf.append(" String s= null;\n"); |
| 2158 |
buf.append(" (s = \"a\").equals(\"a\");\n"); |
| 2159 |
buf.append(" }\n"); |
| 2160 |
buf.append("}\n"); |
| 2161 |
assertEqualString(preview, buf.toString()); |
| 2162 |
|
| 2163 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 2164 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2165 |
proposals= collectAssists(context, false); |
| 2166 |
|
| 2167 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2168 |
assertCorrectLabels(proposals); |
| 2169 |
|
| 2170 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 2171 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2172 |
|
| 2173 |
buf= new StringBuffer(); |
| 2174 |
buf.append("package test1;\n"); |
| 2175 |
buf.append("public class E {\n"); |
| 2176 |
buf.append(" public void foo() {\n"); |
| 2177 |
buf.append(" String s= null;\n"); |
| 2178 |
buf.append(" \"a\".equals(s = \"a\");\n"); |
| 2179 |
buf.append(" }\n"); |
| 2180 |
buf.append("}\n"); |
| 2181 |
assertEqualString(preview, buf.toString()); |
| 2182 |
} |
| 2183 |
|
| 2184 |
public void testInvertEquals21() throws Exception { |
| 2185 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2186 |
StringBuffer buf= new StringBuffer(); |
| 2187 |
buf.append("package test1;\n"); |
| 2188 |
buf.append("public class E {\n"); |
| 2189 |
buf.append(" public void foo() {\n"); |
| 2190 |
buf.append(" \"aaa\".equals(\"a\" + \"a\" + \"a\");\n"); |
| 2191 |
buf.append(" }\n"); |
| 2192 |
buf.append("}\n"); |
| 2193 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2194 |
|
| 2195 |
String str= "equals"; |
| 2196 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2197 |
List proposals= collectAssists(context, false); |
| 2198 |
|
| 2199 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2200 |
assertCorrectLabels(proposals); |
| 2201 |
|
| 2202 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 2203 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2204 |
|
| 2205 |
buf= new StringBuffer(); |
| 2206 |
buf.append("package test1;\n"); |
| 2207 |
buf.append("public class E {\n"); |
| 2208 |
buf.append(" public void foo() {\n"); |
| 2209 |
buf.append(" (\"a\" + \"a\" + \"a\").equals(\"aaa\");\n"); |
| 2210 |
buf.append(" }\n"); |
| 2211 |
buf.append("}\n"); |
| 2212 |
assertEqualString(preview, buf.toString()); |
| 2213 |
|
| 2214 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 2215 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2216 |
proposals= collectAssists(context, false); |
| 2217 |
|
| 2218 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2219 |
assertCorrectLabels(proposals); |
| 2220 |
|
| 2221 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 2222 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2223 |
|
| 2224 |
buf= new StringBuffer(); |
| 2225 |
buf.append("package test1;\n"); |
| 2226 |
buf.append("public class E {\n"); |
| 2227 |
buf.append(" public void foo() {\n"); |
| 2228 |
buf.append(" \"aaa\".equals(\"a\" + \"a\" + \"a\");\n"); |
| 2229 |
buf.append(" }\n"); |
| 2230 |
buf.append("}\n"); |
| 2231 |
assertEqualString(preview, buf.toString()); |
| 2232 |
} |
| 2233 |
|
| 2234 |
public void testInvertEquals22() throws Exception { |
| 2235 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2236 |
StringBuffer buf= new StringBuffer(); |
| 2237 |
buf.append("package test1;\n"); |
| 2238 |
buf.append("public class E {\n"); |
| 2239 |
buf.append(" public void foo() {\n"); |
| 2240 |
buf.append(" \"a\".equals(true ? \"a\" : \"b\");\n"); |
| 2241 |
buf.append(" }\n"); |
| 2242 |
buf.append("}\n"); |
| 2243 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2244 |
|
| 2245 |
String str= "equals"; |
| 2246 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2247 |
List proposals= collectAssists(context, false); |
| 2248 |
|
| 2249 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2250 |
assertCorrectLabels(proposals); |
| 2251 |
|
| 2252 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 2253 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2254 |
|
| 2255 |
buf= new StringBuffer(); |
| 2256 |
buf.append("package test1;\n"); |
| 2257 |
buf.append("public class E {\n"); |
| 2258 |
buf.append(" public void foo() {\n"); |
| 2259 |
buf.append(" (true ? \"a\" : \"b\").equals(\"a\");\n"); |
| 2260 |
buf.append(" }\n"); |
| 2261 |
buf.append("}\n"); |
| 2262 |
assertEqualString(preview, buf.toString()); |
| 2263 |
|
| 2264 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 2265 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2266 |
proposals= collectAssists(context, false); |
| 2267 |
|
| 2268 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2269 |
assertCorrectLabels(proposals); |
| 2270 |
|
| 2271 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 2272 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2273 |
|
| 2274 |
buf= new StringBuffer(); |
| 2275 |
buf.append("package test1;\n"); |
| 2276 |
buf.append("public class E {\n"); |
| 2277 |
buf.append(" public void foo() {\n"); |
| 2278 |
buf.append(" \"a\".equals(true ? \"a\" : \"b\");\n"); |
| 2279 |
buf.append(" }\n"); |
| 2280 |
buf.append("}\n"); |
| 2281 |
assertEqualString(preview, buf.toString()); |
| 2282 |
} |
| 2283 |
|
| 2284 |
public void testInvertEquals23() throws Exception { |
| 2285 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 2286 |
StringBuffer buf= new StringBuffer(); |
| 2287 |
buf.append("package test1;\n"); |
| 2288 |
buf.append("public class E {\n"); |
| 2289 |
buf.append(" public void foo() {\n"); |
| 2290 |
buf.append(" \"a\".equals((\"a\"));\n"); |
| 2291 |
buf.append(" }\n"); |
| 2292 |
buf.append("}\n"); |
| 2293 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 2294 |
|
| 2295 |
String str= "equals"; |
| 2296 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2297 |
List proposals= collectAssists(context, false); |
| 2298 |
|
| 2299 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2300 |
assertCorrectLabels(proposals); |
| 2301 |
|
| 2302 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(2); |
| 2303 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2304 |
|
| 2305 |
buf= new StringBuffer(); |
| 2306 |
buf.append("package test1;\n"); |
| 2307 |
buf.append("public class E {\n"); |
| 2308 |
buf.append(" public void foo() {\n"); |
| 2309 |
buf.append(" (\"a\").equals(\"a\");\n"); |
| 2310 |
buf.append(" }\n"); |
| 2311 |
buf.append("}\n"); |
| 2312 |
assertEqualString(preview, buf.toString()); |
| 2313 |
|
| 2314 |
cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null); |
| 2315 |
context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
| 2316 |
proposals= collectAssists(context, false); |
| 2317 |
|
| 2318 |
assertNumberOf("proposals", proposals.size(), 3); |
| 2319 |
assertCorrectLabels(proposals); |
| 2320 |
|
| 2321 |
proposal= (CUCorrectionProposal) proposals.get(2); |
| 2322 |
preview= proposal.getCompilationUnitChange().getPreviewContent(); |
| 2323 |
|
| 2324 |
buf= new StringBuffer(); |
| 2325 |
buf.append("package test1;\n"); |
| 2326 |
buf.append("public class E {\n"); |
| 2327 |
buf.append(" public void foo() {\n"); |
| 2328 |
buf.append(" \"a\".equals(\"a\");\n"); |
| 2329 |
buf.append(" }\n"); |
| 2330 |
buf.append("}\n"); |
| 2331 |
assertEqualString(preview, buf.toString()); |
| 2332 |
} |
| 1336 |
} |
2333 |
} |