### 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.199 diff -u -r1.199 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 4 Mar 2010 17:43:10 -0000 1.199 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 10 Mar 2010 09:48:39 -0000 @@ -2379,6 +2379,12 @@ case TerminalTokens.TokenNameCOMMENT_JAVADOC : if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); + if (!this.editsEnabled && this.editsIndex > 1) { + OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; + if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { + printNewLinesBeforeDisablingComment(); + } + } previousFoundTaskCount = foundTaskCount; } if (trailing > NO_TRAILING_COMMENT) { #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.58 diff -u -r1.58 FormatterCommentsBugsTest.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 4 Mar 2010 17:43:07 -0000 1.58 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 10 Mar 2010 09:48:43 -0000 @@ -14,6 +14,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.formatter.CodeFormatter; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; @@ -6239,4 +6240,45 @@ "}\n"); } +/** + * @bug 305281: [formatter] Turning off formatting changes comment's formatting + * @test Verify that turning off formatting in a javadoc does not screw up its indentation + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305281" + */ +public void testBug305281() { + this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "format: OFF"); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "format: ON"); + String source = + "public class test {\n" + + "\n" + + " /**\n" + + " * @param args\n" + + " * format: OFF\n" + + " */\n" + + " public static void main(String[] args) {\n" + + " do {\n" + + " } while (false);\n" + + " for (;;) {\n" + + " }\n" + + " // format: ON\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class test {\n" + + "\n" + + " /**\n" + + " * @param args\n" + + " * format: OFF\n" + + " */\n" + + " public static void main(String[] args) {\n" + + " do {\n" + + " } while (false);\n" + + " for (;;) {\n" + + " }\n" + + " // format: ON\n" + + " }\n" + + "}\n"); +} + }