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> - testChangeEqualsToSame, testChangeSameToEquals |
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 testChangeEqualsToSame() 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(" boolean b= \"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(), 2); |
1353 |
assertCorrectLabels(proposals); |
1354 |
|
1355 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1); |
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(" boolean b= \"a\" == \"b\";\n"); |
1363 |
buf.append(" }\n"); |
1364 |
buf.append("}\n"); |
1365 |
assertEqualString(preview, buf.toString()); |
1366 |
} |
1367 |
|
1368 |
public void testChangeEqualsToSame2() throws Exception { |
1369 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1370 |
StringBuffer buf= new StringBuffer(); |
1371 |
buf.append("package test1;\n"); |
1372 |
buf.append("public class E {\n"); |
1373 |
buf.append(" public void foo() {\n"); |
1374 |
buf.append(" boolean b= equals(null);\n"); |
1375 |
buf.append(" }\n"); |
1376 |
buf.append("}\n"); |
1377 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1378 |
|
1379 |
String str= "equals"; |
1380 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1381 |
List proposals= collectAssists(context, false); |
1382 |
|
1383 |
assertNumberOf("proposals", proposals.size(), 1); |
1384 |
assertCorrectLabels(proposals); |
1385 |
|
1386 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); |
1387 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
1388 |
|
1389 |
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(" boolean b= this == null;\n"); |
1394 |
buf.append(" }\n"); |
1395 |
buf.append("}\n"); |
1396 |
assertEqualString(preview, buf.toString()); |
1397 |
} |
1398 |
|
1399 |
public void testChangeEqualsToSame3() throws Exception { |
1400 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1401 |
StringBuffer buf= new StringBuffer(); |
1402 |
buf.append("package test1;\n"); |
1403 |
buf.append("public class E {\n"); |
1404 |
buf.append(" boolean equals(Object o, boolean a) {\n"); |
1405 |
buf.append(" return false;\n"); |
1406 |
buf.append(" }\n"); |
1407 |
buf.append(" public void foo() {\n"); |
1408 |
buf.append(" boolean b= new E().equals(\"a\", false);\n"); |
1409 |
buf.append(" }\n"); |
1410 |
buf.append("}\n"); |
1411 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1412 |
|
1413 |
String str= "equals"; |
1414 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1415 |
List proposals= collectAssists(context, false); |
1416 |
|
1417 |
assertNumberOf("proposals", proposals.size(), 0); |
1418 |
assertCorrectLabels(proposals); |
1419 |
|
1420 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
1421 |
proposals= collectAssists(context, false); |
1422 |
|
1423 |
assertNumberOf("proposals", proposals.size(), 0); |
1424 |
assertCorrectLabels(proposals); |
1425 |
} |
1426 |
|
1427 |
public void testChangeEqualsToSame4() throws Exception { |
1428 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1429 |
StringBuffer buf= new StringBuffer(); |
1430 |
buf.append("package test1;\n"); |
1431 |
buf.append("public class E {\n"); |
1432 |
buf.append(" boolean equals(boolean b) {\n"); |
1433 |
buf.append(" return false;\n"); |
1434 |
buf.append(" }\n"); |
1435 |
buf.append(" public void foo() {\n"); |
1436 |
buf.append(" boolean b= new E().equals(false);\n"); |
1437 |
buf.append(" }\n"); |
1438 |
buf.append("}\n"); |
1439 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1440 |
|
1441 |
String str= "equals"; |
1442 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1443 |
List proposals= collectAssists(context, false); |
1444 |
|
1445 |
assertNumberOf("proposals", proposals.size(), 0); |
1446 |
assertCorrectLabels(proposals); |
1447 |
|
1448 |
context= getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0); |
1449 |
proposals= collectAssists(context, false); |
1450 |
|
1451 |
assertNumberOf("proposals", proposals.size(), 0); |
1452 |
assertCorrectLabels(proposals); |
1453 |
} |
1454 |
|
1455 |
public void testChangeEqualsToSame5() throws Exception { |
1456 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1457 |
StringBuffer buf= new StringBuffer(); |
1458 |
buf.append("package test1;\n"); |
1459 |
buf.append("public class E {\n"); |
1460 |
buf.append(" public void foo() {\n"); |
1461 |
buf.append(" boolean b= new E().equals(\"a\");\n"); |
1462 |
buf.append(" }\n"); |
1463 |
buf.append("}\n"); |
1464 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1465 |
|
1466 |
String str= "equals"; |
1467 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1468 |
List proposals= collectAssists(context, false); |
1469 |
|
1470 |
assertNumberOf("proposals", proposals.size(), 1); |
1471 |
assertCorrectLabels(proposals); |
1472 |
} |
1473 |
|
1474 |
public void testChangeSameToEquals() throws Exception { |
1475 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1476 |
StringBuffer buf= new StringBuffer(); |
1477 |
buf.append("package test1;\n"); |
1478 |
buf.append("public class E {\n"); |
1479 |
buf.append(" public void foo() {\n"); |
1480 |
buf.append(" boolean b= \"a\" == \"b\";\n"); |
1481 |
buf.append(" }\n"); |
1482 |
buf.append("}\n"); |
1483 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1484 |
|
1485 |
String str= "=="; |
1486 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1487 |
List proposals= collectAssists(context, false); |
1488 |
|
1489 |
assertNumberOf("proposals", proposals.size(), 2); |
1490 |
assertCorrectLabels(proposals); |
1491 |
|
1492 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1); |
1493 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
1494 |
|
1495 |
buf= new StringBuffer(); |
1496 |
buf.append("package test1;\n"); |
1497 |
buf.append("public class E {\n"); |
1498 |
buf.append(" public void foo() {\n"); |
1499 |
buf.append(" boolean b= \"a\".equals(\"b\");\n"); |
1500 |
buf.append(" }\n"); |
1501 |
buf.append("}\n"); |
1502 |
assertEqualString(preview, buf.toString()); |
1503 |
} |
1504 |
|
1505 |
public void testChangeSameToEquals2() throws Exception { |
1506 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1507 |
StringBuffer buf= new StringBuffer(); |
1508 |
buf.append("package test1;\n"); |
1509 |
buf.append("public class E {\n"); |
1510 |
buf.append(" public void foo() {\n"); |
1511 |
buf.append(" boolean b= this == null;\n"); |
1512 |
buf.append(" }\n"); |
1513 |
buf.append("}\n"); |
1514 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1515 |
|
1516 |
String str= "=="; |
1517 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1518 |
List proposals= collectAssists(context, false); |
1519 |
|
1520 |
assertNumberOf("proposals", proposals.size(), 2); |
1521 |
assertCorrectLabels(proposals); |
1522 |
|
1523 |
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1); |
1524 |
String preview= proposal.getCompilationUnitChange().getPreviewContent(); |
1525 |
|
1526 |
buf= new StringBuffer(); |
1527 |
buf.append("package test1;\n"); |
1528 |
buf.append("public class E {\n"); |
1529 |
buf.append(" public void foo() {\n"); |
1530 |
buf.append(" boolean b= equals(null);\n"); |
1531 |
buf.append(" }\n"); |
1532 |
buf.append("}\n"); |
1533 |
assertEqualString(preview, buf.toString()); |
1534 |
} |
1535 |
|
1536 |
public void testChangeSameToEquals3() throws Exception { |
1537 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1538 |
StringBuffer buf= new StringBuffer(); |
1539 |
buf.append("package test1;\n"); |
1540 |
buf.append("public class E {\n"); |
1541 |
buf.append(" public void foo() {\n"); |
1542 |
buf.append(" boolean b= 1 == 2;\n"); |
1543 |
buf.append(" }\n"); |
1544 |
buf.append("}\n"); |
1545 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1546 |
|
1547 |
String str= "=="; |
1548 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1549 |
List proposals= collectAssists(context, false); |
1550 |
|
1551 |
assertNumberOf("proposals", proposals.size(), 1); |
1552 |
assertCorrectLabels(proposals); |
1553 |
} |
1554 |
|
1555 |
public void testChangeSameToEquals4() throws Exception { |
1556 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1557 |
StringBuffer buf= new StringBuffer(); |
1558 |
buf.append("package test1;\n"); |
1559 |
buf.append("public class E {\n"); |
1560 |
buf.append(" public void foo() {\n"); |
1561 |
buf.append(" boolean b= null == \"a\";\n"); |
1562 |
buf.append(" }\n"); |
1563 |
buf.append("}\n"); |
1564 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1565 |
|
1566 |
String str= "=="; |
1567 |
AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); |
1568 |
List proposals= collectAssists(context, false); |
1569 |
|
1570 |
assertNumberOf("proposals", proposals.size(), 1); |
1571 |
assertCorrectLabels(proposals); |
1572 |
} |
1336 |
} |
1573 |
} |