|
1 | 1 | /*
|
2 |
| - * Copyright 2009-2019 the original author or authors. |
| 2 | + * Copyright 2009-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 |
|
18 | 18 | import static org.junit.Assert.assertEquals;
|
19 | 19 | import static org.junit.Assert.assertFalse;
|
20 |
| -import static org.junit.Assert.assertNotNull; |
21 | 20 | import static org.junit.Assert.assertTrue;
|
22 | 21 |
|
23 |
| -import java.util.List; |
24 | 22 | import java.util.Map;
|
25 | 23 |
|
26 |
| -import org.codehaus.groovy.ast.ClassNode; |
27 |
| -import org.codehaus.groovy.ast.ImportNode; |
28 |
| -import org.codehaus.groovy.ast.ModuleNode; |
29 | 24 | import org.codehaus.jdt.groovy.internal.compiler.ast.AliasImportReference;
|
30 | 25 | import org.eclipse.jdt.internal.compiler.ast.ImportReference;
|
31 | 26 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
|
@@ -1371,348 +1366,4 @@ public void testAmbiguous_GRE945_ji() {
|
1371 | 1366 |
|
1372 | 1367 | runConformTest(sources, "abc");
|
1373 | 1368 | }
|
1374 |
| - |
1375 |
| - @Test |
1376 |
| - public void testParsingBlankPackage() { |
1377 |
| - //@formatter:off |
1378 |
| - String[] sources = { |
1379 |
| - "Foo.groovy", |
1380 |
| - "package \n" + |
1381 |
| - "class Name { }\n", |
1382 |
| - }; |
1383 |
| - //@formatter:on |
1384 |
| - |
1385 |
| - runNegativeTest(sources, "----------\n" + |
1386 |
| - "1. ERROR in Foo.groovy (at line 1)\n" + |
1387 |
| - "\tpackage \n" + |
1388 |
| - "\t^\n" + |
1389 |
| - "Groovy:Invalid package specification\n" + |
1390 |
| - "----------\n"); |
1391 |
| - } |
1392 |
| - |
1393 |
| - @Test |
1394 |
| - public void testParsingBlankPackage2() { |
1395 |
| - //@formatter:off |
1396 |
| - String[] sources = { |
1397 |
| - "Foo.groovy", |
1398 |
| - "package ;\n" + |
1399 |
| - "class Name { }\n", |
1400 |
| - }; |
1401 |
| - //@formatter:on |
1402 |
| - |
1403 |
| - runNegativeTest(sources, "----------\n" + |
1404 |
| - "1. ERROR in Foo.groovy (at line 1)\n" + |
1405 |
| - "\tpackage ;\n" + |
1406 |
| - "\t^\n" + |
1407 |
| - "Groovy:Invalid package specification\n" + |
1408 |
| - "----------\n"); |
1409 |
| - } |
1410 |
| - |
1411 |
| - @Test // does the second error now get reported after the package problem |
1412 |
| - public void testParsingBlankPackage3() { |
1413 |
| - //@formatter:off |
1414 |
| - String[] sources = { |
1415 |
| - "Foo.groovy", |
1416 |
| - "package ;\n" + |
1417 |
| - "class Name { \n" + |
1418 |
| - " asdf\n" + |
1419 |
| - "}\n", |
1420 |
| - }; |
1421 |
| - //@formatter:on |
1422 |
| - |
1423 |
| - runNegativeTest(sources, "----------\n" + |
1424 |
| - "1. ERROR in Foo.groovy (at line 1)\n" + |
1425 |
| - "\tpackage ;\n" + |
1426 |
| - "\t^\n" + |
1427 |
| - "Groovy:Invalid package specification\n" + |
1428 |
| - "----------\n" + |
1429 |
| - "2. ERROR in Foo.groovy (at line 3)\n" + |
1430 |
| - "\tasdf\n" + |
1431 |
| - "\t^\n" + |
1432 |
| - "Groovy:unexpected token: asdf\n" + |
1433 |
| - "----------\n"); |
1434 |
| - } |
1435 |
| - |
1436 |
| - @Test |
1437 |
| - public void testParsingBlankImport_538() { |
1438 |
| - //@formatter:off |
1439 |
| - String[] sources = { |
1440 |
| - "A.groovy", |
1441 |
| - "import ", |
1442 |
| - }; |
1443 |
| - //@formatter:on |
1444 |
| - |
1445 |
| - runNegativeTest(sources, "----------\n" + |
1446 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1447 |
| - "\timport \n" + |
1448 |
| - "\t^^^^^^^\n" + |
1449 |
| - "Groovy:unable to resolve class ?\n" + |
1450 |
| - "----------\n"); |
1451 |
| - |
1452 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1453 |
| - assertNotNull(mn); |
1454 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1455 |
| - |
1456 |
| - List<ImportNode> imports = mn.getImports(); |
1457 |
| - ImportNode recoveredImport = imports.get(0); |
1458 |
| - assertEquals(0, recoveredImport.getStart()); |
1459 |
| - assertEquals(7, recoveredImport.getEnd()); |
1460 |
| - assertEquals("?", recoveredImport.getType().getName()); |
1461 |
| - |
1462 |
| - ClassNode cn = mn.getClasses().get(0); |
1463 |
| - assertNotNull(cn); |
1464 |
| - assertTrue(cn.getName().equals("A")); |
1465 |
| - } |
1466 |
| - |
1467 |
| - @Test |
1468 |
| - public void testParsingBlankImport2_538() { |
1469 |
| - //@formatter:off |
1470 |
| - String[] sources = { |
1471 |
| - "A.groovy", |
1472 |
| - "import ;", |
1473 |
| - }; |
1474 |
| - //@formatter:on |
1475 |
| - |
1476 |
| - runNegativeTest(sources, "----------\n" + |
1477 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1478 |
| - "\timport ;\n" + |
1479 |
| - "\t^^^^^^^\n" + |
1480 |
| - "Groovy:unable to resolve class ?\n" + |
1481 |
| - "----------\n"); |
1482 |
| - |
1483 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1484 |
| - assertNotNull(mn); |
1485 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1486 |
| - |
1487 |
| - List<ImportNode> imports = mn.getImports(); |
1488 |
| - ImportNode recoveredImport = imports.get(0); |
1489 |
| - assertEquals(0, recoveredImport.getStart()); |
1490 |
| - assertEquals(7, recoveredImport.getEnd()); |
1491 |
| - assertEquals("?", recoveredImport.getType().getName()); |
1492 |
| - |
1493 |
| - ClassNode cn = mn.getClasses().get(0); |
1494 |
| - assertNotNull(cn); |
1495 |
| - assertTrue(cn.getName().equals("A")); |
1496 |
| - } |
1497 |
| - |
1498 |
| - @Test |
1499 |
| - public void testParsingDotTerminatedImport_538() { |
1500 |
| - //@formatter:off |
1501 |
| - String[] sources = { |
1502 |
| - "A.groovy", |
1503 |
| - "import foo.", |
1504 |
| - }; |
1505 |
| - //@formatter:on |
1506 |
| - |
1507 |
| - runNegativeTest(sources, "----------\n" + |
1508 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1509 |
| - "\timport foo.\n" + |
1510 |
| - "\t ^\n" + |
1511 |
| - "Groovy:Invalid import\n" + |
1512 |
| - "----------\n"); |
1513 |
| - |
1514 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1515 |
| - assertNotNull(mn); |
1516 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1517 |
| - |
1518 |
| - List<ImportNode> imports = mn.getStarImports(); |
1519 |
| - ImportNode recoveredImport = imports.get(0); |
1520 |
| - assertEquals("foo.", recoveredImport.getPackageName()); |
1521 |
| - |
1522 |
| - ClassNode cn = mn.getClasses().get(0); |
1523 |
| - assertNotNull(cn); |
1524 |
| - assertTrue(cn.getName().equals("A")); |
1525 |
| - } |
1526 |
| - |
1527 |
| - @Test |
1528 |
| - public void testParsingBlankImportStatic_538() { |
1529 |
| - //@formatter:off |
1530 |
| - String[] sources = { |
1531 |
| - "A.groovy", |
1532 |
| - "import static \n", |
1533 |
| - }; |
1534 |
| - //@formatter:on |
1535 |
| - |
1536 |
| - runNegativeTest(sources, "----------\n" + |
1537 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1538 |
| - "\timport static \n" + |
1539 |
| - "\t^^^^^^^^^^^^^^\n" + |
1540 |
| - "Groovy:unable to resolve class ?\n" + |
1541 |
| - "----------\n"); |
1542 |
| - |
1543 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1544 |
| - assertNotNull(mn); |
1545 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1546 |
| - |
1547 |
| - List<ImportNode> imports = mn.getImports(); |
1548 |
| - ImportNode recoveredImport = imports.get(0); |
1549 |
| - assertEquals(0, recoveredImport.getStart()); |
1550 |
| - assertEquals(14, recoveredImport.getEnd()); |
1551 |
| - assertEquals("?", recoveredImport.getType().getName()); |
1552 |
| - assertTrue(mn.getStaticImports().isEmpty()); |
1553 |
| - |
1554 |
| - ClassNode cn = mn.getClasses().get(0); |
1555 |
| - assertNotNull(cn); |
1556 |
| - assertTrue(cn.getName().equals("A")); |
1557 |
| - } |
1558 |
| - |
1559 |
| - @Test |
1560 |
| - public void testParsingBlankImportStatic2_538() { |
1561 |
| - //@formatter:off |
1562 |
| - String[] sources = { |
1563 |
| - "A.groovy", |
1564 |
| - "import static ;\n", |
1565 |
| - }; |
1566 |
| - //@formatter:on |
1567 |
| - |
1568 |
| - runNegativeTest(sources, "----------\n" + |
1569 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1570 |
| - "\timport static ;\n" + |
1571 |
| - "\t^^^^^^^^^^^^^^\n" + |
1572 |
| - "Groovy:unable to resolve class ?\n" + |
1573 |
| - "----------\n"); |
1574 |
| - |
1575 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1576 |
| - assertNotNull(mn); |
1577 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1578 |
| - |
1579 |
| - List<ImportNode> imports = mn.getImports(); |
1580 |
| - ImportNode recoveredImport = imports.get(0); |
1581 |
| - assertEquals(0, recoveredImport.getStart()); |
1582 |
| - assertEquals(14, recoveredImport.getEnd()); |
1583 |
| - assertEquals("?", recoveredImport.getType().getName()); |
1584 |
| - assertTrue(mn.getStaticImports().isEmpty()); |
1585 |
| - |
1586 |
| - ClassNode cn = mn.getClasses().get(0); |
1587 |
| - assertNotNull(cn); |
1588 |
| - assertTrue(cn.getName().equals("A")); |
1589 |
| - } |
1590 |
| - |
1591 |
| - @Test |
1592 |
| - public void testParsingDotTerminatedImportStatic_538() { |
1593 |
| - //@formatter:off |
1594 |
| - String[] sources = { |
1595 |
| - "A.groovy", |
1596 |
| - "import static foo.Bar.", |
1597 |
| - }; |
1598 |
| - //@formatter:on |
1599 |
| - |
1600 |
| - runNegativeTest(sources, |
1601 |
| - "----------\n" + |
1602 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1603 |
| - "\timport static foo.Bar.\n" + |
1604 |
| - "\t ^\n" + |
1605 |
| - "Groovy:Invalid import\n" + |
1606 |
| - "----------\n" + |
1607 |
| - "2. ERROR in A.groovy (at line 1)\n" + |
1608 |
| - "\timport static foo.Bar.\n" + |
1609 |
| - "\t ^^^^^^^\n" + |
1610 |
| - "Groovy:unable to resolve class foo.Bar\n" + |
1611 |
| - "----------\n"); |
1612 |
| - |
1613 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1614 |
| - assertNotNull(mn); |
1615 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1616 |
| - |
1617 |
| - Map<String, ImportNode> imports = mn.getStaticStarImports(); |
1618 |
| - ImportNode recoveredImport = imports.get("foo.Bar"); |
1619 |
| - assertEquals("foo.Bar", recoveredImport.getType().getName()); |
1620 |
| - |
1621 |
| - ClassNode cn = mn.getClasses().get(0); |
1622 |
| - assertNotNull(cn); |
1623 |
| - assertEquals("A", cn.getName()); |
1624 |
| - } |
1625 |
| - |
1626 |
| - @Test |
1627 |
| - public void testParsingDotTerminatedImportFollowedByClassDeclaration_538() { |
1628 |
| - //@formatter:off |
1629 |
| - String[] sources = { |
1630 |
| - "A.groovy", |
1631 |
| - "import foo.\n" + |
1632 |
| - "\n" + |
1633 |
| - "class Wibble {}\n", |
1634 |
| - }; |
1635 |
| - //@formatter:on |
1636 |
| - |
1637 |
| - runNegativeTest(sources, "----------\n" + |
1638 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1639 |
| - "\timport foo.\n" + |
1640 |
| - "\t ^\n" + |
1641 |
| - "Groovy:Invalid import\n" + |
1642 |
| - "----------\n"); |
1643 |
| - |
1644 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1645 |
| - assertNotNull(mn); |
1646 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1647 |
| - |
1648 |
| - List<ImportNode> imports = mn.getStarImports(); |
1649 |
| - ImportNode recoveredImport = imports.get(0); |
1650 |
| - assertEquals("foo.", recoveredImport.getPackageName()); |
1651 |
| - |
1652 |
| - ClassNode cn = mn.getClasses().get(0); |
1653 |
| - assertNotNull(cn); |
1654 |
| - assertEquals("Wibble", cn.getName()); |
1655 |
| - } |
1656 |
| - |
1657 |
| - @Test |
1658 |
| - public void testParsingDotTerminatedImportFollowedByModifierAndClassDeclaration_538() { |
1659 |
| - //@formatter:off |
1660 |
| - String[] sources = { |
1661 |
| - "A.groovy", |
1662 |
| - "import foo.\n" + |
1663 |
| - "\n" + |
1664 |
| - "public class Wibble {}\n", |
1665 |
| - }; |
1666 |
| - //@formatter:on |
1667 |
| - |
1668 |
| - runNegativeTest(sources, "----------\n" + |
1669 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1670 |
| - "\timport foo.\n" + |
1671 |
| - "\t ^\n" + |
1672 |
| - "Groovy:Invalid import\n" + |
1673 |
| - "----------\n"); |
1674 |
| - |
1675 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1676 |
| - assertNotNull(mn); |
1677 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1678 |
| - |
1679 |
| - List<ImportNode> imports = mn.getStarImports(); |
1680 |
| - ImportNode recoveredImport = imports.get(0); |
1681 |
| - assertEquals("foo.", recoveredImport.getPackageName()); |
1682 |
| - |
1683 |
| - ClassNode cn = mn.getClasses().get(0); |
1684 |
| - assertNotNull(cn); |
1685 |
| - assertEquals("Wibble", cn.getName()); |
1686 |
| - } |
1687 |
| - |
1688 |
| - @Test |
1689 |
| - public void testParsingBlankImportFollowedByClassDeclaration_538() { |
1690 |
| - //@formatter:off |
1691 |
| - String[] sources = { |
1692 |
| - "A.groovy", |
1693 |
| - "import\n" + |
1694 |
| - "\n" + |
1695 |
| - "public class Wibble {}\n", |
1696 |
| - }; |
1697 |
| - //@formatter:on |
1698 |
| - |
1699 |
| - runNegativeTest(sources, "----------\n" + |
1700 |
| - "1. ERROR in A.groovy (at line 1)\n" + |
1701 |
| - "\timport\n" + |
1702 |
| - "\t^^^^^^\n" + |
1703 |
| - "Groovy:unable to resolve class ?\n" + |
1704 |
| - "----------\n"); |
1705 |
| - |
1706 |
| - ModuleNode mn = getModuleNode("A.groovy"); |
1707 |
| - assertNotNull(mn); |
1708 |
| - assertFalse(mn.encounteredUnrecoverableError()); |
1709 |
| - |
1710 |
| - List<ImportNode> imports = mn.getImports(); |
1711 |
| - ImportNode recoveredImport = imports.get(0); |
1712 |
| - assertEquals("?", recoveredImport.getType().getName()); |
1713 |
| - |
1714 |
| - ClassNode cn = mn.getClasses().get(0); |
1715 |
| - assertNotNull(cn); |
1716 |
| - assertEquals("Wibble", cn.getName()); |
1717 |
| - } |
1718 | 1369 | }
|
0 commit comments