### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: buildnotes_jdt-core.html =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v retrieving revision 1.7311 diff -u -r1.7311 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 22 Feb 2010 11:05:21 -0000 1.7311 +++ buildnotes_jdt-core.html 22 Feb 2010 12:58:51 -0000 @@ -50,6 +50,69 @@
+These new preferences are controlled respectively with the options:
+DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT
DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT
++/** + * FORMATTER / Option to control whether block comments are condensed or not + * - option id: "org.eclipse.jdt.core.formatter.comment.condensed_block_comment" + * - possible values: { TRUE, FALSE } + * - default: FALSE + * + * @see #TRUE + * @see #FALSE + * @since 3.6 + */ + +/** + * FORMATTER / Option to control whether javadoc comments are condensed or not + * - option id: "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment" + * - possible values: { TRUE, FALSE } + * - default: FALSE + * + * @see #TRUE + * @see #FALSE + * @since 3.6 + */ ++
For example, when both of these options are used, the following snippet:
++public class X { + /* + * This block comment after formatting will no longer use a new line + * at the beginning and at the end of the comment... + */ + void foo() { + } + /** + * This javadoc comment after formatting will no longer use a new line + * at the beginning and at the end of the comment... + */ + void bar() { + } +} ++formatted with this preference activated, will produce the following output: +
+public class X { + /* This block comment after formatting will no longer use a new line at the + * beginning and at the end of the comment... */ + void foo() { + } + + /** This javadoc comment after formatting will no longer use a new line at + * the beginning and at the end of the comment... */ + void bar() { + } + } +} ++See bug 270209 for more details. +
CodeFormatter.F_INCLUDE_COMMENT
flag now works for all kind
of snippet while using the formatter.+ * FORMATTER / Option to control whether block comments are condensed or not + * - option id: "org.eclipse.jdt.core.formatter.comment.condensed_block_comment" + * - possible values: { TRUE, FALSE } + * - default: FALSE + *+ * @see #TRUE + * @see #FALSE + * @since 3.6 + */ + public final static String FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_block_comment"; //$NON-NLS-1$ + + /** + *
+ * FORMATTER / Option to control whether javadoc comments are condensed or not + * - option id: "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment" + * - possible values: { TRUE, FALSE } + * - default: FALSE + *+ * @see #TRUE + * @see #FALSE + * @since 3.6 + */ + public final static String FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment"; //$NON-NLS-1$ + + /** + *
* FORMATTER / Option to control whether comments are formatted * - option id: "org.eclipse.jdt.core.formatter.comment.format_comments" * - possible values: { TRUE, FALSE } Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v retrieving revision 1.95 diff -u -r1.95 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 18 Feb 2010 10:41:32 -0000 1.95 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 22 Feb 2010 12:58:54 -0000 @@ -99,6 +99,8 @@ public boolean comment_clear_blank_lines_in_javadoc_comment; public boolean comment_clear_blank_lines_in_block_comment; + public boolean comment_condensed_block_comment; + public boolean comment_condensed_javadoc_comment; public boolean comment_format_javadoc_comment; public boolean comment_format_line_comment; public boolean comment_format_block_comment; @@ -367,6 +369,8 @@ options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH, this.brace_position_for_switch); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, this.comment_clear_blank_lines_in_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT, this.comment_condensed_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT, this.comment_condensed_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); @@ -1089,6 +1093,14 @@ this.comment_line_length = 80; } } + final Object commentCondensedBlockCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT); + if (commentCondensedBlockCommentOption != null) { + this.comment_condensed_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedBlockCommentOption); + } + final Object commentCondensedJavadocCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT); + if (commentCondensedJavadocCommentOption != null) { + this.comment_condensed_javadoc_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedJavadocCommentOption); + } final Object indentStatementsCompareToBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK); if (indentStatementsCompareToBlockOption != null) { this.indent_statements_compare_to_block = DefaultCodeFormatterConstants.TRUE.equals(indentStatementsCompareToBlockOption); 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.192 diff -u -r1.192 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 14 Feb 2010 15:57:25 -0000 1.192 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 22 Feb 2010 12:58:54 -0000 @@ -1628,6 +1628,7 @@ boolean firstWord = true; boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment; boolean joinLines = this.formatter.preferences.join_lines_in_comments; + boolean condensed = this.formatter.preferences.comment_condensed_block_comment; int scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, 0, this.maxLines); int firstLine = scannerLine; int lineNumber = scannerLine; @@ -1687,10 +1688,12 @@ this.column += tokensBuffer.length(); } // end of comment - if (multiLines || hasMultiLines) { - buffer.append(this.lineSeparator); - this.column = 1; - printIndentationIfNecessary(buffer); + if (!condensed) { + if (multiLines || hasMultiLines) { + buffer.append(this.lineSeparator); + this.column = 1; + printIndentationIfNecessary(buffer); + } } buffer.append(' '); this.column += BLOCK_FOOTER_LENGTH + 1; @@ -1736,7 +1739,7 @@ int max; lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); if (lastTextLine == -1) { - linesGap = lineNumber - firstLine; + linesGap = condensed ? 0 : lineNumber - firstLine; max = 0; } else { linesGap = lineNumber - lastTextLine; @@ -1874,7 +1877,11 @@ } private void printBlockCommentHeaderLine(StringBuffer buffer) { - if (buffer.length() == 0) { + if (this.formatter.preferences.comment_condensed_block_comment) { + buffer.insert(0, ' '); + this.column++; + } + else if (buffer.length() == 0) { buffer.append(this.lineSeparator); this.column = 1; printIndentationIfNecessary(buffer); @@ -3276,7 +3283,7 @@ printJavadocBlock(previousBlock); // format the header and footer empty spaces - int newLines = this.line > currentLine || javadoc.isMultiLine() ? 1 : 0; + int newLines = (!this.formatter.preferences.comment_condensed_javadoc_comment && (this.line > currentLine || javadoc.isMultiLine())) ? 1 : 0; printJavadocGapLines(javadoc.textStart, firstBlockStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); printJavadocGapLines(previousBlock.sourceEnd+1, javadoc.textEnd, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, true, null); } #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.53 diff -u -r1.53 FormatterCommentsBugsTest.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 22 Feb 2010 11:01:36 -0000 1.53 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 22 Feb 2010 12:58:57 -0000 @@ -5558,6 +5558,133 @@ } /** + * @bug 270209: [format] Condensed block comment formatting + * @test Verify that block and javadoc comments are formatted in condensed + * mode when the corresponding preferences is set + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=270209" + */ +public void testBug270209_Block01() throws JavaModelException { + this.formatterPrefs.comment_condensed_block_comment = true; + String source = + "public interface X01 {\n" + + "\n" + + "/* Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space. */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X01 {\n" + + "\n" + + " /* Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} +public void testBug270209_Block02() throws JavaModelException { + this.formatterPrefs.comment_condensed_block_comment = true; + String source = + "public interface X02 {\n" + + "\n" + + "/*\n" + + " * Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space.\n" + + " */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X02 {\n" + + "\n" + + " /* Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} +public void testBug270209_Block03() throws JavaModelException { + this.formatterPrefs.comment_condensed_block_comment = true; + String source = + "public interface X03 {\n" + + "\n" + + "/*\n" + + " * \n" + + " * Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space.\n" + + " * \n" + + " */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X03 {\n" + + "\n" + + " /* Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} +public void testBug270209_Javadoc01() throws JavaModelException { + this.formatterPrefs.comment_condensed_javadoc_comment = true; + String source = + "public interface X01 {\n" + + "\n" + + "/** Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space. */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X01 {\n" + + "\n" + + " /** Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} +public void testBug270209_Javadoc02() throws JavaModelException { + this.formatterPrefs.comment_condensed_javadoc_comment = true; + String source = + "public interface X02 {\n" + + "\n" + + "/**\n" + + " * Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space.\n" + + " */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X02 {\n" + + "\n" + + " /** Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} +public void testBug270209_Javadoc03() throws JavaModelException { + this.formatterPrefs.comment_condensed_javadoc_comment = true; + String source = + "public interface X03 {\n" + + "\n" + + "/**\n" + + " * \n" + + " * Instead of like this. I use these a lot and\n" + + " * this can take up a lot of space.\n" + + " * \n" + + " */\n" + + "void foo();\n" + + "}\n"; + formatSource(source, + "public interface X03 {\n" + + "\n" + + " /** Instead of like this. I use these a lot and this can take up a lot of\n" + + " * space. */\n" + + " void foo();\n" + + "}\n" + ); +} + +/** * @bug 273619: [formatter] Formatting repeats *} in javadoc * @test Ensure that *} is not repeated while formatting * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=273619"