### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v retrieving revision 1.99 diff -u -r1.99 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 18 Feb 2010 10:41:31 -0000 1.99 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 20 Feb 2010 10:19:53 -0000 @@ -605,6 +605,32 @@ /** *
+	 * 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	20 Feb 2010 10:19:56 -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	20 Feb 2010 10:19:58 -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.52
diff -u -r1.52 FormatterCommentsBugsTest.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java	14 Feb 2010 15:57:04 -0000	1.52
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java	20 Feb 2010 10:20:06 -0000
@@ -5424,6 +5424,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"