View | Details | Raw Unified | Return to bug 270209 | Differences between
and this patch

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+26 lines)
Lines 605-610 Link Here
605
605
606
	/**
606
	/**
607
	 * <pre>
607
	 * <pre>
608
	 * FORMATTER / Option to control whether block comments are condensed or not
609
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.condensed_block_comment"
610
	 *     - possible values:   { TRUE, FALSE }
611
	 *     - default:           FALSE
612
	 * </pre>
613
	 * @see #TRUE
614
	 * @see #FALSE
615
	 * @since 3.6
616
	 */
617
	public final static String FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_block_comment"; //$NON-NLS-1$
618
619
	/**
620
	 * <pre>
621
	 * FORMATTER / Option to control whether javadoc comments are condensed or not
622
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment"
623
	 *     - possible values:   { TRUE, FALSE }
624
	 *     - default:           FALSE
625
	 * </pre>
626
	 * @see #TRUE
627
	 * @see #FALSE
628
	 * @since 3.6
629
	 */
630
	public final static String FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment"; //$NON-NLS-1$
631
632
	/**
633
	 * <pre>
608
	 * FORMATTER / Option to control whether comments are formatted
634
	 * FORMATTER / Option to control whether comments are formatted
609
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_comments"
635
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_comments"
610
	 *     - possible values:   { TRUE, FALSE }
636
	 *     - possible values:   { TRUE, FALSE }
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+12 lines)
Lines 99-104 Link Here
99
99
100
	public boolean comment_clear_blank_lines_in_javadoc_comment;
100
	public boolean comment_clear_blank_lines_in_javadoc_comment;
101
	public boolean comment_clear_blank_lines_in_block_comment;
101
	public boolean comment_clear_blank_lines_in_block_comment;
102
	public boolean comment_condensed_block_comment;
103
	public boolean comment_condensed_javadoc_comment;
102
	public boolean comment_format_javadoc_comment;
104
	public boolean comment_format_javadoc_comment;
103
	public boolean comment_format_line_comment;
105
	public boolean comment_format_line_comment;
104
	public boolean comment_format_block_comment;
106
	public boolean comment_format_block_comment;
Lines 367-372 Link Here
367
		options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH, this.brace_position_for_switch);
369
		options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH, this.brace_position_for_switch);
368
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, this.comment_clear_blank_lines_in_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
370
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, this.comment_clear_blank_lines_in_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
369
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
371
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
372
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT, this.comment_condensed_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
373
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT, this.comment_condensed_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
370
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
374
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
371
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
375
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
372
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
376
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
Lines 1089-1094 Link Here
1089
				this.comment_line_length = 80;
1093
				this.comment_line_length = 80;
1090
			}
1094
			}
1091
		}
1095
		}
1096
		final Object commentCondensedBlockCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT);
1097
		if (commentCondensedBlockCommentOption != null) {
1098
			this.comment_condensed_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedBlockCommentOption);
1099
		}
1100
		final Object commentCondensedJavadocCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT);
1101
		if (commentCondensedJavadocCommentOption != null) {
1102
			this.comment_condensed_javadoc_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedJavadocCommentOption);
1103
		}
1092
		final Object indentStatementsCompareToBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK);
1104
		final Object indentStatementsCompareToBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK);
1093
		if (indentStatementsCompareToBlockOption != null) {
1105
		if (indentStatementsCompareToBlockOption != null) {
1094
			this.indent_statements_compare_to_block = DefaultCodeFormatterConstants.TRUE.equals(indentStatementsCompareToBlockOption);
1106
			this.indent_statements_compare_to_block = DefaultCodeFormatterConstants.TRUE.equals(indentStatementsCompareToBlockOption);
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-7 / +14 lines)
Lines 1628-1633 Link Here
1628
		boolean firstWord = true;
1628
		boolean firstWord = true;
1629
		boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment;
1629
		boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment;
1630
		boolean joinLines = this.formatter.preferences.join_lines_in_comments;
1630
		boolean joinLines = this.formatter.preferences.join_lines_in_comments;
1631
		boolean condensed = this.formatter.preferences.comment_condensed_block_comment;
1631
		int scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, 0, this.maxLines);
1632
		int scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, 0, this.maxLines);
1632
		int firstLine = scannerLine;
1633
		int firstLine = scannerLine;
1633
		int lineNumber = scannerLine;
1634
		int lineNumber = scannerLine;
Lines 1687-1696 Link Here
1687
							this.column += tokensBuffer.length();
1688
							this.column += tokensBuffer.length();
1688
						}
1689
						}
1689
						// end of comment
1690
						// end of comment
1690
						if (multiLines || hasMultiLines) {
1691
						if (!condensed) {
1691
					    	buffer.append(this.lineSeparator);
1692
							if (multiLines || hasMultiLines) {
1692
					    	this.column = 1;
1693
						    	buffer.append(this.lineSeparator);
1693
					    	printIndentationIfNecessary(buffer);
1694
						    	this.column = 1;
1695
						    	printIndentationIfNecessary(buffer);
1696
							}
1694
						}
1697
						}
1695
						buffer.append(' ');
1698
						buffer.append(' ');
1696
						this.column += BLOCK_FOOTER_LENGTH + 1;
1699
						this.column += BLOCK_FOOTER_LENGTH + 1;
Lines 1736-1742 Link Here
1736
			int max;
1739
			int max;
1737
			lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines);
1740
			lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines);
1738
			if (lastTextLine == -1) {
1741
			if (lastTextLine == -1) {
1739
				linesGap = lineNumber - firstLine;
1742
				linesGap = condensed ? 0 : lineNumber - firstLine;
1740
				max = 0;
1743
				max = 0;
1741
			} else {
1744
			} else {
1742
				linesGap = lineNumber - lastTextLine;
1745
				linesGap = lineNumber - lastTextLine;
Lines 1874-1880 Link Here
1874
	}
1877
	}
1875
1878
1876
	private void printBlockCommentHeaderLine(StringBuffer buffer) {
1879
	private void printBlockCommentHeaderLine(StringBuffer buffer) {
1877
	    if (buffer.length() == 0) {
1880
		if (this.formatter.preferences.comment_condensed_block_comment) {
1881
			buffer.insert(0, ' ');
1882
			this.column++;
1883
		}
1884
	    else if (buffer.length() == 0) {
1878
	    	buffer.append(this.lineSeparator);
1885
	    	buffer.append(this.lineSeparator);
1879
	    	this.column = 1;
1886
	    	this.column = 1;
1880
	    	printIndentationIfNecessary(buffer);
1887
	    	printIndentationIfNecessary(buffer);
Lines 3276-3282 Link Here
3276
			printJavadocBlock(previousBlock);
3283
			printJavadocBlock(previousBlock);
3277
3284
3278
			// format the header and footer empty spaces
3285
			// format the header and footer empty spaces
3279
			int newLines = this.line > currentLine || javadoc.isMultiLine() ? 1 : 0;
3286
			int newLines = (!this.formatter.preferences.comment_condensed_javadoc_comment && (this.line > currentLine || javadoc.isMultiLine())) ? 1 : 0;
3280
			printJavadocGapLines(javadoc.textStart, firstBlockStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null);
3287
			printJavadocGapLines(javadoc.textStart, firstBlockStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null);
3281
			printJavadocGapLines(previousBlock.sourceEnd+1, javadoc.textEnd, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, true, null);
3288
			printJavadocGapLines(previousBlock.sourceEnd+1, javadoc.textEnd, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, true, null);
3282
		}
3289
		}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (+127 lines)
Lines 5424-5429 Link Here
5424
}
5424
}
5425
5425
5426
/**
5426
/**
5427
 * @bug 270209: [format] Condensed block comment formatting
5428
 * @test Verify that block and javadoc comments are formatted in condensed
5429
 * 		mode when the corresponding preferences is set
5430
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=270209"
5431
 */
