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 / +26 lines)
Lines 616-647 Link Here
616
616
617
	/**
617
	/**
618
	 * <pre>
618
	 * <pre>
619
	 * FORMATTER / Option to control whether block comments are condensed or not
620
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.condensed_block_comment"
621
	 *     - possible values:   { TRUE, FALSE }
622
	 *     - default:           FALSE
623
	 * </pre>
624
	 * @see #TRUE
625
	 * @see #FALSE
626
	 * @since 3.6
627
	 */
628
	public final static String FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_block_comment"; //$NON-NLS-1$
629
630
	/**
631
	 * <pre>
632
	 * FORMATTER / Option to control whether javadoc comments are condensed or not
633
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment"
634
	 *     - possible values:   { TRUE, FALSE }
635
	 *     - default:           FALSE
636
	 * </pre>
637
	 * @see #TRUE
638
	 * @see #FALSE
639
	 * @since 3.6
640
	 */
641
	public final static String FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT = "org.eclipse.jdt.core.formatter.comment.condensed_javadoc_comment"; //$NON-NLS-1$
642
643
	/**
644
	 * <pre>
645
	 * FORMATTER / Option to control whether comments are formatted
619
	 * FORMATTER / Option to control whether comments are formatted
646
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_comments"
620
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_comments"
647
	 *     - possible values:   { TRUE, FALSE }
621
	 *     - possible values:   { TRUE, FALSE }
Lines 798-803 Link Here
798
772
799
	/**
773
	/**
800
	 * <pre>
774
	 * <pre>
775
	 * FORMATTER / Option to control whether block comments will have new lines at boundaries
776
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries"
777
	 *     - possible values:   { TRUE, FALSE }
778
	 *     - default:           TRUE
779
	 * </pre>
780
	 * @see #TRUE
781
	 * @see #FALSE
782
	 * @since 3.6
783
	 */
784
	public final static String FORMATTER_COMMENT_NEW_LINES_AT_BLOCK_BOUNDARIES = "org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries"; //$NON-NLS-1$
785
786
	/**
787
	 * <pre>
788
	 * FORMATTER / Option to control whether javadoc comments will have new lines at boundaries
789
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries"
790
	 *     - possible values:   { TRUE, FALSE }
791
	 *     - default:           TRUE
792
	 * </pre>
793
	 * @see #TRUE
794
	 * @see #FALSE
795
	 * @since 3.6
796
	 */
797
	public final static String FORMATTER_COMMENT_NEW_LINES_AT_JAVADOC_BOUNDARIES = "org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries"; //$NON-NLS-1$
