View | Details | Raw Unified | Return to bug 237453
Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-1 / +3 lines)
Lines 380-386 Link Here
380
						// Set the replacement string to the number of missing new lines
380
						// Set the replacement string to the number of missing new lines
381
						// As the end of the edit is out of the region, the possible trailing
381
						// As the end of the edit is out of the region, the possible trailing
382
						// indentation should not be added...
382
						// indentation should not be added...
383
						if (linesReplaced > 0) {
383
						if (linesReplaced == 0) {
384
			    			edit.replacement = ""; //$NON-NLS-1$
385
						} else {
384
							int linesCount = linesReplaced > linesOutside ? linesReplaced - linesOutside : 0;
386
							int linesCount = linesReplaced > linesOutside ? linesReplaced - linesOutside : 0;
385
							if (linesCount == 0) {
387
							if (linesCount == 0) {
386
				    			edit.replacement = ""; //$NON-NLS-1$
388
				    			edit.replacement = ""; //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-52 / +229 lines)
Lines 741-747 Link Here
741
		"public class E {       \n" +
741
		"public class E {       \n" +
742
		"	\n" +
742
		"	\n" +
743
		"\n" +
743
		"\n" +
744
		"	void m3() { // this      is        a    bug\n" +
744
		"	void m3() { // this     is        a    bug\n" +
745
		"\n" +
745
		"\n" +
746
		"        }\n" +
746
		"        }\n" +
747
		"   \n" +
747
		"   \n" +
Lines 1361-1416 Link Here
1361
		"}\n"
1361
		"}\n"
1362
	);
1362
	);
1363
}
1363
}
1364
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=237453
1365
public void testBug234583_Bug237453a() throws JavaModelException {
1366
	String source = 
1367
		"package test1;\n" + 
1368
		"\n" + 
1369
		"public class E1 {\n" + 
1370
		" 	void foo() {\n" + 
1371
		"	}\n" + 
1372
		" 	[#\n" + 
1373
		"	#]\n" + 
1374
		" 	void bar() {\n" + 
1375
		"	}\n" + 
1376
		"}";
1377
	formatSource(source,
1378
		"package test1;\n" + 
1379
		"\n" + 
1380
		"public class E1 {\n" + 
1381
		" 	void foo() {\n" + 
1382
		"	}\n" + 
1383
		" 	\n" + 
1384
		" 	void bar() {\n" + 
1385
		"	}\n" + 
1386
		"}"
1387
	);
1388
}
1389
public void testBug234583_Bug237453b() throws JavaModelException {
1390
	String source = 
1391
		"package test1;\n" + 
1392
		"\n" + 
1393
		"public class E1 {\n" + 
1394
		" 	void foo() {\n" + 
1395
		"	}\n" + 
1396
		" 	\n" + 
1397
		"[#	#]\n" + 
1398
		" 	void bar() {\n" + 
1399
		"	}\n" + 
1400
		"}";
1401
	formatSource(source,
1402
		"package test1;\n" + 
1403
		"\n" + 
1404
		"public class E1 {\n" + 
1405
		" 	void foo() {\n" + 
1406
		"	}\n" + 
1407
		" 	\n" + 
1408
		"	\n" + 
1409
		" 	void bar() {\n" + 
1410
		"	}\n" + 
1411
		"}"
1412
	);
1413
}
1414
// duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=237592
1364
// duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=237592
1415
public void testBug234583_Bug237592() throws JavaModelException {
1365
public void testBug234583_Bug237592() throws JavaModelException {
1416
	String source = 
1366
	String source = 
Lines 1445-1451 Link Here
1445
		"	void foo() {\n" + 
1395
		"	void foo() {\n" + 
1446
		"	}\n" + 
1396
		"	}\n" + 
1447
		"\n" + 
1397
		"\n" + 
1448
		"	\n" + 
1398
		"\n" + 
1449
		"	\n" + 
1399
		"	\n" + 
1450
		"	\n" + 
1400
		"	\n" + 
1451
		"	\n" + 
1401
		"	\n" + 
Lines 1790-1795 Link Here
1790
}
1740
}
1791
1741
1792
/**
1742
/**
1743
 * @bug 237453: [formatter] Save actions fails to remove excess new lines when set to "format edited lines"
1744
 * @test Ensure that empty lines/spaces selection is well formatted
1745
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237453"
1746
 */
