### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v retrieving revision 1.150 diff -u -r1.150 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 29 Aug 2008 13:21:12 -0000 1.150 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 1 Sep 2008 09:06:40 -0000 @@ -380,7 +380,9 @@ // Set the replacement string to the number of missing new lines // As the end of the edit is out of the region, the possible trailing // indentation should not be added... - if (linesReplaced > 0) { + if (linesReplaced == 0) { + edit.replacement = ""; //$NON-NLS-1$ + } else { int linesCount = linesReplaced > linesOutside ? linesReplaced - linesOutside : 0; if (linesCount == 0) { edit.replacement = ""; //$NON-NLS-1$ #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v retrieving revision 1.26 diff -u -r1.26 FormatterCommentsBugsTest.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 29 Aug 2008 13:21:18 -0000 1.26 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 1 Sep 2008 09:06:42 -0000 @@ -741,7 +741,7 @@ "public class E { \n" + " \n" + "\n" + - " void m3() { // this is a bug\n" + + " void m3() { // this is a bug\n" + "\n" + " }\n" + " \n" + @@ -1361,56 +1361,6 @@ "}\n" ); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=237453 -public void testBug234583_Bug237453a() throws JavaModelException { - String source = - "package test1;\n" + - "\n" + - "public class E1 {\n" + - " void foo() {\n" + - " }\n" + - " [#\n" + - " #]\n" + - " void bar() {\n" + - " }\n" + - "}"; - formatSource(source, - "package test1;\n" + - "\n" + - "public class E1 {\n" + - " void foo() {\n" + - " }\n" + - " \n" + - " void bar() {\n" + - " }\n" + - "}" - ); -} -public void testBug234583_Bug237453b() throws JavaModelException { - String source = - "package test1;\n" + - "\n" + - "public class E1 {\n" + - " void foo() {\n" + - " }\n" + - " \n" + - "[# #]\n" + - " void bar() {\n" + - " }\n" + - "}"; - formatSource(source, - "package test1;\n" + - "\n" + - "public class E1 {\n" + - " void foo() {\n" + - " }\n" + - " \n" + - " \n" + - " void bar() {\n" + - " }\n" + - "}" - ); -} // duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=237592 public void testBug234583_Bug237592() throws JavaModelException { String source = @@ -1445,7 +1395,7 @@ " void foo() {\n" + " }\n" + "\n" + - " \n" + + "\n" + " \n" + " \n" + " \n" + @@ -1790,6 +1740,233 @@ } /** + * @bug 237453: [formatter] Save actions fails to remove excess new lines when set to "format edited lines" + * @test Ensure that empty lines/spaces selection is well formatted + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237453" + */ +public void testBug237453a() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " [#\n" + + " #]\n" + + " void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453b() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + "[# #]\n" + + " void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + "\n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453c() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + "[# \n" + + "#] void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453d() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + "[# \n" + + " #] void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453e() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + "[# \n" + + " #]void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453f() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + "[# #] void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453g() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + "[# #] void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453h() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + "[# #]void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} +public void testBug237453i() throws JavaModelException { + String source = + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + "[# #]void bar() {\n" + + " }\n" + + "}"; + formatSource(source, + "package test1;\n" + + "\n" + + "public class E1 {\n" + + " void foo() {\n" + + " }\n" + + " \n" + + " \n" + + " void bar() {\n" + + " }\n" + + "}" + ); +} + +/** * @bug 238090: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations * @test Ensure that no unexpected empty new lines are added while formatting a reference * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=238090"