798
799
	/**
800
	 * <pre>
801
	 * FORMATTER / Option to compact else/if
801
	 * FORMATTER / Option to compact else/if
802
	 *     - option id:         "org.eclipse.jdt.core.formatter.compact_else_if"
802
	 *     - option id:         "org.eclipse.jdt.core.formatter.compact_else_if"
803
	 *     - possible values:   { TRUE, FALSE }
803
	 *     - possible values:   { TRUE, FALSE }
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-11 / +15 lines)
Lines 100-107 Link Here
100
100
101
	public boolean comment_clear_blank_lines_in_javadoc_comment;
101
	public boolean comment_clear_blank_lines_in_javadoc_comment;
102
	public boolean comment_clear_blank_lines_in_block_comment;
102
	public boolean comment_clear_blank_lines_in_block_comment;
103
	public boolean comment_condensed_block_comment;
103
	public boolean comment_new_lines_at_block_boundaries;
104
	public boolean comment_condensed_javadoc_comment;
104
	public boolean comment_new_lines_at_javadoc_boundaries;
105
	public boolean comment_format_javadoc_comment;
105
	public boolean comment_format_javadoc_comment;
106
	public boolean comment_format_line_comment;
106
	public boolean comment_format_line_comment;
107
	public boolean comment_format_block_comment;
107
	public boolean comment_format_block_comment;
Lines 371-378 Link Here
371
		options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH, this.brace_position_for_switch);
371
		options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH, this.brace_position_for_switch);
372
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, this.comment_clear_blank_lines_in_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
372
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, this.comment_clear_blank_lines_in_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
373
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
373
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
374
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT, this.comment_condensed_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
374
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_BLOCK_BOUNDARIES, this.comment_new_lines_at_block_boundaries ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
375
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT, this.comment_condensed_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
375
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_JAVADOC_BOUNDARIES, this.comment_new_lines_at_javadoc_boundaries ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
376
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
376
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
377
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
377
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
378
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
378
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
Lines 1105-1117 Link Here
1105
				this.comment_line_length = 80;
1105
				this.comment_line_length = 80;
1106
			}
1106
			}
1107
		}
1107
		}
1108
		final Object commentCondensedBlockCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_BLOCK_COMMENT);
1108
		final Object commentNewLinesAtBlockBoundariesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_BLOCK_BOUNDARIES);
1109
		if (commentCondensedBlockCommentOption != null) {
1109
		if (commentNewLinesAtBlockBoundariesOption != null) {
1110
			this.comment_condensed_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedBlockCommentOption);
1110
			this.comment_new_lines_at_block_boundaries = DefaultCodeFormatterConstants.TRUE.equals(commentNewLinesAtBlockBoundariesOption);
1111
		}
1111
		}
1112
		final Object commentCondensedJavadocCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CONDENSED_JAVADOC_COMMENT);
1112
		final Object commentNewLinesAtJavadocBoundariesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_JAVADOC_BOUNDARIES);
1113
		if (commentCondensedJavadocCommentOption != null) {
1113
		if (commentNewLinesAtJavadocBoundariesOption != null) {
1114
			this.comment_condensed_javadoc_comment = DefaultCodeFormatterConstants.TRUE.equals(commentCondensedJavadocCommentOption);
1114
			this.comment_new_lines_at_javadoc_boundaries = DefaultCodeFormatterConstants.TRUE.equals(commentNewLinesAtJavadocBoundariesOption);
1115
		}
1115
		}
1116
		final Object indentStatementsCompareToBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK);
1116
		final Object indentStatementsCompareToBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK);
1117
		if (indentStatementsCompareToBlockOption != null) {
1117
		if (indentStatementsCompareToBlockOption != null) {
Lines 2024-2029 Link Here
2024
		this.comment_indent_root_tags = true;
2024
		this.comment_indent_root_tags = true;
2025
		this.comment_insert_empty_line_before_root_tags = true;
2025
		this.comment_insert_empty_line_before_root_tags = true;
2026
		this.comment_insert_new_line_for_parameter = true;
2026
		this.comment_insert_new_line_for_parameter = true;
2027
		this.comment_new_lines_at_block_boundaries = true;
2028
		this.comment_new_lines_at_javadoc_boundaries = true;
2027
		this.comment_line_length = 80;
2029
		this.comment_line_length = 80;
2028
		this.continuation_indentation = 2;
2030
		this.continuation_indentation = 2;
2029
		this.continuation_indentation_for_array_initializer = 2;
2031
		this.continuation_indentation_for_array_initializer = 2;
Lines 2291-2296 Link Here
2291
		this.comment_indent_root_tags = true;
2293
		this.comment_indent_root_tags = true;
2292
		this.comment_insert_empty_line_before_root_tags = true;
2294
		this.comment_insert_empty_line_before_root_tags = true;
2293
		this.comment_insert_new_line_for_parameter = true;
2295
		this.comment_insert_new_line_for_parameter = true;
2296
		this.comment_new_lines_at_block_boundaries = true;
2297
		this.comment_new_lines_at_javadoc_boundaries = true;
2294
		this.comment_line_length = 80;
2298
		this.comment_line_length = 80;
2295
		this.continuation_indentation = 2;
2299
		this.continuation_indentation = 2;
2296
		this.continuation_indentation_for_array_initializer = 2;
2300
		this.continuation_indentation_for_array_initializer = 2;
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-5 / +5 lines)
Lines 1628-1634 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
		boolean newLinesAtBoundaries = this.formatter.preferences.comment_new_lines_at_block_boundaries;
1632
		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);
1633
		int firstLine = scannerLine;
1633
		int firstLine = scannerLine;
1634
		int lineNumber = scannerLine;
1634
		int lineNumber = scannerLine;
Lines 1688-1694 Link Here
1688
							this.column += tokensBuffer.length();
1688
							this.column += tokensBuffer.length();
1689
						}
1689
						}
1690
						// end of comment
1690
						// end of comment
1691
						if (!condensed) {
1691
						if (newLinesAtBoundaries) {
1692
							if (multiLines || hasMultiLines) {
1692
							if (multiLines || hasMultiLines) {
1693
						    	buffer.append(this.lineSeparator);
1693
						    	buffer.append(this.lineSeparator);
1694
						    	this.column = 1;
1694
						    	this.column = 1;
Lines 1739-1745 Link Here
1739
			int max;
1739
			int max;
1740
			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);
1741
			if (lastTextLine == -1) {
1741
			if (lastTextLine == -1) {
1742
				linesGap = condensed ? 0 : lineNumber - firstLine;
1742
				linesGap = newLinesAtBoundaries ? lineNumber - firstLine : 0;
1743
				max = 0;
1743
				max = 0;
1744
			} else {
1744
			} else {
1745
				linesGap = lineNumber - lastTextLine;
1745
				linesGap = lineNumber - lastTextLine;
Lines 1877-1883 Link Here
1877
	}
1877
	}
1878
1878
1879
	private void printBlockCommentHeaderLine(StringBuffer buffer) {
1879
	private void printBlockCommentHeaderLine(StringBuffer buffer) {
1880
		if (this.formatter.preferences.comment_condensed_block_comment) {
1880
		if (!this.formatter.preferences.comment_new_lines_at_block_boundaries) {
1881
			buffer.insert(0, ' ');
1881
			buffer.insert(0, ' ');
1882
			this.column++;
1882
			this.column++;
1883
		}
1883
		}
Lines 3283-3289 Link Here
3283
			printJavadocBlock(previousBlock);
3283
			printJavadocBlock(previousBlock);
3284
3284
3285
			// format the header and footer empty spaces
3285
			// format the header and footer empty spaces
3286
			int newLines = (!this.formatter.preferences.comment_condensed_javadoc_comment && (this.line > currentLine || javadoc.isMultiLine())) ? 1 : 0;
3286
			int newLines = (this.formatter.preferences.comment_new_lines_at_javadoc_boundaries && (this.line > currentLine || javadoc.isMultiLine())) ? 1 : 0;
3287
			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);
3288
			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);
3289
		}
3289
		}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-6 / +6 lines)
Lines 5564-5570 Link Here
5564
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=270209"
5564
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=270209"
5565
 */
