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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+13 lines)
Lines 673-678 Link Here
673
673
674
	/**
674
	/**
675
	 * <pre>
675
	 * <pre>
676
	 * FORMATTER / Option to control whether comments appearing at the end of lines should preserve their indentation or have that indentation replaced with a single space
677
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.preserve_trailing_line_comment_indentation"
678
	 *     - possible values:   { TRUE, FALSE }
679
	 *     - default:           TRUE
680
	 * </pre>
681
	 * @see #TRUE
682
	 * @see #FALSE
683
	 * @since 3.7
684
	 */
685
	public final static String FORMATTER_COMMENT_PRESERVE_TRAILING_LINE_COMMENT_INDENTATION = "org.eclipse.jdt.core.formatter.comment.preserve_trailing_line_comment_indentation"; //$NON-NLS-1$
686
687
	/**
688
	 * <pre>
676
	 * FORMATTER / Option to control whether multiple lines comments are formatted
689
	 * FORMATTER / Option to control whether multiple lines comments are formatted
677
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_block_comments"
690
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_block_comments"
678
	 *     - possible values:   { TRUE, FALSE }
691
	 *     - possible values:   { TRUE, FALSE }
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+6 lines)
Lines 115-120 Link Here
115
	public boolean comment_indent_root_tags;
115
	public boolean comment_indent_root_tags;
116
	public boolean comment_insert_empty_line_before_root_tags;
116
	public boolean comment_insert_empty_line_before_root_tags;
117
	public boolean comment_insert_new_line_for_parameter;
117
	public boolean comment_insert_new_line_for_parameter;
118
	public boolean comment_preserve_trailing_line_comment_indentation;
118
	public int comment_line_length;
119
	public int comment_line_length;
119
120
120
	public boolean use_tags;
121
	public boolean use_tags;
Lines 398-403 Link Here
398
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS, this.comment_indent_root_tags ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
399
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS, this.comment_indent_root_tags ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
399
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, this.comment_insert_empty_line_before_root_tags ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
400
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, this.comment_insert_empty_line_before_root_tags ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
400
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER, this.comment_insert_new_line_for_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
401
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER, this.comment_insert_new_line_for_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
402
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_TRAILING_LINE_COMMENT_INDENTATION, this.comment_preserve_trailing_line_comment_indentation ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
401
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length));
403
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length));
402
		options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation));
404
		options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation));
403
		options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, Integer.toString(this.continuation_indentation_for_array_initializer));
405
		options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, Integer.toString(this.continuation_indentation_for_array_initializer));
Lines 1131-1136 Link Here
1131
		if (commentInsertNewLineForParameterOption != null) {
1133
		if (commentInsertNewLineForParameterOption != null) {
1132
			this.comment_insert_new_line_for_parameter = JavaCore.INSERT.equals(commentInsertNewLineForParameterOption);
1134
			this.comment_insert_new_line_for_parameter = JavaCore.INSERT.equals(commentInsertNewLineForParameterOption);
1133
		}
1135
		}
1136
		final Object commentPreserveTrailingLineCommentIndentationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_TRAILING_LINE_COMMENT_INDENTATION);
1137
		if (commentPreserveTrailingLineCommentIndentationOption != null) {
1138
			this.comment_preserve_trailing_line_comment_indentation = DefaultCodeFormatterConstants.TRUE.equals(commentPreserveTrailingLineCommentIndentationOption);
1139
		}
1134
		final Object commentLineLengthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH);
1140
		final Object commentLineLengthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH);
1135
		if (commentLineLengthOption != null) {
1141
		if (commentLineLengthOption != null) {
1136
			try {
1142
			try {
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-1 / +5 lines)
Lines 2810-2816 Link Here
2810
		
2810
		
2811
		// Add pending space if necessary
2811
		// Add pending space if necessary
2812
    	if (this.pendingSpace) {
2812
    	if (this.pendingSpace) {
2813
    		addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
2813
    		if (this.formatter.preferences.comment_preserve_trailing_line_comment_indentation) {
2814
    			addInsertEdit(currentTokenStartPosition, new String(this.lastLineComment.leadingSpaces));
2815
    		} else {
2816
    			addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
2817
    		}
2814
    	}
2818
    	}
2815
    	this.needSpace = false;
2819
    	this.needSpace = false;
2816
    	this.pendingSpace = false;
2820
    	this.pendingSpace = false;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+32 lines)
Lines 10429-10432 Link Here
10429
		"}\n"
10429
		"}\n"
10430
	);
10430
	);
10431
}
10431
}
10432
10433
/**
10434
 * @bug 282988: [formatter] Option to align single-line comments in a column
10435
 * @test Ensure that with line comment formatting turned off comment alignment doesn't change 
10436
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988"
10437
 */
10438
public void testBug282988() throws Exception {
10439
	this.formatterPrefs.comment_preserve_trailing_line_comment_indentation = true;
10440
	String source =
10441
		"package test;\n" +
10442
		"\n" +
10443
		"public class FormatterError {\n" +
10444
		"	public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" +
10445
		"		buffer.clear();\n" +
10446
		"		buffer.putLong(0);     // backlink to previous version of this object\n" +
10447
		"		buffer.putInt(1);      // version identifier\n" +
10448
		"		buffer.flip();         // prepare to write\n" +
10449
		"	}\n" +
10450
		"}\n";
10451
	formatSource(source,
10452
		"package test;\n" +
10453
		"\n" +
10454
		"public class FormatterError {\n" +
10455
		"	public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" +
10456
		"		buffer.clear();\n" +
10457
		"		buffer.putLong(0);     // backlink to previous version of this object\n" +
10458
		"		buffer.putInt(1);      // version identifier\n" +
10459
		"		buffer.flip();         // prepare to write\n" +
10460
		"	}\n" +
10461
		"}\n"
10462
    );
10463
}
10432
}
10464
}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+29 lines)
Lines 10981-10984 Link Here
10981
		"}"
10981
		"}"
10982
	);
10982
	);
10983
}
10983
}
10984
public void test734() {
10985
	this.formatterPrefs = null;
10986
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_TRAILING_LINE_COMMENT_INDENTATION, DefaultCodeFormatterConstants.TRUE);
10987
	String source =
10988
		"package p;\n" + 
10989
		"\n" + 
10990
		"public class Comment {\n" + 
10991
		"	public static void main(String[] args) {\n" +
10992
		"		//                         internal indentation\n" +
10993
		"		int i = 1;				// tabs\n" + 
10994
		"		int j = 2;              // spaces\n" +
10995
		"		int k = 3;			    // mixed tabs and spaces\n" +
10996
		"		System.out.print(i);	/* does not affect block comments */\n" +
10997
		"	}\n" + 
10998
		"}\n";
10999
	formatSource(source,
11000
		"package p;\n" + 
11001
		"\n" + 
11002
		"public class Comment {\n" + 
11003
		"	public static void main(String[] args) {\n" +
11004
		"		// internal indentation\n" +
11005
		"		int i = 1;				// tabs\n" + 
11006
		"		int j = 2;              // spaces\n" +
11007
		"		int k = 3;			    // mixed tabs and spaces\n" +
11008
		"		System.out.print(i); /* does not affect block comments */\n" +
11009
		"	}\n" + 
11010
		"}\n"
11011
	);
11012
}
10984
}
11013
}

Return to bug 282988