### 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.222 diff -u -r1.222 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 26 Nov 2010 16:42:56 -0000 1.222 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 10 Jan 2011 10:54:42 -0000 @@ -2457,7 +2457,9 @@ // delete consumed white spaces hasWhitespaces = true; currentTokenStartPosition = this.scanner.currentPosition; - addDeleteEdit(tokenStartPosition, whitespacesEndPosition); + if (this.formatter.preferences.comment_format_line_comment) { + addDeleteEdit(tokenStartPosition, whitespacesEndPosition); + } } else { if (lines == 0) { hasWhitespaces = true; @@ -2731,7 +2733,7 @@ this.lastLineComment.indentation = commentIndentationLevel; // Add pending space if necessary - if (this.pendingSpace) { + if (this.formatter.preferences.comment_format_line_comment && this.pendingSpace) { addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$ } this.needSpace = false; #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 10 Jan 2011 10:54:45 -0000 @@ -7628,4 +7628,36 @@ "}\n" ); } + +/** + * @bug 282988: [formatter] Option to align single-line comments in a column + * @test Ensure that with line comment formatting turned off comment alignment doesn't change + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988" + */ +public void testBug282988() throws Exception { + this.formatterPrefs.comment_format_line_comment = false; + String source = + "package test;\n" + + "\n" + + "public class FormatterError {\n" + + " public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" + + " buffer.clear();\n" + + " buffer.putLong(0); // backlink to previous version of this object\n" + + " buffer.putInt(1); // version identifier\n" + + " buffer.flip(); // prepare to write\n" + + " }\n" + + "}\n"; + formatSource(source, + "package test;\n" + + "\n" + + "public class FormatterError {\n" + + " public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" + + " buffer.clear();\n" + + " buffer.putLong(0); // backlink to previous version of this object\n" + + " buffer.putInt(1); // version identifier\n" + + " buffer.flip(); // prepare to write\n" + + " }\n" + + "}\n" + ); +} }