5565
 */
5566
public void testBug270209_Block01() throws JavaModelException {
5566
public void testBug270209_Block01() throws JavaModelException {
5567
	this.formatterPrefs.comment_condensed_block_comment = true;
5567
	this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
5568
	String source = 
5568
	String source = 
5569
		"public interface X01 {\n" + 
5569
		"public interface X01 {\n" + 
5570
		"\n" + 
5570
		"\n" + 
Lines 5582-5588 Link Here
5582
	);
5582
	);
5583
}
5583
}
5584
public void testBug270209_Block02() throws JavaModelException {
5584
public void testBug270209_Block02() throws JavaModelException {
5585
	this.formatterPrefs.comment_condensed_block_comment = true;
5585
	this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
5586
	String source = 
5586
	String source = 
5587
		"public interface X02 {\n" + 
5587
		"public interface X02 {\n" + 
5588
		"\n" + 
5588
		"\n" + 
Lines 5602-5608 Link Here
5602
	);
5602
	);
5603
}
5603
}
5604
public void testBug270209_Block03() throws JavaModelException {
5604
public void testBug270209_Block03() throws JavaModelException {
5605
	this.formatterPrefs.comment_condensed_block_comment = true;
5605
	this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
5606
	String source = 
5606
	String source = 
5607
		"public interface X03 {\n" + 
5607
		"public interface X03 {\n" + 
5608
		"\n" + 
5608
		"\n" + 
Lines 5624-5630 Link Here
5624
	);
5624
	);
5625
}
5625
}
5626
public void testBug270209_Javadoc01() throws JavaModelException {
5626
public void testBug270209_Javadoc01() throws JavaModelException {
5627
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5627
	this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
5628
	String source = 
5628
	String source = 
5629
		"public interface X01 {\n" + 
5629
		"public interface X01 {\n" + 
5630
		"\n" + 
5630
		"\n" + 
Lines 5642-5648 Link Here
5642
	);
5642
	);
5643
}
5643
}
5644
public void testBug270209_Javadoc02() throws JavaModelException {
5644
public void testBug270209_Javadoc02() throws JavaModelException {
5645
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5645
	this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
5646
	String source = 
5646
	String source = 
5647
		"public interface X02 {\n" + 
5647
		"public interface X02 {\n" + 
5648
		"\n" + 
5648
		"\n" + 
Lines 5662-5668 Link Here
5662
	);
5662
	);
5663
}
5663
}
5664
public void testBug270209_Javadoc03() throws JavaModelException {
5664
public void testBug270209_Javadoc03() throws JavaModelException {
5665
	this.formatterPrefs.comment_condensed_javadoc_comment = true;
5665
	this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
5666
	String source = 
5666
	String source = 
5667
		"public interface X03 {\n" + 
5667
		"public interface X03 {\n" + 
5668
		"\n" + 
5668
		"\n" + 

Return to bug 270209