5432
public void testBug270209_Block01() throws JavaModelException {
5433
	this.formatterPrefs.comment_condensed_block_comment = true;
5434
	String source = 
5435
		"public interface X01 {\n" + 
5436
		"\n" + 
5437
		"/* Instead of like this.  I use these a lot and\n" + 
5438
		" * this can take up a lot of space. */\n" + 
5439
		"void foo();\n" + 
5440
		"}\n";
5441
	formatSource(source,
5442
		"public interface X01 {\n" + 
5443
		"\n" + 
5444
		"	/* Instead of like this. I use these a lot and this can take up a lot of\n" + 
5445
		"	 * space. */\n" + 
5446
		"	void foo();\n" + 
5447
		"}\n"
5448
	);
5449
}
5450
public void testBug270209_Block02() throws JavaModelException {
5451
	this.formatterPrefs.comment_condensed_block_comment = true;
5452
	String source = 
5453
		"public interface X02 {\n" + 
5454
		"\n" + 
5455
		"/*\n" + 
5456
		" * Instead of like this.  I use these a lot and\n" + 
5457
		" * this can take up a lot of space.\n" + 
5458
		" */\n" + 
5459
		"void foo();\n" + 
5460
		"}\n";
5461
	formatSource(source,
5462
		"public interface X02 {\n" + 
5463
		"\n" + 
5464
		"	/* Instead of like this. I use these a lot and this can take up a lot of\n" + 
5465
		"	 * space. */\n" + 
5466
		"	void foo();\n" + 
5467
		"}\n"
5468
	);
5469
}
5470
public void testBug270209_Block03() throws JavaModelException {
5471
	this.formatterPrefs.comment_condensed_block_comment = true;
5472
	String source = 
5473
		"public interface X03 {\n" + 
5474
		"\n" + 
5475
		"/*\n" + 
5476
		" * \n" + 
5477
		" * Instead of like this.  I use these a lot and\n" + 
5478
		" * this can take up a lot of space.\n" + 
5479
		" * \n" + 
5480
		" */\n" + 
5481
		"void foo();\n" + 
5482
		"}\n";
5483
	formatSource(source,
5484
		"public interface X03 {\n" + 
5485
		"\n" + 
5486
		"	/* Instead of like this. I use these a lot and this can take up a lot of\n" + 
5487
		"	 * space. */\n" + 
5488
		"	void foo();\n" + 
5489
		"}\n"
5490
	);
5491
}
5492
public void testBug270209_Javadoc01() throws JavaModelException {
5493
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5494
	String source = 
5495
		"public interface X01 {\n" + 
5496
		"\n" + 
5497
		"/** Instead of like this.  I use these a lot and\n" + 
5498
		" * this can take up a lot of space. */\n" + 
5499
		"void foo();\n" + 
5500
		"}\n";
5501
	formatSource(source,
5502
		"public interface X01 {\n" + 
5503
		"\n" + 
5504
		"	/** Instead of like this. I use these a lot and this can take up a lot of\n" + 
5505
		"	 * space. */\n" + 
5506
		"	void foo();\n" + 
5507
		"}\n"
5508
	);
5509
}
5510
public void testBug270209_Javadoc02() throws JavaModelException {
5511
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5512
	String source = 
5513
		"public interface X02 {\n" + 
5514
		"\n" + 
5515
		"/**\n" + 
5516
		" * Instead of like this.  I use these a lot and\n" + 
5517
		" * this can take up a lot of space.\n" + 
5518
		" */\n" + 
5519
		"void foo();\n" + 
5520
		"}\n";
5521
	formatSource(source,
5522
		"public interface X02 {\n" + 
5523
		"\n" + 
5524
		"	/** Instead of like this. I use these a lot and this can take up a lot of\n" + 
5525
		"	 * space. */\n" + 
5526
		"	void foo();\n" + 
5527
		"}\n"
5528
	);
5529
}
5530
public void testBug270209_Javadoc03() throws JavaModelException {
5531
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5532
	String source = 
5533
		"public interface X03 {\n" + 
5534
		"\n" + 
5535
		"/**\n" + 
5536
		" * \n" + 
5537
		" * Instead of like this.  I use these a lot and\n" + 
5538
		" * this can take up a lot of space.\n" + 
5539
		" * \n" + 
5540
		" */\n" + 
5541
		"void foo();\n" + 
5542
		"}\n";
5543
	formatSource(source,
5544
		"public interface X03 {\n" + 
5545
		"\n" + 
5546
		"	/** Instead of like this. I use these a lot and this can take up a lot of\n" + 
5547
		"	 * space. */\n" + 
5548
		"	void foo();\n" + 
5549
		"}\n"
5550
	);
5551
}
5552
5553
/**
5427
 * @bug 273619: [formatter] Formatting repeats *} in javadoc
5554
 * @bug 273619: [formatter] Formatting repeats *} in javadoc
5428
 * @test Ensure that *} is not repeated while formatting
5555
 * @test Ensure that *} is not repeated while formatting
5429
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=273619"
5556
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=273619"

Return to bug 270209