1747
public void testBug237453a() throws JavaModelException {
1748
	String source = 
1749
		"package test1;\n" + 
1750
		"\n" + 
1751
		"public class E1 {\n" + 
1752
		" 	void foo() {\n" + 
1753
		"	}\n" + 
1754
		" 	[#\n" + 
1755
		"	#]\n" + 
1756
		" 	void bar() {\n" + 
1757
		"	}\n" + 
1758
		"}";
1759
	formatSource(source,
1760
		"package test1;\n" + 
1761
		"\n" + 
1762
		"public class E1 {\n" + 
1763
		" 	void foo() {\n" + 
1764
		"	}\n" + 
1765
		" 	\n" + 
1766
		" 	void bar() {\n" + 
1767
		"	}\n" + 
1768
		"}"
1769
	);
1770
}
1771
public void testBug237453b() throws JavaModelException {
1772
	String source = 
1773
		"package test1;\n" + 
1774
		"\n" + 
1775
		"public class E1 {\n" + 
1776
		" 	void foo() {\n" + 
1777
		"	}\n" + 
1778
		" 	\n" + 
1779
		"[#	#]\n" + 
1780
		" 	void bar() {\n" + 
1781
		"	}\n" + 
1782
		"}";
1783
	formatSource(source,
1784
		"package test1;\n" + 
1785
		"\n" + 
1786
		"public class E1 {\n" + 
1787
		" 	void foo() {\n" + 
1788
		"	}\n" + 
1789
		" 	\n" + 
1790
		"\n" + 
1791
		" 	void bar() {\n" + 
1792
		"	}\n" + 
1793
		"}"
1794
	);
1795
}
1796
public void testBug237453c() throws JavaModelException {
1797
	String source = 
1798
		"package test1;\n" + 
1799
		"\n" + 
1800
		"public class E1 {\n" + 
1801
		" 	void foo() {\n" + 
1802
		"	}\n" + 
1803
		" 	\n" + 
1804
		"[#	\n" + 
1805
		"#] 	void bar() {\n" + 
1806
		"	}\n" + 
1807
		"}";
1808
	formatSource(source,
1809
		"package test1;\n" + 
1810
		"\n" + 
1811
		"public class E1 {\n" + 
1812
		" 	void foo() {\n" + 
1813
		"	}\n" + 
1814
		" 	\n" + 
1815
		" 	void bar() {\n" + 
1816
		"	}\n" + 
1817
		"}"
1818
	);
1819
}
1820
public void testBug237453d() throws JavaModelException {
1821
	String source = 
1822
		"package test1;\n" + 
1823
		"\n" + 
1824
		"public class E1 {\n" + 
1825
		" 	void foo() {\n" + 
1826
		"	}\n" + 
1827
		" 	\n" + 
1828
		"[#	\n" + 
1829
		" #]	void bar() {\n" + 
1830
		"	}\n" + 
1831
		"}";
1832
	formatSource(source,
1833
		"package test1;\n" + 
1834
		"\n" + 
1835
		"public class E1 {\n" + 
1836
		" 	void foo() {\n" + 
1837
		"	}\n" + 
1838
		" 	\n" + 
1839
		"	void bar() {\n" + 
1840
		"	}\n" + 
1841
		"}"
1842
	);
1843
}
1844
public void testBug237453e() throws JavaModelException {
1845
	String source = 
1846
		"package test1;\n" + 
1847
		"\n" + 
1848
		"public class E1 {\n" + 
1849
		" 	void foo() {\n" + 
1850
		"	}\n" + 
1851
		" 	\n" + 
1852
		"[#	\n" + 
1853
		" 	#]void bar() {\n" + 
1854
		"	}\n" + 
1855
		"}";
1856
	formatSource(source,
1857
		"package test1;\n" + 
1858
		"\n" + 
1859
		"public class E1 {\n" + 
1860
		" 	void foo() {\n" + 
1861
		"	}\n" + 
1862
		" 	\n" + 
1863
		"	void bar() {\n" + 
1864
		"	}\n" + 
1865
		"}"
1866
	);
1867
}
1868
public void testBug237453f() throws JavaModelException {
1869
	String source = 
1870
		"package test1;\n" + 
1871
		"\n" + 
1872
		"public class E1 {\n" + 
1873
		" 	void foo() {\n" + 
1874
		"	}\n" + 
1875
		" 	\n" + 
1876
		"	\n" + 
1877
		"[# #]	void bar() {\n" + 
1878
		"	}\n" + 
1879
		"}";
1880
	formatSource(source,
1881
		"package test1;\n" + 
1882
		"\n" + 
1883
		"public class E1 {\n" + 
1884
		" 	void foo() {\n" + 
1885
		"	}\n" + 
1886
		" 	\n" + 
1887
		"	\n" + 
1888
		"	void bar() {\n" + 
1889
		"	}\n" + 
1890
		"}"
1891
	);
1892
}
1893
public void testBug237453g() throws JavaModelException {
1894
	String source = 
1895
		"package test1;\n" + 
1896
		"\n" + 
1897
		"public class E1 {\n" + 
1898
		" 	void foo() {\n" + 
1899
		"	}\n" + 
1900
		" 	\n" + 
1901
		"	\n" + 
1902
		"[# #] void bar() {\n" + 
1903
		"	}\n" + 
1904
		"}";
1905
	formatSource(source,
1906
		"package test1;\n" + 
1907
		"\n" + 
1908
		"public class E1 {\n" + 
1909
		" 	void foo() {\n" + 
1910
		"	}\n" + 
1911
		" 	\n" + 
1912
		"	\n" + 
1913
		" void bar() {\n" + 
1914
		"	}\n" + 
1915
		"}"
1916
	);
1917
}
1918
public void testBug237453h() throws JavaModelException {
1919
	String source = 
1920
		"package test1;\n" + 
1921
		"\n" + 
1922
		"public class E1 {\n" + 
1923
		" 	void foo() {\n" + 
1924
		"	}\n" + 
1925
		" 	\n" + 
1926
		"	\n" + 
1927
		"[# 	#]void bar() {\n" + 
1928
		"	}\n" + 
1929
		"}";
1930
	formatSource(source,
1931
		"package test1;\n" + 
1932
		"\n" + 
1933
		"public class E1 {\n" + 
1934
		" 	void foo() {\n" + 
1935
		"	}\n" + 
1936
		" 	\n" + 
1937
		"	\n" + 
1938
		"	void bar() {\n" + 
1939
		"	}\n" + 
1940
		"}"
1941
	);
1942
}
1943
public void testBug237453i() throws JavaModelException {
1944
	String source = 
1945
		"package test1;\n" + 
1946
		"\n" + 
1947
		"public class E1 {\n" + 
1948
		" 	void foo() {\n" + 
1949
		"	}\n" + 
1950
		" 	\n" + 
1951
		"	\n" + 
1952
		"[#  #]void bar() {\n" + 
1953
		"	}\n" + 
1954
		"}";
1955
	formatSource(source,
1956
		"package test1;\n" + 
1957
		"\n" + 
1958
		"public class E1 {\n" + 
1959
		" 	void foo() {\n" + 
1960
		"	}\n" + 
1961
		" 	\n" + 
1962
		"	\n" + 
1963
		"	void bar() {\n" + 
1964
		"	}\n" + 
1965
		"}"
1966
	);
1967
}
1968
1969
/**
1793
 * @bug 238090: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations
1970
 * @bug 238090: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations
1794
 * @test Ensure that no unexpected empty new lines are added while formatting a reference
1971
 * @test Ensure that no unexpected empty new lines are added while formatting a reference
1795
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=238090"
1972
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=238090"

Return to bug 237453