Lines 334-340
Link Here
|
334 |
"\n" + |
334 |
"\n" + |
335 |
"public class X02 {\n" + |
335 |
"public class X02 {\n" + |
336 |
"}\n"; |
336 |
"}\n"; |
337 |
formatSource(source); |
337 |
formatSource(source, |
|
|
338 |
"import java.util.List;\n" + |
339 |
"import java.util.Set;\n" + |
340 |
"\n" + |
341 |
"//import java.util.HashMap;\n" + |
342 |
"\n" + |
343 |
"public class X02 {\n" + |
344 |
"}\n" |
345 |
); |
338 |
} |
346 |
} |
339 |
public void testBug199265c1() throws JavaModelException { |
347 |
public void testBug199265c1() throws JavaModelException { |
340 |
String source = |
348 |
String source = |
Lines 379-384
Link Here
|
379 |
"}\n"; |
387 |
"}\n"; |
380 |
formatSource(source); |
388 |
formatSource(source); |
381 |
} |
389 |
} |
|
|
390 |
public void testBug199265d1() throws JavaModelException { |
391 |
String source = |
392 |
"import java.util.Set; // trailing comment\n" + |
393 |
"// line comment\n" + |
394 |
"import java.util.Map; // trailing comment\n" + |
395 |
"// line comment\n" + |
396 |
"public class X04 {\n" + |
397 |
"\n" + |
398 |
"}\n"; |
399 |
formatSource(source, |
400 |
"import java.util.Set; // trailing comment\n" + |
401 |
"// line comment\n" + |
402 |
"import java.util.Map; // trailing comment\n" + |
403 |
"// line comment\n" + |
404 |
"\n" + |
405 |
"public class X04 {\n" + |
406 |
"\n" + |
407 |
"}\n" |
408 |
); |
409 |
} |
410 |
public void testBug199265d2() throws JavaModelException { |
411 |
String source = |
412 |
"import java.util.Set; // trailing comment\n" + |
413 |
"// line comment\n" + |
414 |
"import java.util.Map; // trailing comment\n" + |
415 |
"// line comment\n" + |
416 |
"\n" + |
417 |
"public class X04 {\n" + |
418 |
"\n" + |
419 |
"}\n"; |
420 |
formatSource(source); |
421 |
} |
422 |
public void testBug199265d3() throws JavaModelException { |
423 |
String source = |
424 |
"import java.util.Set; // trailing comment\n" + |
425 |
" // line comment\n" + |
426 |
"import java.util.Map; // trailing comment\n" + |
427 |
" // line comment\n" + |
428 |
"public class X04 {\n" + |
429 |
"\n" + |
430 |
"}\n"; |
431 |
formatSource(source, |
432 |
"import java.util.Set; // trailing comment\n" + |
433 |
"// line comment\n" + |
434 |
"import java.util.Map; // trailing comment\n" + |
435 |
"// line comment\n" + |
436 |
"\n" + |
437 |
"public class X04 {\n" + |
438 |
"\n" + |
439 |
"}\n" |
440 |
); |
441 |
} |
382 |
public void testBug199265_wksp1a() throws JavaModelException { |
442 |
public void testBug199265_wksp1a() throws JavaModelException { |
383 |
String source = |
443 |
String source = |
384 |
"package wksp1;\n" + |
444 |
"package wksp1;\n" + |
Lines 837-843
Link Here
|
837 |
String source = |
897 |
String source = |
838 |
"package massive;\n" + |
898 |
"package massive;\n" + |
839 |
"\n" + |
899 |
"\n" + |
840 |
"public class X05b\n" + |
900 |
"public class X05\n" + |
841 |
"{\n" + |
901 |
"{\n" + |
842 |
"\n" + |
902 |
"\n" + |
843 |
" public void foo() throws NullPointerException {\n" + |
903 |
" public void foo() throws NullPointerException {\n" + |
Lines 859-865
Link Here
|
859 |
formatSource(source, |
919 |
formatSource(source, |
860 |
"package massive;\n" + |
920 |
"package massive;\n" + |
861 |
"\n" + |
921 |
"\n" + |
862 |
"public class X05b {\n" + |
922 |
"public class X05 {\n" + |
863 |
"\n" + |
923 |
"\n" + |
864 |
" public void foo() throws NullPointerException {\n" + |
924 |
" public void foo() throws NullPointerException {\n" + |
865 |
"\n" + |
925 |
"\n" + |
Lines 888-894
Link Here
|
888 |
String source = |
948 |
String source = |
889 |
"package massive;\n" + |
949 |
"package massive;\n" + |
890 |
"\n" + |
950 |
"\n" + |
891 |
"public class X05b\n" + |
951 |
"public class X05\n" + |
892 |
"{\n" + |
952 |
"{\n" + |
893 |
"\n" + |
953 |
"\n" + |
894 |
" public void foo() throws NullPointerException {\n" + |
954 |
" public void foo() throws NullPointerException {\n" + |
Lines 910-916
Link Here
|
910 |
formatSource(source, |
970 |
formatSource(source, |
911 |
"package massive;\n" + |
971 |
"package massive;\n" + |
912 |
"\n" + |
972 |
"\n" + |
913 |
"public class X05b\n" + |
973 |
"public class X05\n" + |
914 |
"{\n" + |
974 |
"{\n" + |
915 |
"\n" + |
975 |
"\n" + |
916 |
" public void foo() throws NullPointerException\n" + |
976 |
" public void foo() throws NullPointerException\n" + |
Lines 1555-1560
Link Here
|
1555 |
} |
1615 |
} |
1556 |
|
1616 |
|
1557 |
/** |
1617 |
/** |
|
|
1618 |
* @bug 293300: [formatter] The formatter is still unstable in certain circumstances |
1619 |
* @test Verify that formatting twice a compilation unit does not produce different output |
1620 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300" |
1621 |
*/ |
1622 |
public void testBug293300_wksp1_01() { |
1623 |
String source = |
1624 |
"package wksp1;\n" + |
1625 |
"\n" + |
1626 |
"public class X01 {\n" + |
1627 |
"\n" + |
1628 |
" boolean foo(int test, int value) {\n" + |
1629 |
" // This comment may also be impacted after having been split in several lines. Furthermore, it\'s also important to verify that the algorithm works when the comment is split into several lines. It\'s a common use case that it may works for 1, 2 but not for 3 iterations...\n" + |
1630 |
" if (test == 0) {\n" + |
1631 |
" // skip\n" + |
1632 |
" } else if (Math.sqrt(Math.pow(test, 2)) > 10) // This is the offending comment after having been split into several lines\n" + |
1633 |
" return false;\n" + |
1634 |
" return true;\n" + |
1635 |
" }\n" + |
1636 |
"}\n"; |
1637 |
formatSource(source, |
1638 |
"package wksp1;\n" + |
1639 |
"\n" + |
1640 |
"public class X01 {\n" + |
1641 |
"\n" + |
1642 |
" boolean foo(int test, int value) {\n" + |
1643 |
" // This comment may also be impacted after having been split in several\n" + |
1644 |
" // lines. Furthermore, it\'s also important to verify that the algorithm\n" + |
1645 |
" // works when the comment is split into several lines. It\'s a common use\n" + |
1646 |
" // case that it may works for 1, 2 but not for 3 iterations...\n" + |
1647 |
" if (test == 0) {\n" + |
1648 |
" // skip\n" + |
1649 |
" } else if (Math.sqrt(Math.pow(test, 2)) > 10) // This is the offending\n" + |
1650 |
" // comment after having\n" + |
1651 |
" // been split into\n" + |
1652 |
" // several lines\n" + |
1653 |
" return false;\n" + |
1654 |
" return true;\n" + |
1655 |
" }\n" + |
1656 |
"}\n" |
1657 |
); |
1658 |
} |
1659 |
public void testBug293300_wkps1_02() { |
1660 |
String source = |
1661 |
"package wksp1;\n" + |
1662 |
"\n" + |
1663 |
"public class X02 {\n" + |
1664 |
" String field;\n" + |
1665 |
" public X02(String test) {\n" + |
1666 |
" field= test.toLowerCase();\n" + |
1667 |
" try {\n" + |
1668 |
" testWhetherItWorksOrNot(test); // This comment will be split and should not involve instability\n" + |
1669 |
" } catch (Exception e) {\n" + |
1670 |
" return;\n" + |
1671 |
" }\n" + |
1672 |
" }\n" + |
1673 |
" private void testWhetherItWorksOrNot(String test) {\n" + |
1674 |
" }\n" + |
1675 |
"}\n"; |
1676 |
formatSource(source, |
1677 |
"package wksp1;\n" + |
1678 |
"\n" + |
1679 |
"public class X02 {\n" + |
1680 |
" String field;\n" + |
1681 |
"\n" + |
1682 |
" public X02(String test) {\n" + |
1683 |
" field = test.toLowerCase();\n" + |
1684 |
" try {\n" + |
1685 |
" testWhetherItWorksOrNot(test); // This comment will be split and\n" + |
1686 |
" // should not involve instability\n" + |
1687 |
" } catch (Exception e) {\n" + |
1688 |
" return;\n" + |
1689 |
" }\n" + |
1690 |
" }\n" + |
1691 |
"\n" + |
1692 |
" private void testWhetherItWorksOrNot(String test) {\n" + |
1693 |
" }\n" + |
1694 |
"}\n" |
1695 |
); |
1696 |
} |
1697 |
public void testBug293300_wkps1_03() { |
1698 |
String source = |
1699 |
"package wksp1;\n" + |
1700 |
"\n" + |
1701 |
"public class X03 {\n" + |
1702 |
"public static final native int foo(\n" + |
1703 |
" int firstParameter,\n" + |
1704 |
" int secondParameter,\n" + |
1705 |
" int[] param3); //When a long comment is placed here with at least one line to follow,\n" + |
1706 |
" // the second line may be difficult to be formatted correctly\n" + |
1707 |
"public static final native int bar();\n" + |
1708 |
"\n" + |
1709 |
"}\n"; |
1710 |
formatSource(source, |
1711 |
"package wksp1;\n" + |
1712 |
"\n" + |
1713 |
"public class X03 {\n" + |
1714 |
" public static final native int foo(int firstParameter, int secondParameter,\n" + |
1715 |
" int[] param3); // When a long comment is placed here with at least\n" + |
1716 |
" // one line to follow,\n" + |
1717 |
" // the second line may be difficult to be formatted\n" + |
1718 |
" // correctly\n" + |
1719 |
"\n" + |
1720 |
" public static final native int bar();\n" + |
1721 |
"\n" + |
1722 |
"}\n" |
1723 |
); |
1724 |
} |
1725 |
public void testBug293300_wkps1_04() { |
1726 |
String source = |
1727 |
"package wksp1;\n" + |
1728 |
"\n" + |
1729 |
"interface Y04_____________________________ {\n" + |
1730 |
"}\n" + |
1731 |
"\n" + |
1732 |
"public interface X04 extends Y04_____________________________ { // modifier constant\n" + |
1733 |
" // those constants are depending upon ClassFileConstants (relying that classfiles only use the 16 lower bits)\n" + |
1734 |
" final int AccDefault = 0;\n" + |
1735 |
"}\n"; |
1736 |
formatSource(source, |
1737 |
"package wksp1;\n" + |
1738 |
"\n" + |
1739 |
"interface Y04_____________________________ {\n" + |
1740 |
"}\n" + |
1741 |
"\n" + |
1742 |
"public interface X04 extends Y04_____________________________ { // modifier\n" + |
1743 |
" // constant\n" + |
1744 |
" // those constants are depending upon ClassFileConstants (relying that\n" + |
1745 |
" // classfiles only use the 16 lower bits)\n" + |
1746 |
" final int AccDefault = 0;\n" + |
1747 |
"}\n" |
1748 |
); |
1749 |
} |
1750 |
public void testBug293300_wksp2_01() { |
1751 |
String source = |
1752 |
"package wksp2;\n" + |
1753 |
"\n" + |
1754 |
"public class X01 {\n" + |
1755 |
"\n" + |
1756 |
" protected String foo(String[] tests) {\n" + |
1757 |
" String result = null;\n" + |
1758 |
" for (int i = 0; i < tests.length; i++) {\n" + |
1759 |
" String test = tests[i];\n" + |
1760 |
" if (test.startsWith(\"test\")) { //$NON-NLS-1$\n" + |
1761 |
" //we got the malformed tree exception here\n" + |
1762 |
" result = test;\n" + |
1763 |
" }\n" + |
1764 |
" }\n" + |
1765 |
" return result;\n" + |
1766 |
" }\n" + |
1767 |
"\n" + |
1768 |
"}\n"; |
1769 |
formatSource(source, |
1770 |
"package wksp2;\n" + |
1771 |
"\n" + |
1772 |
"public class X01 {\n" + |
1773 |
"\n" + |
1774 |
" protected String foo(String[] tests) {\n" + |
1775 |
" String result = null;\n" + |
1776 |
" for (int i = 0; i < tests.length; i++) {\n" + |
1777 |
" String test = tests[i];\n" + |
1778 |
" if (test.startsWith(\"test\")) { //$NON-NLS-1$\n" + |
1779 |
" // we got the malformed tree exception here\n" + |
1780 |
" result = test;\n" + |
1781 |
" }\n" + |
1782 |
" }\n" + |
1783 |
" return result;\n" + |
1784 |
" }\n" + |
1785 |
"\n" + |
1786 |
"}\n" |
1787 |
); |
1788 |
} |
1789 |
public void testBug293300_wksp2_02() { |
1790 |
String source = |
1791 |
"package wksp2;\n" + |
1792 |
"\n" + |
1793 |
"public class X02 {\n" + |
1794 |
"\n" + |
1795 |
"\n" + |
1796 |
" public void foo(int kind) {\n" + |
1797 |
" switch (kind) {\n" + |
1798 |
" case 0 :\n" + |
1799 |
" break;\n" + |
1800 |
" case 1 :\n" + |
1801 |
" //the first formatting looks strange on this already splitted\n" + |
1802 |
" // comment\n" + |
1803 |
" if (true)\n" + |
1804 |
" return;\n" + |
1805 |
" //fall through\n" + |
1806 |
" default:\n" + |
1807 |
" if (kind < 0)\n" + |
1808 |
" return;\n" + |
1809 |
" break;\n" + |
1810 |
" }\n" + |
1811 |
" }\n" + |
1812 |
"\n" + |
1813 |
"}\n"; |
1814 |
formatSource(source, |
1815 |
"package wksp2;\n" + |
1816 |
"\n" + |
1817 |
"public class X02 {\n" + |
1818 |
"\n" + |
1819 |
" public void foo(int kind) {\n" + |
1820 |
" switch (kind) {\n" + |
1821 |
" case 0:\n" + |
1822 |
" break;\n" + |
1823 |
" case 1:\n" + |
1824 |
" // the first formatting looks strange on this already splitted\n" + |
1825 |
" // comment\n" + |
1826 |
" if (true)\n" + |
1827 |
" return;\n" + |
1828 |
" // fall through\n" + |
1829 |
" default:\n" + |
1830 |
" if (kind < 0)\n" + |
1831 |
" return;\n" + |
1832 |
" break;\n" + |
1833 |
" }\n" + |
1834 |
" }\n" + |
1835 |
"\n" + |
1836 |
"}\n" |
1837 |
); |
1838 |
} |
1839 |
public void testBug293300_wksp2_03() { |
1840 |
String source = |
1841 |
"package wksp2;\n" + |
1842 |
"\n" + |
1843 |
"public class X03 {\n" + |
1844 |
" public byte[] foo(byte value) {\n" + |
1845 |
" byte[] result = new byte[10];\n" + |
1846 |
" int valTest = 0;\n" + |
1847 |
" switch (value) {\n" + |
1848 |
" case 1 :\n" + |
1849 |
" for (int j = 10; j >= 0; j--) {\n" + |
1850 |
" result[j] = (byte) (valTest & 0xff); // Bottom 8\n" + |
1851 |
" // bits\n" + |
1852 |
" valTest = valTest >>> 2;\n" + |
1853 |
" }\n" + |
1854 |
" break;\n" + |
1855 |
" }\n" + |
1856 |
" return result;\n" + |
1857 |
" }\n" + |
1858 |
"}\n"; |
1859 |
formatSource(source, |
1860 |
"package wksp2;\n" + |
1861 |
"\n" + |
1862 |
"public class X03 {\n" + |
1863 |
" public byte[] foo(byte value) {\n" + |
1864 |
" byte[] result = new byte[10];\n" + |
1865 |
" int valTest = 0;\n" + |
1866 |
" switch (value) {\n" + |
1867 |
" case 1:\n" + |
1868 |
" for (int j = 10; j >= 0; j--) {\n" + |
1869 |
" result[j] = (byte) (valTest & 0xff); // Bottom 8\n" + |
1870 |
" // bits\n" + |
1871 |
" valTest = valTest >>> 2;\n" + |
1872 |
" }\n" + |
1873 |
" break;\n" + |
1874 |
" }\n" + |
1875 |
" return result;\n" + |
1876 |
" }\n" + |
1877 |
"}\n" |
1878 |
); |
1879 |
} |
1880 |
public void testBug293300_wksp2_04() { |
1881 |
String source = |
1882 |
"package wksp2;\n" + |
1883 |
"\n" + |
1884 |
"public class X04 {\n" + |
1885 |
"\n" + |
1886 |
" void foo() {\n" + |
1887 |
" int lastDiagonal[]= new int[1000000 + 1]; // this line comments configuration\n" + |
1888 |
" // may screw up the formatter to know which one\n" + |
1889 |
" int origin= 1000000 / 2; // needs to stay at its current indentation or not\n" + |
1890 |
" }\n" + |
1891 |
"}\n"; |
1892 |
formatSource(source, |
1893 |
"package wksp2;\n" + |
1894 |
"\n" + |
1895 |
"public class X04 {\n" + |
1896 |
"\n" + |
1897 |
" void foo() {\n" + |
1898 |
" int lastDiagonal[] = new int[1000000 + 1]; // this line comments\n" + |
1899 |
" // configuration\n" + |
1900 |
" // may screw up the formatter to know which one\n" + |
1901 |
" int origin = 1000000 / 2; // needs to stay at its current indentation or\n" + |
1902 |
" // not\n" + |
1903 |
" }\n" + |
1904 |
"}\n" |
1905 |
); |
1906 |
} |
1907 |
private static final String EXPECTED_OUTPUT_WKSP2E1 = |
1908 |
"package wksp2;\n" + |
1909 |
"\n" + |
1910 |
"public class X05 {\n" + |
1911 |
" void foo(int val) {\n" + |
1912 |
" try {\n" + |
1913 |
" loop: for (int i = 0; i < 10; i++) {\n" + |
1914 |
" switch (val) {\n" + |
1915 |
" case 1:\n" + |
1916 |
" if (i == 0) {\n" + |
1917 |
" if (true) {\n" + |
1918 |
" val++;\n" + |
1919 |
" } // these comments\n" + |
1920 |
" // may be wrongly\n" + |
1921 |
" // realigned\n" + |
1922 |
" // by the formatter\n" + |
1923 |
"\n" + |
1924 |
" // other comment\n" + |
1925 |
" val--;\n" + |
1926 |
" continue loop;\n" + |
1927 |
" }\n" + |
1928 |
" default:\n" + |
1929 |
" throw new IllegalArgumentException();\n" + |
1930 |
" }\n" + |
1931 |
" }\n" + |
1932 |
" } finally {\n" + |
1933 |
" }\n" + |
1934 |
" }\n" + |
1935 |
"}\n"; |
1936 |
public void testBug293300_wksp2_05() { |
1937 |
String source = |
1938 |
"package wksp2;\n" + |
1939 |
"\n" + |
1940 |
"public class X05 {\n" + |
1941 |
" void foo(int val) {\n" + |
1942 |
" try {\n" + |
1943 |
" loop: for (int i=0; i<10; i++) {\n" + |
1944 |
" switch (val) {\n" + |
1945 |
" case 1 :\n" + |
1946 |
" if (i==0) {\n" + |
1947 |
" if (true) {\n" + |
1948 |
" val++;\n" + |
1949 |
" } //these comments\n" + |
1950 |
" // may be wrongly\n" + |
1951 |
" // realigned\n" + |
1952 |
" // by the formatter\n" + |
1953 |
"\n" + |
1954 |
" // other comment\n" + |
1955 |
" val--;\n" + |
1956 |
" continue loop;\n" + |
1957 |
" }\n" + |
1958 |
" default :\n" + |
1959 |
" throw new IllegalArgumentException();\n" + |
1960 |
" }\n" + |
1961 |
" }\n" + |
1962 |
" }\n" + |
1963 |
" finally {\n" + |
1964 |
" }\n" + |
1965 |
" }\n" + |
1966 |
"}\n"; |
1967 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E1); |
1968 |
} |
1969 |
public void testBug293300_wksp2_05b() { |
1970 |
String source = |
1971 |
"package wksp2;\n" + |
1972 |
"\n" + |
1973 |
"public class X05 {\n" + |
1974 |
" void foo(int val) {\n" + |
1975 |
" try {\n" + |
1976 |
" loop: for (int i=0; i<10; i++) {\n" + |
1977 |
" switch (val) {\n" + |
1978 |
" case 1 :\n" + |
1979 |
" if (i==0) {\n" + |
1980 |
" if (true) {\n" + |
1981 |
" val++;\n" + |
1982 |
" } //these comments\n" + |
1983 |
" // may be wrongly\n" + |
1984 |
" // realigned\n" + |
1985 |
" // by the formatter\n" + |
1986 |
"\n" + |
1987 |
" // other comment\n" + |
1988 |
" val--;\n" + |
1989 |
" continue loop;\n" + |
1990 |
" }\n" + |
1991 |
" default :\n" + |
1992 |
" throw new IllegalArgumentException();\n" + |
1993 |
" }\n" + |
1994 |
" }\n" + |
1995 |
" }\n" + |
1996 |
" finally {\n" + |
1997 |
" }\n" + |
1998 |
" }\n" + |
1999 |
"}\n"; |
2000 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E1); |
2001 |
} |
2002 |
private static final String EXPECTED_OUTPUT_WKSP2E3 = |
2003 |
"package wksp2;\n" + |
2004 |
"\n" + |
2005 |
"public class X05 {\n" + |
2006 |
" void foo(int val) {\n" + |
2007 |
" try {\n" + |
2008 |
" loop: for (int i = 0; i < 10; i++) {\n" + |
2009 |
" switch (val) {\n" + |
2010 |
" case 1:\n" + |
2011 |
" if (i == 0) {\n" + |
2012 |
" if (true) {\n" + |
2013 |
" val++;\n" + |
2014 |
" } // these comments\n" + |
2015 |
" // may be wrongly\n" + |
2016 |
" // realigned\n" + |
2017 |
" // by the formatter\n" + |
2018 |
"\n" + |
2019 |
" // other comment\n" + |
2020 |
" val--;\n" + |
2021 |
" continue loop;\n" + |
2022 |
" }\n" + |
2023 |
" default:\n" + |
2024 |
" throw new IllegalArgumentException();\n" + |
2025 |
" }\n" + |
2026 |
" }\n" + |
2027 |
" } finally {\n" + |
2028 |
" }\n" + |
2029 |
" }\n" + |
2030 |
"}\n"; |
2031 |
public void testBug293300_wksp2_05c() { |
2032 |
String source = |
2033 |
"package wksp2;\n" + |
2034 |
"\n" + |
2035 |
"public class X05 {\n" + |
2036 |
" void foo(int val) {\n" + |
2037 |
" try {\n" + |
2038 |
" loop: for (int i=0; i<10; i++) {\n" + |
2039 |
" switch (val) {\n" + |
2040 |
" case 1 :\n" + |
2041 |
" if (i==0) {\n" + |
2042 |
" if (true) {\n" + |
2043 |
" val++;\n" + |
2044 |
" } //these comments\n" + |
2045 |
" // may be wrongly\n" + |
2046 |
" // realigned\n" + |
2047 |
" // by the formatter\n" + |
2048 |
"\n" + |
2049 |
" // other comment\n" + |
2050 |
" val--;\n" + |
2051 |
" continue loop;\n" + |
2052 |
" }\n" + |
2053 |
" default :\n" + |
2054 |
" throw new IllegalArgumentException();\n" + |
2055 |
" }\n" + |
2056 |
" }\n" + |
2057 |
" }\n" + |
2058 |
" finally {\n" + |
2059 |
" }\n" + |
2060 |
" }\n" + |
2061 |
"}\n"; |
2062 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3); |
2063 |
} |
2064 |
public void testBug293300_wksp2_05d() { |
2065 |
String source = |
2066 |
"package wksp2;\n" + |
2067 |
"\n" + |
2068 |
"public class X05 {\n" + |
2069 |
" void foo(int val) {\n" + |
2070 |
" try {\n" + |
2071 |
" loop: for (int i=0; i<10; i++) {\n" + |
2072 |
" switch (val) {\n" + |
2073 |
" case 1 :\n" + |
2074 |
" if (i==0) {\n" + |
2075 |
" if (true) {\n" + |
2076 |
" val++;\n" + |
2077 |
" } //these comments\n" + |
2078 |
" // may be wrongly\n" + |
2079 |
" // realigned\n" + |
2080 |
" // by the formatter\n" + |
2081 |
"\n" + |
2082 |
" // other comment\n" + |
2083 |
" val--;\n" + |
2084 |
" continue loop;\n" + |
2085 |
" }\n" + |
2086 |
" default :\n" + |
2087 |
" throw new IllegalArgumentException();\n" + |
2088 |
" }\n" + |
2089 |
" }\n" + |
2090 |
" }\n" + |
2091 |
" finally {\n" + |
2092 |
" }\n" + |
2093 |
" }\n" + |
2094 |
"}\n"; |
2095 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3); |
2096 |
} |
2097 |
public void testBug293300_wksp2_05e() { |
2098 |
String source = |
2099 |
"package wksp2;\n" + |
2100 |
"\n" + |
2101 |
"public class X05 {\n" + |
2102 |
" void foo(int val) {\n" + |
2103 |
" try {\n" + |
2104 |
" loop: for (int i=0; i<10; i++) {\n" + |
2105 |
" switch (val) {\n" + |
2106 |
" case 1 :\n" + |
2107 |
" if (i==0) {\n" + |
2108 |
" if (true) {\n" + |
2109 |
" val++;\n" + |
2110 |
" } //these comments\n" + |
2111 |
" // may be wrongly\n" + |
2112 |
" // realigned\n" + |
2113 |
" // by the formatter\n" + |
2114 |
"\n" + |
2115 |
" // other comment\n" + |
2116 |
" val--;\n" + |
2117 |
" continue loop;\n" + |
2118 |
" }\n" + |
2119 |
" default :\n" + |
2120 |
" throw new IllegalArgumentException();\n" + |
2121 |
" }\n" + |
2122 |
" }\n" + |
2123 |
" }\n" + |
2124 |
" finally {\n" + |
2125 |
" }\n" + |
2126 |
" }\n" + |
2127 |
"}\n"; |
2128 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3); |
2129 |
} |
2130 |
private static final String EXPECTED_OUTPUT_WKSP2E1_SPACES = |
2131 |
"package wksp2;\n" + |
2132 |
"\n" + |
2133 |
"public class X05 {\n" + |
2134 |
" void foo(int val) {\n" + |
2135 |
" try {\n" + |
2136 |
" loop: for (int i = 0; i < 10; i++) {\n" + |
2137 |
" switch (val) {\n" + |
2138 |
" case 1:\n" + |
2139 |
" if (i == 0) {\n" + |
2140 |
" if (true) {\n" + |
2141 |
" val++;\n" + |
2142 |
" } // these comments\n" + |
2143 |
" // may be wrongly\n" + |
2144 |
" // realigned\n" + |
2145 |
" // by the formatter\n" + |
2146 |
"\n" + |
2147 |
" // other comment\n" + |
2148 |
" val--;\n" + |
2149 |
" continue loop;\n" + |
2150 |
" }\n" + |
2151 |
" default:\n" + |
2152 |
" throw new IllegalArgumentException();\n" + |
2153 |
" }\n" + |
2154 |
" }\n" + |
2155 |
" } finally {\n" + |
2156 |
" }\n" + |
2157 |
" }\n" + |
2158 |
"}\n"; |
2159 |
public void testBug293300_wksp2_05_spaces() { |
2160 |
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; |
2161 |
String source = |
2162 |
"package wksp2;\n" + |
2163 |
"\n" + |
2164 |
"public class X05 {\n" + |
2165 |
" void foo(int val) {\n" + |
2166 |
" try {\n" + |
2167 |
" loop: for (int i=0; i<10; i++) {\n" + |
2168 |
" switch (val) {\n" + |
2169 |
" case 1 :\n" + |
2170 |
" if (i==0) {\n" + |
2171 |
" if (true) {\n" + |
2172 |
" val++;\n" + |
2173 |
" } //these comments\n" + |
2174 |
" // may be wrongly\n" + |
2175 |
" // realigned\n" + |
2176 |
" // by the formatter\n" + |
2177 |
"\n" + |
2178 |
" // other comment\n" + |
2179 |
" val--;\n" + |
2180 |
" continue loop;\n" + |
2181 |
" }\n" + |
2182 |
" default :\n" + |
2183 |
" throw new IllegalArgumentException();\n" + |
2184 |
" }\n" + |
2185 |
" }\n" + |
2186 |
" }\n" + |
2187 |
" finally {\n" + |
2188 |
" }\n" + |
2189 |
" }\n" + |
2190 |
"}\n"; |
2191 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E1_SPACES); |
2192 |
} |
2193 |
public void testBug293300_wksp2_05b_spaces() { |
2194 |
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; |
2195 |
String source = |
2196 |
"package wksp2;\n" + |
2197 |
"\n" + |
2198 |
"public class X05 {\n" + |
2199 |
" void foo(int val) {\n" + |
2200 |
" try {\n" + |
2201 |
" loop: for (int i=0; i<10; i++) {\n" + |
2202 |
" switch (val) {\n" + |
2203 |
" case 1 :\n" + |
2204 |
" if (i==0) {\n" + |
2205 |
" if (true) {\n" + |
2206 |
" val++;\n" + |
2207 |
" } //these comments\n" + |
2208 |
" // may be wrongly\n" + |
2209 |
" // realigned\n" + |
2210 |
" // by the formatter\n" + |
2211 |
"\n" + |
2212 |
" // other comment\n" + |
2213 |
" val--;\n" + |
2214 |
" continue loop;\n" + |
2215 |
" }\n" + |
2216 |
" default :\n" + |
2217 |
" throw new IllegalArgumentException();\n" + |
2218 |
" }\n" + |
2219 |
" }\n" + |
2220 |
" }\n" + |
2221 |
" finally {\n" + |
2222 |
" }\n" + |
2223 |
" }\n" + |
2224 |
"}\n"; |
2225 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E1_SPACES); |
2226 |
} |
2227 |
private static final String EXPECTED_OUTPUT_WKSP2E3_SPACES = |
2228 |
"package wksp2;\n" + |
2229 |
"\n" + |
2230 |
"public class X05 {\n" + |
2231 |
" void foo(int val) {\n" + |
2232 |
" try {\n" + |
2233 |
" loop: for (int i = 0; i < 10; i++) {\n" + |
2234 |
" switch (val) {\n" + |
2235 |
" case 1:\n" + |
2236 |
" if (i == 0) {\n" + |
2237 |
" if (true) {\n" + |
2238 |
" val++;\n" + |
2239 |
" } // these comments\n" + |
2240 |
" // may be wrongly\n" + |
2241 |
" // realigned\n" + |
2242 |
" // by the formatter\n" + |
2243 |
"\n" + |
2244 |
" // other comment\n" + |
2245 |
" val--;\n" + |
2246 |
" continue loop;\n" + |
2247 |
" }\n" + |
2248 |
" default:\n" + |
2249 |
" throw new IllegalArgumentException();\n" + |
2250 |
" }\n" + |
2251 |
" }\n" + |
2252 |
" } finally {\n" + |
2253 |
" }\n" + |
2254 |
" }\n" + |
2255 |
"}\n"; |
2256 |
public void testBug293300_wksp2_05c_spaces() { |
2257 |
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; |
2258 |
String source = |
2259 |
"package wksp2;\n" + |
2260 |
"\n" + |
2261 |
"public class X05 {\n" + |
2262 |
" void foo(int val) {\n" + |
2263 |
" try {\n" + |
2264 |
" loop: for (int i=0; i<10; i++) {\n" + |
2265 |
" switch (val) {\n" + |
2266 |
" case 1 :\n" + |
2267 |
" if (i==0) {\n" + |
2268 |
" if (true) {\n" + |
2269 |
" val++;\n" + |
2270 |
" } //these comments\n" + |
2271 |
" // may be wrongly\n" + |
2272 |
" // realigned\n" + |
2273 |
" // by the formatter\n" + |
2274 |
"\n" + |
2275 |
" // other comment\n" + |
2276 |
" val--;\n" + |
2277 |
" continue loop;\n" + |
2278 |
" }\n" + |
2279 |
" default :\n" + |
2280 |
" throw new IllegalArgumentException();\n" + |
2281 |
" }\n" + |
2282 |
" }\n" + |
2283 |
" }\n" + |
2284 |
" finally {\n" + |
2285 |
" }\n" + |
2286 |
" }\n" + |
2287 |
"}\n"; |
2288 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); |
2289 |
} |
2290 |
public void testBug293300_wksp2_05d_spaces() { |
2291 |
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; |
2292 |
String source = |
2293 |
"package wksp2;\n" + |
2294 |
"\n" + |
2295 |
"public class X05 {\n" + |
2296 |
" void foo(int val) {\n" + |
2297 |
" try {\n" + |
2298 |
" loop: for (int i=0; i<10; i++) {\n" + |
2299 |
" switch (val) {\n" + |
2300 |
" case 1 :\n" + |
2301 |
" if (i==0) {\n" + |
2302 |
" if (true) {\n" + |
2303 |
" val++;\n" + |
2304 |
" } //these comments\n" + |
2305 |
" // may be wrongly\n" + |
2306 |
" // realigned\n" + |
2307 |
" // by the formatter\n" + |
2308 |
"\n" + |
2309 |
" // other comment\n" + |
2310 |
" val--;\n" + |
2311 |
" continue loop;\n" + |
2312 |
" }\n" + |
2313 |
" default :\n" + |
2314 |
" throw new IllegalArgumentException();\n" + |
2315 |
" }\n" + |
2316 |
" }\n" + |
2317 |
" }\n" + |
2318 |
" finally {\n" + |
2319 |
" }\n" + |
2320 |
" }\n" + |
2321 |
"}\n"; |
2322 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); |
2323 |
} |
2324 |
public void testBug293300_wksp2_05e_spaces() { |
2325 |
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; |
2326 |
String source = |
2327 |
"package wksp2;\n" + |
2328 |
"\n" + |
2329 |
"public class X05 {\n" + |
2330 |
" void foo(int val) {\n" + |
2331 |
" try {\n" + |
2332 |
" loop: for (int i=0; i<10; i++) {\n" + |
2333 |
" switch (val) {\n" + |
2334 |
" case 1 :\n" + |
2335 |
" if (i==0) {\n" + |
2336 |
" if (true) {\n" + |
2337 |
" val++;\n" + |
2338 |
" } //these comments\n" + |
2339 |
" // may be wrongly\n" + |
2340 |
" // realigned\n" + |
2341 |
" // by the formatter\n" + |
2342 |
"\n" + |
2343 |
" // other comment\n" + |
2344 |
" val--;\n" + |
2345 |
" continue loop;\n" + |
2346 |
" }\n" + |
2347 |
" default :\n" + |
2348 |
" throw new IllegalArgumentException();\n" + |
2349 |
" }\n" + |
2350 |
" }\n" + |
2351 |
" }\n" + |
2352 |
" finally {\n" + |
2353 |
" }\n" + |
2354 |
" }\n" + |
2355 |
"}\n"; |
2356 |
formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); |
2357 |
} |
2358 |
public void testBug293300_wksp_06() { |
2359 |
String source = |
2360 |
"package wksp2;\n" + |
2361 |
"\n" + |
2362 |
"public class X06 {\n" + |
2363 |
"public static final native int foo(\n" + |
2364 |
" String field, //First field\n" + |
2365 |
" int[] array); //This comment may cause trouble for the formatter, especially if there\'s another\n" + |
2366 |
" // line below \n" + |
2367 |
"public static final native int bar();\n" + |
2368 |
"}\n"; |
2369 |
formatSource(source, |
2370 |
"package wksp2;\n" + |
2371 |
"\n" + |
2372 |
"public class X06 {\n" + |
2373 |
" public static final native int foo(String field, // First field\n" + |
2374 |
" int[] array); // This comment may cause trouble for the formatter,\n" + |
2375 |
" // especially if there\'s another\n" + |
2376 |
" // line below\n" + |
2377 |
"\n" + |
2378 |
" public static final native int bar();\n" + |
2379 |
"}\n" |
2380 |
); |
2381 |
} |
2382 |
public void testBug293300_wksp_07() { |
2383 |
String source = |
2384 |
"package wksp2;\n" + |
2385 |
"\n" + |
2386 |
"public class X07 {\n" + |
2387 |
" void foo(boolean test) {\n" + |
2388 |
" if (test) {\n" + |
2389 |
" while (true) {\n" + |
2390 |
" try {\n" + |
2391 |
" try {\n" + |
2392 |
" } finally {\n" + |
2393 |
" if (true) {\n" + |
2394 |
" try {\n" + |
2395 |
" toString();\n" + |
2396 |
" } catch (Exception e) {\n" + |
2397 |
" } // nothing\n" + |
2398 |
" }\n" + |
2399 |
" } // first comment which does not move\n" + |
2400 |
"\n" + |
2401 |
" // second comment which should not move\n" + |
2402 |
" toString();\n" + |
2403 |
" } catch (Exception e) {\n" + |
2404 |
" }\n" + |
2405 |
"\n" + |
2406 |
" } // last comment\n" + |
2407 |
"\n" + |
2408 |
" }\n" + |
2409 |
"\n" + |
2410 |
" return;\n" + |
2411 |
" }\n" + |
2412 |
"}\n"; |
2413 |
formatSource(source); |
2414 |
} |
2415 |
public void testBug293300_wksp2_08() { |
2416 |
String source = |
2417 |
"package wksp2;\n" + |
2418 |
"\n" + |
2419 |
"public class X08 {\n" + |
2420 |
"int foo(int x) {\n" + |
2421 |
" while (x < 0) {\n" + |
2422 |
" switch (x) {\n" + |
2423 |
" \n" + |
2424 |
" }\n" + |
2425 |
" } // end while\n" + |
2426 |
"\n" + |
2427 |
" // fill in output parameter\n" + |
2428 |
" if(x > 10)\n" + |
2429 |
" x = 1;\n" + |
2430 |
"\n" + |
2431 |
" // return the value\n" + |
2432 |
" return x;\n" + |
2433 |
" }\n" + |
2434 |
"}\n"; |
2435 |
formatSource(source, |
2436 |
"package wksp2;\n" + |
2437 |
"\n" + |
2438 |
"public class X08 {\n" + |
2439 |
" int foo(int x) {\n" + |
2440 |
" while (x < 0) {\n" + |
2441 |
" switch (x) {\n" + |
2442 |
"\n" + |
2443 |
" }\n" + |
2444 |
" } // end while\n" + |
2445 |
"\n" + |
2446 |
" // fill in output parameter\n" + |
2447 |
" if (x > 10)\n" + |
2448 |
" x = 1;\n" + |
2449 |
"\n" + |
2450 |
" // return the value\n" + |
2451 |
" return x;\n" + |
2452 |
" }\n" + |
2453 |
"}\n" |
2454 |
); |
2455 |
} |
2456 |
public void testBug293300_wksp2_08b() { |
2457 |
String source = |
2458 |
"package wksp2;\n" + |
2459 |
"\n" + |
2460 |
"public class X08 {\n" + |
2461 |
"int foo(int x) {\n" + |
2462 |
" while (x < 0) {\n" + |
2463 |
" switch (x) {\n" + |
2464 |
" \n" + |
2465 |
" }\n" + |
2466 |
" } /* end while */\n" + |
2467 |
"\n" + |
2468 |
" // fill in output parameter\n" + |
2469 |
" if(x > 10)\n" + |
2470 |
" x = 1;\n" + |
2471 |
"\n" + |
2472 |
" // return the value\n" + |
2473 |
" return x;\n" + |
2474 |
" }\n" + |
2475 |
"}\n"; |
2476 |
formatSource(source, |
2477 |
"package wksp2;\n" + |
2478 |
"\n" + |
2479 |
"public class X08 {\n" + |
2480 |
" int foo(int x) {\n" + |
2481 |
" while (x < 0) {\n" + |
2482 |
" switch (x) {\n" + |
2483 |
"\n" + |
2484 |
" }\n" + |
2485 |
" } /* end while */\n" + |
2486 |
"\n" + |
2487 |
" // fill in output parameter\n" + |
2488 |
" if (x > 10)\n" + |
2489 |
" x = 1;\n" + |
2490 |
"\n" + |
2491 |
" // return the value\n" + |
2492 |
" return x;\n" + |
2493 |
" }\n" + |
2494 |
"}\n" |
2495 |
); |
2496 |
} |
2497 |
public void testBug293300_wksp2_08c() { |
2498 |
String source = |
2499 |
"package wksp2;\n" + |
2500 |
"\n" + |
2501 |
"public class X08 {\n" + |
2502 |
"int foo(int x) {\n" + |
2503 |
" while (x < 0) {\n" + |
2504 |
" switch (x) {\n" + |
2505 |
" \n" + |
2506 |
" }\n" + |
2507 |
" } /** end while */\n" + |
2508 |
"\n" + |
2509 |
" // fill in output parameter\n" + |
2510 |
" if(x > 10)\n" + |
2511 |
" x = 1;\n" + |
2512 |
"\n" + |
2513 |
" // return the value\n" + |
2514 |
" return x;\n" + |
2515 |
" }\n" + |
2516 |
"}\n"; |
2517 |
formatSource(source, |
2518 |
"package wksp2;\n" + |
2519 |
"\n" + |
2520 |
"public class X08 {\n" + |
2521 |
" int foo(int x) {\n" + |
2522 |
" while (x < 0) {\n" + |
2523 |
" switch (x) {\n" + |
2524 |
"\n" + |
2525 |
" }\n" + |
2526 |
" }\n" + |
2527 |
" /** end while */\n" + |
2528 |
"\n" + |
2529 |
" // fill in output parameter\n" + |
2530 |
" if (x > 10)\n" + |
2531 |
" x = 1;\n" + |
2532 |
"\n" + |
2533 |
" // return the value\n" + |
2534 |
" return x;\n" + |
2535 |
" }\n" + |
2536 |
"}\n" |
2537 |
); |
2538 |
} |
2539 |
public void testBug293300_wksp2_09() { |
2540 |
String source = |
2541 |
"package wksp2;\n" + |
2542 |
"\n" + |
2543 |
"public class X09 {\n" + |
2544 |
"void foo(int param) {\n" + |
2545 |
" int local = param - 10000; // first comment\n" + |
2546 |
" // on several lines\n" + |
2547 |
" // following unrelated comment\n" + |
2548 |
" // also on several lines\n" + |
2549 |
" int value = param + 10000;\n" + |
2550 |
"}\n" + |
2551 |
"}\n"; |
2552 |
formatSource(source, |
2553 |
"package wksp2;\n" + |
2554 |
"\n" + |
2555 |
"public class X09 {\n" + |
2556 |
" void foo(int param) {\n" + |
2557 |
" int local = param - 10000; // first comment\n" + |
2558 |
" // on several lines\n" + |
2559 |
" // following unrelated comment\n" + |
2560 |
" // also on several lines\n" + |
2561 |
" int value = param + 10000;\n" + |
2562 |
" }\n" + |
2563 |
"}\n" |
2564 |
); |
2565 |
} |
2566 |
public void testBug293300_wksp2_10() { |
2567 |
String source = |
2568 |
"package wksp2;\n" + |
2569 |
"\n" + |
2570 |
"public class X10 {\n" + |
2571 |
"\n" + |
2572 |
" private String field; // Trailing comment of the field\n" + |
2573 |
" // This comment was not well formatted\n" + |
2574 |
" // as an unexpected line was inserted after the first one\n" + |
2575 |
"\n" + |
2576 |
" // -------------------------------\n" + |
2577 |
" X10() {}\n" + |
2578 |
"}\n"; |
2579 |
formatSource(source, |
2580 |
"package wksp2;\n" + |
2581 |
"\n" + |
2582 |
"public class X10 {\n" + |
2583 |
"\n" + |
2584 |
" private String field; // Trailing comment of the field\n" + |
2585 |
" // This comment was not well formatted\n" + |
2586 |
" // as an unexpected line was inserted after the\n" + |
2587 |
" // first one\n" + |
2588 |
"\n" + |
2589 |
" // -------------------------------\n" + |
2590 |
" X10() {\n" + |
2591 |
" }\n" + |
2592 |
"}\n" |
2593 |
); |
2594 |
} |
2595 |
public void testBug293300_wksp2_11() { |
2596 |
String source = |
2597 |
"package wksp2;\n" + |
2598 |
"\n" + |
2599 |
"public abstract class X11 {\n" + |
2600 |
"\n" + |
2601 |
" // [NEW] \n" + |
2602 |
" /**\n" + |
2603 |
" * Comment foo\n" + |
2604 |
" */\n" + |
2605 |
" public abstract StringBuffer foo();\n" + |
2606 |
"//#if defined(TEST)\n" + |
2607 |
"//#else\n" + |
2608 |
"//#endif\n" + |
2609 |
"\n" + |
2610 |
" // [NEW]\n" + |
2611 |
" /**\n" + |
2612 |
" * Comment foo2\n" + |
2613 |
" */\n" + |
2614 |
" public abstract StringBuffer foo2();\n" + |
2615 |
" // [NEW]\n" + |
2616 |
" /**\n" + |
2617 |
" * Comment foo3\n" + |
2618 |
" */\n" + |
2619 |
" public abstract StringBuffer foo3();\n" + |
2620 |
"\n" + |
2621 |
"}\n"; |
2622 |
formatSource(source, |
2623 |
"package wksp2;\n" + |
2624 |
"\n" + |
2625 |
"public abstract class X11 {\n" + |
2626 |
"\n" + |
2627 |
" // [NEW]\n" + |
2628 |
" /**\n" + |
2629 |
" * Comment foo\n" + |
2630 |
" */\n" + |
2631 |
" public abstract StringBuffer foo();\n" + |
2632 |
"\n" + |
2633 |
" // #if defined(TEST)\n" + |
2634 |
" // #else\n" + |
2635 |
" // #endif\n" + |
2636 |
"\n" + |
2637 |
" // [NEW]\n" + |
2638 |
" /**\n" + |
2639 |
" * Comment foo2\n" + |
2640 |
" */\n" + |
2641 |
" public abstract StringBuffer foo2();\n" + |
2642 |
"\n" + |
2643 |
" // [NEW]\n" + |
2644 |
" /**\n" + |
2645 |
" * Comment foo3\n" + |
2646 |
" */\n" + |
2647 |
" public abstract StringBuffer foo3();\n" + |
2648 |
"\n" + |
2649 |
"}\n" |
2650 |
); |
2651 |
} |
2652 |
public void testBug293300_wksp2_12a() { |
2653 |
String source = |
2654 |
"package wksp2;\n" + |
2655 |
"\n" + |
2656 |
"public class X12 {\n" + |
2657 |
"\n" + |
2658 |
"\n" + |
2659 |
" private boolean sampleField = false; //trailing comment of the field which\n" + |
2660 |
" //was wrongly formatted in previous\n" + |
2661 |
" //version as an unexpected empty lines was\n" + |
2662 |
" //inserted after the second comment line...\n" + |
2663 |
"\n" + |
2664 |
"\n" + |
2665 |
" /**\n" + |
2666 |
" Javadoc comment\n" + |
2667 |
" */\n" + |
2668 |
" public X12() {}\n" + |
2669 |
"}\n"; |
2670 |
formatSource(source, |
2671 |
"package wksp2;\n" + |
2672 |
"\n" + |
2673 |
"public class X12 {\n" + |
2674 |
"\n" + |
2675 |
" private boolean sampleField = false; // trailing comment of the field which\n" + |
2676 |
" // was wrongly formatted in previous\n" + |
2677 |
" // version as an unexpected empty\n" + |
2678 |
" // lines was\n" + |
2679 |
" // inserted after the second comment\n" + |
2680 |
" // line...\n" + |
2681 |
"\n" + |
2682 |
" /**\n" + |
2683 |
" * Javadoc comment\n" + |
2684 |
" */\n" + |
2685 |
" public X12() {\n" + |
2686 |
" }\n" + |
2687 |
"}\n" |
2688 |
); |
2689 |
} |
2690 |
public void testBug293300_wksp2_12b() { |
2691 |
String source = |
2692 |
"package wksp2;\n" + |
2693 |
"\n" + |
2694 |
"public class X12 {\n" + |
2695 |
"\n" + |
2696 |
"\n" + |
2697 |
" private boolean sampleField = false; //trailing comment of the field which\n" + |
2698 |
" //was wrongly formatted in previous\n" + |
2699 |
" //version as an unexpected empty lines was\n" + |
2700 |
" //inserted after the second comment line...\n" + |
2701 |
"\n" + |
2702 |
"\n" + |
2703 |
" /**\n" + |
2704 |
" Javadoc comment\n" + |
2705 |
" */\n" + |
2706 |
" public X12() {}\n" + |
2707 |
"}\n"; |
2708 |
formatSource(source, |
2709 |
"package wksp2;\n" + |
2710 |
"\n" + |
2711 |
"public class X12 {\n" + |
2712 |
"\n" + |
2713 |
" private boolean sampleField = false; // trailing comment of the field which\n" + |
2714 |
" // was wrongly formatted in previous\n" + |
2715 |
" // version as an unexpected empty\n" + |
2716 |
" // lines was\n" + |
2717 |
" // inserted after the second comment\n" + |
2718 |
" // line...\n" + |
2719 |
"\n" + |
2720 |
" /**\n" + |
2721 |
" * Javadoc comment\n" + |
2722 |
" */\n" + |
2723 |
" public X12() {\n" + |
2724 |
" }\n" + |
2725 |
"}\n" |
2726 |
); |
2727 |
} |
2728 |
public void testBug293300_wksp2_13() { |
2729 |
String source = |
2730 |
"package wksp2;\n" + |
2731 |
"\n" + |
2732 |
"public class X13 {\n" + |
2733 |
"void foo(int x) {\n" + |
2734 |
" switch (x) {\n" + |
2735 |
" default : // regular object ref\n" + |
2736 |
"// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {\n" + |
2737 |
"// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);\n" + |
2738 |
"// }\n" + |
2739 |
" }\n" + |
2740 |
"}\n" + |
2741 |
"}\n"; |
2742 |
formatSource(source, |
2743 |
"package wksp2;\n" + |
2744 |
"\n" + |
2745 |
"public class X13 {\n" + |
2746 |
" void foo(int x) {\n" + |
2747 |
" switch (x) {\n" + |
2748 |
" default: // regular object ref\n" + |
2749 |
" // if (compileTimeType.isRawType() &&\n" + |
2750 |
" // runtimeTimeType.isBoundParameterizedType()) {\n" + |
2751 |
" // scope.problemReporter().unsafeRawExpression(this,\n" + |
2752 |
" // compileTimeType, runtimeTimeType);\n" + |
2753 |
" // }\n" + |
2754 |
" }\n" + |
2755 |
" }\n" + |
2756 |
"}\n" |
2757 |
); |
2758 |
} |
2759 |
public void testBug293300_wksp2_14() { |
2760 |
String source = |
2761 |
"package wksp2;\n" + |
2762 |
"\n" + |
2763 |
"public interface X14 {\n" + |
2764 |
"void foo();\n" + |
2765 |
"// line 1\n" + |
2766 |
"// line 2\n" + |
2767 |
"void bar();\n" + |
2768 |
"}\n"; |
2769 |
formatSource(source, |
2770 |
"package wksp2;\n" + |
2771 |
"\n" + |
2772 |
"public interface X14 {\n" + |
2773 |
" void foo();\n" + |
2774 |
"\n" + |
2775 |
" // line 1\n" + |
2776 |
" // line 2\n" + |
2777 |
" void bar();\n" + |
2778 |
"}\n" |
2779 |
); |
2780 |
} |
2781 |
// TODO (frederic) try to fix the formatter instability in the following test case |
2782 |
public void _testBug293300_wksp2_15a() { |
2783 |
String source = |
2784 |
"package wksp2;\n" + |
2785 |
"\n" + |
2786 |
"public class X15 {\n" + |
2787 |
" void foo(int[] params) {\n" + |
2788 |
" if (params.length > 0) { // trailing comment formatted in several lines...\n" + |
2789 |
"// int length = params == null ? : 0 params.length; // this commented lined causes troubles for the formatter but only if the comment starts at column 1...\n" + |
2790 |
" for (int i=0; i<params.length; i++) {\n" + |
2791 |
" }\n" + |
2792 |
" }\n" + |
2793 |
" }\n" + |
2794 |
"}\n"; |
2795 |
formatSource(source, |
2796 |
"\n" + |
2797 |
"public class X15 {\n" + |
2798 |
" void foo(int[] params) {\n" + |
2799 |
" if (params.length > 0) { // trailing comment formatted in several\n" + |
2800 |
" // lines...\n" + |
2801 |
" // int length = params == null ? : 0 params.length; // this\n" + |
2802 |
" // commented\n" + |
2803 |
" // lined causes troubles for the formatter but only if the comment\n" + |
2804 |
" // starts at column 1...\n" + |
2805 |
" for (int i = 0; i < params.length; i++) {\n" + |
2806 |
" }\n" + |
2807 |
" }\n" + |
2808 |
" }\n" + |
2809 |
"}\n" |
2810 |
); |
2811 |
} |
2812 |
public void testBug293300_wksp2_15b() { |
2813 |
String source = |
2814 |
"package wksp2;\n" + |
2815 |
"\n" + |
2816 |
"public class X15 {\n" + |
2817 |
" void foo(int[] params) {\n" + |
2818 |
" if (params.length > 0) { // trailing comment formatted in several lines...\n" + |
2819 |
" // int length = params == null ? : 0 params.length; // this commented lined does not cause troubles for the formatter when the comments is not on column 1...\n" + |
2820 |
" for (int i=0; i<params.length; i++) {\n" + |
2821 |
" }\n" + |
2822 |
" }\n" + |
2823 |
" }\n" + |
2824 |
"}\n"; |
2825 |
formatSource(source, |
2826 |
"package wksp2;\n" + |
2827 |
"\n" + |
2828 |
"public class X15 {\n" + |
2829 |
" void foo(int[] params) {\n" + |
2830 |
" if (params.length > 0) { // trailing comment formatted in several\n" + |
2831 |
" // lines...\n" + |
2832 |
" // int length = params == null ? : 0 params.length; // this\n" + |
2833 |
" // commented lined does not cause troubles for the formatter when\n" + |
2834 |
" // the comments is not on column 1...\n" + |
2835 |
" for (int i = 0; i < params.length; i++) {\n" + |
2836 |
" }\n" + |
2837 |
" }\n" + |
2838 |
" }\n" + |
2839 |
"}\n" |
2840 |
); |
2841 |
} |
2842 |
public void testBug293300_wksp3_01() { |
2843 |
String source = |
2844 |
"package wksp3;\n" + |
2845 |
"\n" + |
2846 |
"public class X01 {\n" + |
2847 |
"static String[] constant = {\n" + |
2848 |
"// comment\n" + |
2849 |
"\"first\",\n" + |
2850 |
"// comment\n" + |
2851 |
"\"second\",\n" + |
2852 |
"};\n" + |
2853 |
"}\n"; |
2854 |
formatSource(source, |
2855 |
"package wksp3;\n" + |
2856 |
"\n" + |
2857 |
"public class X01 {\n" + |
2858 |
" static String[] constant = {\n" + |
2859 |
" // comment\n" + |
2860 |
" \"first\",\n" + |
2861 |
" // comment\n" + |
2862 |
" \"second\", };\n" + |
2863 |
"}\n" |
2864 |
); |
2865 |
} |
2866 |
|
2867 |
/** |
1558 |
* @bug 293496: [formatter] 'insert_space_before_opening_brace_in_array_initializer' preference may be reset in certain circumstances |
2868 |
* @bug 293496: [formatter] 'insert_space_before_opening_brace_in_array_initializer' preference may be reset in certain circumstances |
1559 |
* @test Verify that non ArithmeticException occurs when using tab size = 0 |
2869 |
* @test Verify that non ArithmeticException occurs when using tab size = 0 |
1560 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293496" |
2870 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293496" |