Lines 1290-1293
Link Here
|
1290 |
assertCorrectLabels(proposals); |
1290 |
assertCorrectLabels(proposals); |
1291 |
assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_expression); |
1291 |
assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_expression); |
1292 |
} |
1292 |
} |
1293 |
} |
1293 |
|
|
|
1294 |
public void testBug426967Comment2() throws Exception { |
1295 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1296 |
StringBuffer buf= new StringBuffer(); |
1297 |
buf.append("package test1;\n"); |
1298 |
buf.append("\n"); |
1299 |
buf.append("class E {\n"); |
1300 |
buf.append(" private void foo() {\n"); |
1301 |
buf.append(" for (String str : new String[1]) {\n"); |
1302 |
buf.append(" }\n"); |
1303 |
buf.append(" }\n"); |
1304 |
buf.append("}\n"); |
1305 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
1306 |
|
1307 |
int offset= buf.toString().indexOf("str"); |
1308 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1309 |
assertNoErrors(context); |
1310 |
List proposals= collectAssists(context, false); |
1311 |
buf= new StringBuffer(); |
1312 |
buf.append("package test1;\n"); |
1313 |
buf.append("\n"); |
1314 |
buf.append("class E {\n"); |
1315 |
buf.append(" private void foo() {\n"); |
1316 |
buf.append(" String[] strings = new String[1];\n"); |
1317 |
buf.append(" for (int i = 0; i < strings.length; i++) {\n"); |
1318 |
buf.append(" String str = strings[i];\n"); |
1319 |
buf.append(" }\n"); |
1320 |
buf.append(" }\n"); |
1321 |
buf.append("}\n"); |
1322 |
assertNumberOfProposals(proposals, 1); |
1323 |
assertCorrectLabels(proposals); |
1324 |
|
1325 |
String expected1= buf.toString(); |
1326 |
|
1327 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1328 |
} |
1329 |
|
1330 |
public void testTypeAnnotations1() throws Exception { |
1331 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1332 |
StringBuffer buf= new StringBuffer(); |
1333 |
buf.append("package test1;\n"); |
1334 |
buf.append("\n"); |
1335 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1336 |
buf.append("import java.lang.annotation.Target;\n"); |
1337 |
buf.append("\n"); |
1338 |
buf.append("public class C1 {\n"); |
1339 |
buf.append(" private void foo() {\n"); |
1340 |
buf.append(" for(@ReadOnly String s11= \"a\";;) ;\n"); |
1341 |
buf.append(" }\n"); |
1342 |
buf.append("}\n"); |
1343 |
buf.append("\n"); |
1344 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1345 |
buf.append("@interface ReadOnly {\n"); |
1346 |
buf.append("}\n"); |
1347 |
ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null); |
1348 |
|
1349 |
int offset= buf.toString().indexOf("s11"); |
1350 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1351 |
assertNoErrors(context); |
1352 |
List proposals= collectAssists(context, false); |
1353 |
buf= new StringBuffer(); |
1354 |
buf.append("package test1;\n"); |
1355 |
buf.append("\n"); |
1356 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1357 |
buf.append("import java.lang.annotation.Target;\n"); |
1358 |
buf.append("\n"); |
1359 |
buf.append("public class C1 {\n"); |
1360 |
buf.append(" private void foo() {\n"); |
1361 |
buf.append(" @ReadOnly String s11;\n"); |
1362 |
buf.append(" for(s11 = \"a\";;) ;\n"); |
1363 |
buf.append(" }\n"); |
1364 |
buf.append("}\n"); |
1365 |
buf.append("\n"); |
1366 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1367 |
buf.append("@interface ReadOnly {\n"); |
1368 |
buf.append("}\n"); |
1369 |
assertNumberOfProposals(proposals, 1); |
1370 |
assertCorrectLabels(proposals); |
1371 |
|
1372 |
String expected1= buf.toString(); |
1373 |
|
1374 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1375 |
} |
1376 |
|
1377 |
public void testTypeAnnotations2() throws Exception { |
1378 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1379 |
StringBuffer buf1= new StringBuffer(); |
1380 |
buf1.append("package test1;\n"); |
1381 |
buf1.append("\n"); |
1382 |
buf1.append("import java.lang.annotation.ElementType;\n"); |
1383 |
buf1.append("import java.lang.annotation.Target;\n"); |
1384 |
buf1.append("\n"); |
1385 |
buf1.append("public class C1 {\n"); |
1386 |
buf1.append(" private void foo() {\n"); |
1387 |
buf1.append(" try {\n"); |
1388 |
buf1.append(" if (true)\n"); |
1389 |
buf1.append(" throw new CloneNotSupportedException();\n"); |
1390 |
buf1.append(" else\n"); |
1391 |
buf1.append(" throw new ClassNotFoundException();\n"); |
1392 |
buf1.append(" } catch (@TA1 CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n"); |
1393 |
buf1.append(" }\n"); |
1394 |
buf1.append(" }\n"); |
1395 |
buf1.append("}\n"); |
1396 |
buf1.append("\n"); |
1397 |
buf1.append("@Target(ElementType.TYPE_USE)\n"); |
1398 |
buf1.append("@interface TA1 {}\n"); |
1399 |
buf1.append("\n"); |
1400 |
buf1.append("@Target(ElementType.TYPE_USE)\n"); |
1401 |
buf1.append("@interface TA2 {}\n"); |
1402 |
ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf1.toString(), false, null); |
1403 |
|
1404 |
int offset= buf1.toString().indexOf("CloneNotSupportedException |"); |
1405 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1406 |
assertNoErrors(context); |
1407 |
List proposals= collectAssists(context, false); |
1408 |
assertNumberOfProposals(proposals, 4); |
1409 |
assertCorrectLabels(proposals); |
1410 |
|
1411 |
StringBuffer buf= new StringBuffer(); |
1412 |
buf.append("package test1;\n"); |
1413 |
buf.append("\n"); |
1414 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1415 |
buf.append("import java.lang.annotation.Target;\n"); |
1416 |
buf.append("\n"); |
1417 |
buf.append("public class C1 {\n"); |
1418 |
buf.append(" private void foo() {\n"); |
1419 |
buf.append(" try {\n"); |
1420 |
buf.append(" if (true)\n"); |
1421 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1422 |
buf.append(" else\n"); |
1423 |
buf.append(" throw new ClassNotFoundException();\n"); |
1424 |
buf.append(" } catch (@TA2 ClassNotFoundException e) {\n"); |
1425 |
buf.append(" }\n"); |
1426 |
buf.append(" }\n"); |
1427 |
buf.append("}\n"); |
1428 |
buf.append("\n"); |
1429 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1430 |
buf.append("@interface TA1 {}\n"); |
1431 |
buf.append("\n"); |
1432 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1433 |
buf.append("@interface TA2 {}\n"); |
1434 |
String expected1= buf.toString(); |
1435 |
|
1436 |
buf= new StringBuffer(); |
1437 |
buf.append("package test1;\n"); |
1438 |
buf.append("\n"); |
1439 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1440 |
buf.append("import java.lang.annotation.Target;\n"); |
1441 |
buf.append("\n"); |
1442 |
buf.append("public class C1 {\n"); |
1443 |
buf.append(" private void foo() throws @TA1 CloneNotSupportedException {\n"); |
1444 |
buf.append(" try {\n"); |
1445 |
buf.append(" if (true)\n"); |
1446 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1447 |
buf.append(" else\n"); |
1448 |
buf.append(" throw new ClassNotFoundException();\n"); |
1449 |
buf.append(" } catch (@TA2 ClassNotFoundException e) {\n"); |
1450 |
buf.append(" }\n"); |
1451 |
buf.append(" }\n"); |
1452 |
buf.append("}\n"); |
1453 |
buf.append("\n"); |
1454 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1455 |
buf.append("@interface TA1 {}\n"); |
1456 |
buf.append("\n"); |
1457 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1458 |
buf.append("@interface TA2 {}\n"); |
1459 |
String expected2= buf.toString(); |
1460 |
|
1461 |
buf= new StringBuffer(); |
1462 |
buf.append("package test1;\n"); |
1463 |
buf.append("\n"); |
1464 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1465 |
buf.append("import java.lang.annotation.Target;\n"); |
1466 |
buf.append("\n"); |
1467 |
buf.append("public class C1 {\n"); |
1468 |
buf.append(" private void foo() {\n"); |
1469 |
buf.append(" try {\n"); |
1470 |
buf.append(" if (true)\n"); |
1471 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1472 |
buf.append(" else\n"); |
1473 |
buf.append(" throw new ClassNotFoundException();\n"); |
1474 |
buf.append(" } catch (@TA2 ClassNotFoundException e) {\n"); |
1475 |
buf.append(" } catch (@TA1 CloneNotSupportedException e) {\n"); |
1476 |
buf.append(" }\n"); |
1477 |
buf.append(" }\n"); |
1478 |
buf.append("}\n"); |
1479 |
buf.append("\n"); |
1480 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1481 |
buf.append("@interface TA1 {}\n"); |
1482 |
buf.append("\n"); |
1483 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1484 |
buf.append("@interface TA2 {}\n"); |
1485 |
String expected3= buf.toString(); |
1486 |
|
1487 |
assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 }); |
1488 |
|
1489 |
offset= buf1.toString().indexOf("@TA1 CloneNotSupportedException |"); |
1490 |
context= getCorrectionContext(cu, offset, 0); |
1491 |
assertNoErrors(context); |
1492 |
proposals= collectAssists(context, false); |
1493 |
assertNumberOfProposals(proposals, 4); |
1494 |
assertCorrectLabels(proposals); |
1495 |
|
1496 |
buf= new StringBuffer(); |
1497 |
buf.append("package test1;\n"); |
1498 |
buf.append("\n"); |
1499 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1500 |
buf.append("import java.lang.annotation.Target;\n"); |
1501 |
buf.append("\n"); |
1502 |
buf.append("public class C1 {\n"); |
1503 |
buf.append(" private void foo() throws @TA1 CloneNotSupportedException, @TA2 ClassNotFoundException {\n"); |
1504 |
buf.append(" if (true)\n"); |
1505 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1506 |
buf.append(" else\n"); |
1507 |
buf.append(" throw new ClassNotFoundException();\n"); |
1508 |
buf.append(" }\n"); |
1509 |
buf.append("}\n"); |
1510 |
buf.append("\n"); |
1511 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1512 |
buf.append("@interface TA1 {}\n"); |
1513 |
buf.append("\n"); |
1514 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1515 |
buf.append("@interface TA2 {}\n"); |
1516 |
String expected4= buf.toString(); |
1517 |
|
1518 |
assertExpectedExistInProposals(proposals, new String[] { expected4 }); |
1519 |
} |
1520 |
|
1521 |
public void testTypeAnnotations3() throws Exception { |
1522 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1523 |
StringBuffer buf= new StringBuffer(); |
1524 |
buf.append("package test1;\n"); |
1525 |
buf.append("\n"); |
1526 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1527 |
buf.append("import java.lang.annotation.Target;\n"); |
1528 |
buf.append("\n"); |
1529 |
buf.append("public class C1 {\n"); |
1530 |
buf.append(" private void foo() {\n"); |
1531 |
buf.append(" try {\n"); |
1532 |
buf.append(" if (true)\n"); |
1533 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1534 |
buf.append(" else\n"); |
1535 |
buf.append(" throw new ClassNotFoundException();\n"); |
1536 |
buf.append(" } catch (@TA1 CloneNotSupportedException e) {\n"); |
1537 |
buf.append(" } catch (@TA2 ClassNotFoundException e) {\n"); |
1538 |
buf.append(" }\n"); |
1539 |
buf.append(" }\n"); |
1540 |
buf.append("}\n"); |
1541 |
buf.append("\n"); |
1542 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1543 |
buf.append("@interface TA1 {}\n"); |
1544 |
buf.append("\n"); |
1545 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1546 |
buf.append("@interface TA2 {}\n"); |
1547 |
ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null); |
1548 |
|
1549 |
int offset= buf.toString().indexOf("catch"); |
1550 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1551 |
assertNoErrors(context); |
1552 |
List proposals= collectAssists(context, false); |
1553 |
buf= new StringBuffer(); |
1554 |
buf.append("package test1;\n"); |
1555 |
buf.append("\n"); |
1556 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1557 |
buf.append("import java.lang.annotation.Target;\n"); |
1558 |
buf.append("\n"); |
1559 |
buf.append("public class C1 {\n"); |
1560 |
buf.append(" private void foo() {\n"); |
1561 |
buf.append(" try {\n"); |
1562 |
buf.append(" if (true)\n"); |
1563 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1564 |
buf.append(" else\n"); |
1565 |
buf.append(" throw new ClassNotFoundException();\n"); |
1566 |
buf.append(" } catch (@TA1 CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n"); |
1567 |
buf.append(" }\n"); |
1568 |
buf.append(" }\n"); |
1569 |
buf.append("}\n"); |
1570 |
buf.append("\n"); |
1571 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1572 |
buf.append("@interface TA1 {}\n"); |
1573 |
buf.append("\n"); |
1574 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1575 |
buf.append("@interface TA2 {}\n"); |
1576 |
assertNumberOfProposals(proposals, 4); |
1577 |
assertCorrectLabels(proposals); |
1578 |
|
1579 |
String expected1= buf.toString(); |
1580 |
|
1581 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1582 |
} |
1583 |
|
1584 |
public void testTypeAnnotations4() throws Exception { |
1585 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1586 |
StringBuffer buf= new StringBuffer(); |
1587 |
buf.append("package test1;\n"); |
1588 |
buf.append("\n"); |
1589 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1590 |
buf.append("import java.lang.annotation.Target;\n"); |
1591 |
buf.append("\n"); |
1592 |
buf.append("public class C1 {\n"); |
1593 |
buf.append(" private void foo() {\n"); |
1594 |
buf.append(" try {\n"); |
1595 |
buf.append(" if (true)\n"); |
1596 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1597 |
buf.append(" else\n"); |
1598 |
buf.append(" throw new ClassNotFoundException();\n"); |
1599 |
buf.append(" } catch (@TA1 CloneNotSupportedException e) {\n"); |
1600 |
buf.append(" } catch (@TA1 ClassCastException | @TA2 ClassNotFoundException e) {\n"); |
1601 |
buf.append(" }\n"); |
1602 |
buf.append(" }\n"); |
1603 |
buf.append("}\n"); |
1604 |
buf.append("\n"); |
1605 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1606 |
buf.append("@interface TA1 {}\n"); |
1607 |
buf.append("\n"); |
1608 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1609 |
buf.append("@interface TA2 {}\n"); |
1610 |
ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null); |
1611 |
|
1612 |
int offset= buf.toString().indexOf("catch"); |
1613 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1614 |
assertNoErrors(context); |
1615 |
List proposals= collectAssists(context, false); |
1616 |
buf= new StringBuffer(); |
1617 |
buf.append("package test1;\n"); |
1618 |
buf.append("\n"); |
1619 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1620 |
buf.append("import java.lang.annotation.Target;\n"); |
1621 |
buf.append("\n"); |
1622 |
buf.append("public class C1 {\n"); |
1623 |
buf.append(" private void foo() {\n"); |
1624 |
buf.append(" try {\n"); |
1625 |
buf.append(" if (true)\n"); |
1626 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1627 |
buf.append(" else\n"); |
1628 |
buf.append(" throw new ClassNotFoundException();\n"); |
1629 |
buf.append(" } catch (@TA1 CloneNotSupportedException | @TA1 ClassCastException | @TA2 ClassNotFoundException e) {\n"); |
1630 |
buf.append(" }\n"); |
1631 |
buf.append(" }\n"); |
1632 |
buf.append("}\n"); |
1633 |
buf.append("\n"); |
1634 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1635 |
buf.append("@interface TA1 {}\n"); |
1636 |
buf.append("\n"); |
1637 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1638 |
buf.append("@interface TA2 {}\n"); |
1639 |
assertNumberOfProposals(proposals, 4); |
1640 |
assertCorrectLabels(proposals); |
1641 |
|
1642 |
String expected1= buf.toString(); |
1643 |
|
1644 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1645 |
} |
1646 |
|
1647 |
public void testTypeAnnotations5() throws Exception { |
1648 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1649 |
StringBuffer buf= new StringBuffer(); |
1650 |
buf.append("package test1;\n"); |
1651 |
buf.append("\n"); |
1652 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1653 |
buf.append("import java.lang.annotation.Target;\n"); |
1654 |
buf.append("\n"); |
1655 |
buf.append("public class C1 {\n"); |
1656 |
buf.append(" private void foo() {\n"); |
1657 |
buf.append(" try {\n"); |
1658 |
buf.append(" if (true)\n"); |
1659 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1660 |
buf.append(" else\n"); |
1661 |
buf.append(" throw new ClassNotFoundException();\n"); |
1662 |
buf.append(" } catch (@TA1 CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n"); |
1663 |
buf.append(" }\n"); |
1664 |
buf.append(" }\n"); |
1665 |
buf.append("}\n"); |
1666 |
buf.append("\n"); |
1667 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1668 |
buf.append("@interface TA1 {}\n"); |
1669 |
buf.append("\n"); |
1670 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1671 |
buf.append("@interface TA2 {}\n"); |
1672 |
ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null); |
1673 |
|
1674 |
int offset= buf.toString().indexOf("catch"); |
1675 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1676 |
assertNoErrors(context); |
1677 |
List proposals= collectAssists(context, false); |
1678 |
buf= new StringBuffer(); |
1679 |
buf.append("package test1;\n"); |
1680 |
buf.append("\n"); |
1681 |
buf.append("import java.lang.annotation.ElementType;\n"); |
1682 |
buf.append("import java.lang.annotation.Target;\n"); |
1683 |
buf.append("\n"); |
1684 |
buf.append("public class C1 {\n"); |
1685 |
buf.append(" private void foo() {\n"); |
1686 |
buf.append(" try {\n"); |
1687 |
buf.append(" if (true)\n"); |
1688 |
buf.append(" throw new CloneNotSupportedException();\n"); |
1689 |
buf.append(" else\n"); |
1690 |
buf.append(" throw new ClassNotFoundException();\n"); |
1691 |
buf.append(" } catch (@TA1 CloneNotSupportedException e) {\n"); |
1692 |
buf.append(" } catch (@TA2 ClassNotFoundException e) {\n"); |
1693 |
buf.append(" }\n"); |
1694 |
buf.append(" }\n"); |
1695 |
buf.append("}\n"); |
1696 |
buf.append("\n"); |
1697 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1698 |
buf.append("@interface TA1 {}\n"); |
1699 |
buf.append("\n"); |
1700 |
buf.append("@Target(ElementType.TYPE_USE)\n"); |
1701 |
buf.append("@interface TA2 {}\n"); |
1702 |
assertNumberOfProposals(proposals, 4); |
1703 |
assertCorrectLabels(proposals); |
1704 |
|
1705 |
String expected1= buf.toString(); |
1706 |
|
1707 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1708 |
} |
1709 |
|
1710 |
} |