Lines 1304-1309
public class AssistQuickFixTest18 extends QuickFixTest {
Link Here
|
1304 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1304 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1305 |
} |
1305 |
} |
1306 |
|
1306 |
|
|
|
1307 |
public void testConvertToAnonymousClassCreation8() throws Exception { |
1308 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1309 |
StringBuffer buf= new StringBuffer(); |
1310 |
buf.append("package test1;\n"); |
1311 |
buf.append("import java.util.function.IntSupplier;\n"); |
1312 |
buf.append("public class C {\n"); |
1313 |
buf.append(" C() {\n"); |
1314 |
buf.append(" IntSupplier i = () -> this.m();\n"); |
1315 |
buf.append(" }\n"); |
1316 |
buf.append("\n"); |
1317 |
buf.append(" public int m() {\n"); |
1318 |
buf.append(" return 7;\n"); |
1319 |
buf.append(" }\n"); |
1320 |
buf.append("}\n"); |
1321 |
|
1322 |
ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); |
1323 |
|
1324 |
int offset= buf.toString().indexOf("->"); |
1325 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1326 |
assertNoErrors(context); |
1327 |
List proposals= collectAssists(context, false); |
1328 |
|
1329 |
assertNumberOfProposals(proposals, 4); |
1330 |
assertCorrectLabels(proposals); |
1331 |
|
1332 |
buf= new StringBuffer(); |
1333 |
buf.append("package test1;\n"); |
1334 |
buf.append("import java.util.function.IntSupplier;\n"); |
1335 |
buf.append("public class C {\n"); |
1336 |
buf.append(" C() {\n"); |
1337 |
buf.append(" IntSupplier i = new IntSupplier() {\n"); |
1338 |
buf.append(" @Override\n"); |
1339 |
buf.append(" public int getAsInt() {\n"); |
1340 |
buf.append(" return C.this.m();\n"); |
1341 |
buf.append(" }\n"); |
1342 |
buf.append(" };\n"); |
1343 |
buf.append(" }\n"); |
1344 |
buf.append("\n"); |
1345 |
buf.append(" public int m() {\n"); |
1346 |
buf.append(" return 7;\n"); |
1347 |
buf.append(" }\n"); |
1348 |
buf.append("}\n"); |
1349 |
|
1350 |
|
1351 |
String expected1= buf.toString(); |
1352 |
|
1353 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1354 |
} |
1355 |
|
1356 |
public void testConvertToAnonymousClassCreation9() throws Exception { |
1357 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1358 |
StringBuffer buf= new StringBuffer(); |
1359 |
buf.append("package test1;\n"); |
1360 |
buf.append("import java.util.function.IntSupplier;\n"); |
1361 |
buf.append("public class C {\n"); |
1362 |
buf.append(" int varA;\n"); |
1363 |
buf.append(" C() {\n"); |
1364 |
buf.append(" IntSupplier i = () -> this.varA;\n"); |
1365 |
buf.append(" }\n"); |
1366 |
buf.append("\n"); |
1367 |
buf.append(" public int m() {\n"); |
1368 |
buf.append(" return 7;\n"); |
1369 |
buf.append(" }\n"); |
1370 |
buf.append("}\n"); |
1371 |
|
1372 |
ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); |
1373 |
|
1374 |
int offset= buf.toString().indexOf("->"); |
1375 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1376 |
assertNoErrors(context); |
1377 |
List proposals= collectAssists(context, false); |
1378 |
|
1379 |
assertNumberOfProposals(proposals, 4); |
1380 |
assertCorrectLabels(proposals); |
1381 |
|
1382 |
buf= new StringBuffer(); |
1383 |
buf.append("package test1;\n"); |
1384 |
buf.append("import java.util.function.IntSupplier;\n"); |
1385 |
buf.append("public class C {\n"); |
1386 |
buf.append(" int varA;\n"); |
1387 |
buf.append(" C() {\n"); |
1388 |
buf.append(" IntSupplier i = new IntSupplier() {\n"); |
1389 |
buf.append(" @Override\n"); |
1390 |
buf.append(" public int getAsInt() {\n"); |
1391 |
buf.append(" return C.this.varA;\n"); |
1392 |
buf.append(" }\n"); |
1393 |
buf.append(" };\n"); |
1394 |
buf.append(" }\n"); |
1395 |
buf.append("\n"); |
1396 |
buf.append(" public int m() {\n"); |
1397 |
buf.append(" return 7;\n"); |
1398 |
buf.append(" }\n"); |
1399 |
buf.append("}\n"); |
1400 |
|
1401 |
|
1402 |
String expected1= buf.toString(); |
1403 |
|
1404 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1405 |
} |
1406 |
|
1407 |
public void testConvertToAnonymousClassCreation10() throws Exception { |
1408 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1409 |
StringBuffer buf= new StringBuffer(); |
1410 |
buf.append("package test1;\n"); |
1411 |
buf.append("import java.util.function.IntSupplier;\n"); |
1412 |
buf.append("public class B extends C {\n"); |
1413 |
buf.append(" int var;\n"); |
1414 |
buf.append(" B() {\n"); |
1415 |
buf.append(" IntSupplier i = () -> {\n"); |
1416 |
buf.append(" System.out.println(this.var);\n"); |
1417 |
buf.append(" System.out.println(this.varC);\n"); |
1418 |
buf.append(" super.o();\n"); |
1419 |
buf.append(" return this.n();\n"); |
1420 |
buf.append(" };\n"); |
1421 |
buf.append(" }\n"); |
1422 |
buf.append("\n"); |
1423 |
buf.append(" public int n() {\n"); |
1424 |
buf.append(" return 7;\n"); |
1425 |
buf.append(" }\n"); |
1426 |
buf.append("}\n"); |
1427 |
buf.append("\n"); |
1428 |
buf.append("class C {\n"); |
1429 |
buf.append(" int varC;\n"); |
1430 |
buf.append(" public void o() {}\n"); |
1431 |
buf.append("}\n"); |
1432 |
|
1433 |
ICompilationUnit cu= pack1.createCompilationUnit("B.java", buf.toString(), false, null); |
1434 |
|
1435 |
int offset= buf.toString().indexOf("->"); |
1436 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1437 |
assertNoErrors(context); |
1438 |
List proposals= collectAssists(context, false); |
1439 |
|
1440 |
assertNumberOfProposals(proposals, 3); |
1441 |
assertCorrectLabels(proposals); |
1442 |
|
1443 |
buf= new StringBuffer(); |
1444 |
buf.append("package test1;\n"); |
1445 |
buf.append("import java.util.function.IntSupplier;\n"); |
1446 |
buf.append("public class B extends C {\n"); |
1447 |
buf.append(" int var;\n"); |
1448 |
buf.append(" B() {\n"); |
1449 |
buf.append(" IntSupplier i = new IntSupplier() {\n"); |
1450 |
buf.append(" @Override\n"); |
1451 |
buf.append(" public int getAsInt() {\n"); |
1452 |
buf.append(" System.out.println(B.this.var);\n"); |
1453 |
buf.append(" System.out.println(B.this.varC);\n"); |
1454 |
buf.append(" B.super.o();\n"); |
1455 |
buf.append(" return B.this.n();\n"); |
1456 |
buf.append(" }\n"); |
1457 |
buf.append(" };\n"); |
1458 |
buf.append(" }\n"); |
1459 |
buf.append("\n"); |
1460 |
buf.append(" public int n() {\n"); |
1461 |
buf.append(" return 7;\n"); |
1462 |
buf.append(" }\n"); |
1463 |
buf.append("}\n"); |
1464 |
buf.append("\n"); |
1465 |
buf.append("class C {\n"); |
1466 |
buf.append(" int varC;\n"); |
1467 |
buf.append(" public void o() {}\n"); |
1468 |
buf.append("}\n"); |
1469 |
|
1470 |
|
1471 |
String expected1= buf.toString(); |
1472 |
|
1473 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1474 |
} |
1475 |
|
1476 |
public void testConvertToAnonymousClassCreation11() throws Exception { |
1477 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1478 |
StringBuffer buf= new StringBuffer(); |
1479 |
buf.append("package test1;\n"); |
1480 |
buf.append("import java.util.function.IntSupplier;\n"); |
1481 |
buf.append("public class D {\n"); |
1482 |
buf.append(" D() {\n"); |
1483 |
buf.append(" Runnable r = new Runnable() {\n"); |
1484 |
buf.append(" int x= 10;\n"); |
1485 |
buf.append(" @Override\n"); |
1486 |
buf.append(" public void run() {\n"); |
1487 |
buf.append(" IntSupplier i = () -> this.x;\n"); |
1488 |
buf.append(" }\n"); |
1489 |
buf.append(" };\n"); |
1490 |
buf.append(" }\n"); |
1491 |
buf.append("}\n"); |
1492 |
|
1493 |
ICompilationUnit cu= pack1.createCompilationUnit("D.java", buf.toString(), false, null); |
1494 |
|
1495 |
int offset= buf.toString().indexOf("->"); |
1496 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1497 |
assertNoErrors(context); |
1498 |
List proposals= collectAssists(context, false); |
1499 |
|
1500 |
assertNumberOfProposals(proposals, 4); |
1501 |
assertCorrectLabels(proposals); |
1502 |
|
1503 |
buf= new StringBuffer(); |
1504 |
buf.append("package test1;\n"); |
1505 |
buf.append("import java.util.function.IntSupplier;\n"); |
1506 |
buf.append("public class D {\n"); |
1507 |
buf.append(" D() {\n"); |
1508 |
buf.append(" Runnable r = new Runnable() {\n"); |
1509 |
buf.append(" int x= 10;\n"); |
1510 |
buf.append(" @Override\n"); |
1511 |
buf.append(" public void run() {\n"); |
1512 |
buf.append(" IntSupplier i = new IntSupplier() {\n"); |
1513 |
buf.append(" @Override\n"); |
1514 |
buf.append(" public int getAsInt() {\n"); |
1515 |
buf.append(" return x;\n"); |
1516 |
buf.append(" }\n"); |
1517 |
buf.append(" };\n"); |
1518 |
buf.append(" }\n"); |
1519 |
buf.append(" };\n"); |
1520 |
buf.append(" }\n"); |
1521 |
|
1522 |
|
1523 |
String expected1= buf.toString(); |
1524 |
|
1525 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1526 |
} |
1527 |
|
1528 |
public void testConvertToAnonymousClassCreation12() throws Exception { |
1529 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1530 |
StringBuffer buf= new StringBuffer(); |
1531 |
buf.append("package test1;\n"); |
1532 |
buf.append("import java.util.function.IntSupplier;\n"); |
1533 |
buf.append("public class D {\n"); |
1534 |
buf.append(" D() {\n"); |
1535 |
buf.append(" Runnable r = new Runnable() {\n"); |
1536 |
buf.append(" @Override\n"); |
1537 |
buf.append(" public void run() {\n"); |
1538 |
buf.append(" IntSupplier i = () -> D.this.n();\n"); |
1539 |
buf.append(" }\n"); |
1540 |
buf.append(" };\n"); |
1541 |
buf.append(" }\n"); |
1542 |
buf.append("\n"); |
1543 |
buf.append(" public int n() {\n"); |
1544 |
buf.append(" return 7;\n"); |
1545 |
buf.append(" }\n"); |
1546 |
buf.append("}\n"); |
1547 |
|
1548 |
ICompilationUnit cu= pack1.createCompilationUnit("D.java", buf.toString(), false, null); |
1549 |
|
1550 |
int offset= buf.toString().indexOf("->"); |
1551 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1552 |
assertNoErrors(context); |
1553 |
List proposals= collectAssists(context, false); |
1554 |
|
1555 |
assertNumberOfProposals(proposals, 4); |
1556 |
assertCorrectLabels(proposals); |
1557 |
|
1558 |
buf= new StringBuffer(); |
1559 |
buf.append("package test1;\n"); |
1560 |
buf.append("import java.util.function.IntSupplier;\n"); |
1561 |
buf.append("public class D {\n"); |
1562 |
buf.append(" D() {\n"); |
1563 |
buf.append(" Runnable r = new Runnable() {\n"); |
1564 |
buf.append(" @Override\n"); |
1565 |
buf.append(" public void run() {\n"); |
1566 |
buf.append(" IntSupplier i = new IntSupplier() {\n"); |
1567 |
buf.append(" @Override\n"); |
1568 |
buf.append(" public int getAsInt() {\n"); |
1569 |
buf.append(" return D.this.n();\n"); |
1570 |
buf.append(" }\n"); |
1571 |
buf.append(" };\n"); |
1572 |
buf.append(" }\n"); |
1573 |
buf.append(" };\n"); |
1574 |
buf.append(" }\n"); |
1575 |
buf.append("\n"); |
1576 |
buf.append(" public int n() {\n"); |
1577 |
buf.append(" return 7;\n"); |
1578 |
buf.append(" }\n"); |
1579 |
buf.append("}\n"); |
1580 |
|
1581 |
|
1582 |
String expected1= buf.toString(); |
1583 |
|
1584 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1585 |
} |
1586 |
|
1307 |
public void testConvertToAnonymousClassCreationWithParameterName() throws Exception { |
1587 |
public void testConvertToAnonymousClassCreationWithParameterName() throws Exception { |
1308 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1588 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1309 |
StringBuffer buf= new StringBuffer(); |
1589 |
StringBuffer buf= new StringBuffer(); |