### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.237 diff -u -r1.237 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 9 Nov 2010 14:24:24 -0000 1.237 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 22 Dec 2010 12:56:37 -0000 @@ -1156,6 +1156,7 @@ this.scribe.printNewLine(); } } else if (hasConstants) { + this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); // only had a new line if there is at least one enum constant this.scribe.printNewLine(); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v retrieving revision 1.39 diff -u -r1.39 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 26 Nov 2010 16:42:57 -0000 1.39 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 22 Dec 2010 12:56:40 -0000 @@ -7628,4 +7628,23 @@ "}\n" ); } + +/** + * @bug 332877: [formatter] line comment wrongly put on a new line + * @test Ensure that the comment on last enum constant is not wrongly put on a new line + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=332877" + */ +public void testBug332877() throws Exception { + String source = + "public enum Environment {\n" + + " PROD, // Production level environments\n" + + " STAGING // Staging\n" + + "}\n"; + formatSource(source, + "public enum Environment {\n" + + " PROD, // Production level environments\n" + + " STAGING // Staging\n" + + "}\n" + ); +} }