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 (-3 / +17 lines)
Lines 1-13 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation  - initial API and implementation
10
 *     Brock Janiczak - Contribution for bug 150741
10
 *     Brock Janiczak   - Contribution for bug 150741
11
 *     Ray V. (voidstar@gmail.com) - Contribution for bug 282988
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.core.formatter;
13
package org.eclipse.jdt.core.formatter;
13
14
Lines 673-678 Link Here
673
674
674
	/**
675
	/**
675
	 * <pre>
676
	 * <pre>
677
	 * FORMATTER / Option to control whether the white space between code and line comments should be preserved or replaced with a single space
678
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments"
679
	 *     - possible values:   { TRUE, FALSE }
680
	 *     - default:           FALSE
681
	 * </pre>
682
	 * @see #TRUE
683
	 * @see #FALSE
684
	 * @since 3.7
685
	 */
686
	public final static String FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT = "org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments"; //$NON-NLS-1$
687
688
	/**
689
	 * <pre>
676
	 * FORMATTER / Option to control whether multiple lines comments are formatted
690
	 * FORMATTER / Option to control whether multiple lines comments are formatted
677
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_block_comments"
691
	 *     - option id:         "org.eclipse.jdt.core.formatter.comment.format_block_comments"
678
	 *     - possible values:   { TRUE, FALSE }
692
	 *     - possible values:   { TRUE, FALSE }
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-1 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak - Contribution for bug 150741
10
 *     Brock Janiczak - Contribution for bug 150741
11
 *     Ray V. (voidstar@gmail.com) - Contribution for bug 282988
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.formatter;
13
package org.eclipse.jdt.internal.formatter;
13
14
Lines 115-120 Link Here
115
	public boolean comment_indent_root_tags;
116
	public boolean comment_indent_root_tags;
116
	public boolean comment_insert_empty_line_before_root_tags;
117
	public boolean comment_insert_empty_line_before_root_tags;
117
	public boolean comment_insert_new_line_for_parameter;
118
	public boolean comment_insert_new_line_for_parameter;
119
	public boolean comment_preserve_white_space_between_code_and_line_comments;
118
	public int comment_line_length;
120
	public int comment_line_length;
119
121
120
	public boolean use_tags;
122
	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);
400
		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);
401
		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);
402
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER, this.comment_insert_new_line_for_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
403
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, this.comment_preserve_white_space_between_code_and_line_comments ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
401
		options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length));
404
		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));
405
		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));
406
		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) {
1134
		if (commentInsertNewLineForParameterOption != null) {
1132
			this.comment_insert_new_line_for_parameter = JavaCore.INSERT.equals(commentInsertNewLineForParameterOption);
1135
			this.comment_insert_new_line_for_parameter = JavaCore.INSERT.equals(commentInsertNewLineForParameterOption);
1133
		}
1136
		}
1137
		final Object commentPreserveWhiteSpaceBetweenCodeAndLineCommentsOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT);
1138
		if (commentPreserveWhiteSpaceBetweenCodeAndLineCommentsOption != null) {
1139
			this.comment_preserve_white_space_between_code_and_line_comments = DefaultCodeFormatterConstants.TRUE.equals(commentPreserveWhiteSpaceBetweenCodeAndLineCommentsOption);
1140
		}
1134
		final Object commentLineLengthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH);
1141
		final Object commentLineLengthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH);
1135
		if (commentLineLengthOption != null) {
1142
		if (commentLineLengthOption != null) {
1136
			try {
1143
			try {
Lines 2132-2137 Link Here
2132
		this.comment_new_lines_at_block_boundaries = true;
2139
		this.comment_new_lines_at_block_boundaries = true;
2133
		this.comment_new_lines_at_javadoc_boundaries = true;
2140
		this.comment_new_lines_at_javadoc_boundaries = true;
2134
		this.comment_line_length = 80;
2141
		this.comment_line_length = 80;
2142
		this.comment_preserve_white_space_between_code_and_line_comments= false; 
2135
		this.continuation_indentation = 2;
2143
		this.continuation_indentation = 2;
2136
		this.continuation_indentation_for_array_initializer = 2;
2144
		this.continuation_indentation_for_array_initializer = 2;
2137
		this.blank_lines_after_imports = 0;
2145
		this.blank_lines_after_imports = 0;
Lines 2410-2415 Link Here
2410
		this.comment_new_lines_at_block_boundaries = true;
2418
		this.comment_new_lines_at_block_boundaries = true;
2411
		this.comment_new_lines_at_javadoc_boundaries = true;
2419
		this.comment_new_lines_at_javadoc_boundaries = true;
2412
		this.comment_line_length = 80;
2420
		this.comment_line_length = 80;
2421
		this.comment_preserve_white_space_between_code_and_line_comments= false; 
2413
		this.continuation_indentation = 2;
2422
		this.continuation_indentation = 2;
2414
		this.continuation_indentation_for_array_initializer = 2;
2423
		this.continuation_indentation_for_array_initializer = 2;
2415
		this.blank_lines_after_imports = 1;
2424
		this.blank_lines_after_imports = 1;
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-1 / +6 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ray V. (voidstar@gmail.com) - Contribution for bug 282988
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
package org.eclipse.jdt.internal.formatter;
12
13
Lines 2810-2816 Link Here
2810
		
2811
		
2811
		// Add pending space if necessary
2812
		// Add pending space if necessary
2812
    	if (this.pendingSpace) {
2813
    	if (this.pendingSpace) {
2813
    		addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
2814
    		if (this.formatter.preferences.comment_preserve_white_space_between_code_and_line_comments) {
2815
    			addInsertEdit(currentTokenStartPosition, new String(this.lastLineComment.leadingSpaces));
2816
    		} else {
2817
    			addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
2818
    		}
2814
    	}
2819
    	}
2815
    	this.needSpace = false;
2820
    	this.needSpace = false;
2816
    	this.pendingSpace = false;
2821
    	this.pendingSpace = false;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (-1 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ray V. (voidstar@gmail.com) - Contribution for bug 282988
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.formatter;
12
package org.eclipse.jdt.core.tests.formatter;
12
13
Lines 10429-10432 Link Here
10429
		"}\n"
10430
		"}\n"
10430
	);
10431
	);
10431
}
10432
}
10433
10434
/**
10435
 * @bug 282988: [formatter] Option to align single-line comments in a column
10436
 * @test Ensure that with line comment formatting turned off comment alignment doesn't change 
10437
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988"
10438
 */
10439
public void testBug282988() throws Exception {
10440
	this.formatterPrefs.comment_preserve_white_space_between_code_and_line_comments = true;
10441
	String source =
10442
		"package test;\n" +
10443
		"\n" +
10444
		"public class FormatterError {\n" +
10445
		"	public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" +
10446
		"		buffer.clear();\n" +
10447
		"		buffer.putLong(0);     // backlink to previous version of this object\n" +
10448
		"		buffer.putInt(1);      // version identifier\n" +
10449
		"		buffer.flip();         // prepare to write\n" +
10450
		"	}\n" +
10451
		"}\n";
10452
	formatSource(source,
10453
		"package test;\n" +
10454
		"\n" +
10455
		"public class FormatterError {\n" +
10456
		"	public void storeSomething(java.nio.ByteBuffer buffer) throws Exception {\n" +
10457
		"		buffer.clear();\n" +
10458
		"		buffer.putLong(0);     // backlink to previous version of this object\n" +
10459
		"		buffer.putInt(1);      // version identifier\n" +
10460
		"		buffer.flip();         // prepare to write\n" +
10461
		"	}\n" +
10462
		"}\n"
10463
    );
10464
}
10432
}
10465
}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-3 / +124 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak - Contribution for bug 150741
10
 *     Brock Janiczak - Contribution for bug 150741
11
 *     Ray V. (voidstar@gmail.com) - Contribution for bug 282988
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.formatter;
13
package org.eclipse.jdt.core.tests.formatter;
13
14
Lines 61-68 Link Here
61
	Map formatterOptions;
62
	Map formatterOptions;
62
63
63
	static {
64
	static {
64
//		TESTS_NUMBERS = new int[] { 730 };
65
//		TESTS_NUMBERS = new int[] { 736 };
65
//		TESTS_RANGE = new int[] { 730, -1 };
66
		TESTS_RANGE = new int[] { 734, -1 };
66
	}
67
	}
67
	public static Test suite() {
68
	public static Test suite() {
68
		return buildModelTestSuite(FormatterRegressionTests.class);
69
		return buildModelTestSuite(FormatterRegressionTests.class);
Lines 10981-10984 Link Here
10981
		"}"
10982
		"}"
10982
	);
10983
	);
10983
}
10984
}
10985
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988
10986
public void test734() {
10987
	this.formatterPrefs = null;
10988
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.TRUE);
10989
	String source =
10990
		"package p;\n" + 
10991
		"\n" + 
10992
		"public class Comment {\n" + 
10993
		"	public static void main(String[] args) {\n" +
10994
		"		//                         internal indentation\n" +
10995
		"		int i = 1;				// tabs\n" + 
10996
		"		int j = 2;              // spaces\n" +
10997
		"		int k = 3;			    // mixed tabs and spaces\n" +
10998
		"		System.out.print(i);	/* does not affect block comments */\n" +
10999
		"	}\n" + 
11000
		"}\n";
11001
	formatSource(source,
11002
		"package p;\n" + 
11003
		"\n" + 
11004
		"public class Comment {\n" + 
11005
		"	public static void main(String[] args) {\n" +
11006
		"		// internal indentation\n" +
11007
		"		int i = 1;				// tabs\n" + 
11008
		"		int j = 2;              // spaces\n" +
11009
		"		int k = 3;			    // mixed tabs and spaces\n" +
11010
		"		System.out.print(i); /* does not affect block comments */\n" +
11011
		"	}\n" + 
11012
		"}\n"
11013
	);
11014
}
11015
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988
11016
public void test735() {
11017
	this.formatterPrefs = null;
11018
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.FALSE);
11019
	String source =
11020
		"package p;\n" + 
11021
		"\n" + 
11022
		"public class Comment {\n" + 
11023
		"	public static void main(String[] args) {\n" +
11024
		"		//                         internal indentation\n" +
11025
		"		int i = 1;				// tabs\n" + 
11026
		"		int j = 2;              // spaces\n" +
11027
		"		int k = 3;			    // mixed tabs and spaces\n" +
11028
		"		System.out.print(i);	/* does not affect block comments */\n" +
11029
		"	}\n" + 
11030
		"}\n";
11031
	formatSource(source,
11032
		"package p;\n" + 
11033
		"\n" + 
11034
		"public class Comment {\n" + 
11035
		"	public static void main(String[] args) {\n" +
11036
		"		// internal indentation\n" +
11037
		"		int i = 1; // tabs\n" + 
11038
		"		int j = 2; // spaces\n" +
11039
		"		int k = 3; // mixed tabs and spaces\n" +
11040
		"		System.out.print(i); /* does not affect block comments */\n" +
11041
		"	}\n" + 
11042
		"}\n"
11043
	);
11044
}
11045
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988
11046
public void test736() {
11047
	this.formatterPrefs = null;
11048
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.TRUE);
11049
	String source =
11050
		"package p;\n" + 
11051
		"\n" + 
11052
		"public class Comment {\n" + 
11053
		"	public static void main(String[] args) {\n" +
11054
		"		//                         internal indentation\n" +
11055
		"		int i = 1;// tabs\n" + 
11056
		"		int j = 2;// spaces\n" +
11057
		"		int k = 3;// mixed tabs and spaces\n" +
11058
		"		System.out.print(i);	/* does not affect block comments */\n" +
11059
		"	}\n" + 
11060
		"}\n";
11061
	formatSource(source,
11062
		"package p;\n" + 
11063
		"\n" + 
11064
		"public class Comment {\n" + 
11065
		"	public static void main(String[] args) {\n" +
11066
		"		// internal indentation\n" +
11067
		"		int i = 1;// tabs\n" + 
11068
		"		int j = 2;// spaces\n" +
11069
		"		int k = 3;// mixed tabs and spaces\n" +
11070
		"		System.out.print(i); /* does not affect block comments */\n" +
11071
		"	}\n" + 
11072
		"}\n"
11073
	);
11074
}
11075
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282988
11076
public void test737() {
11077
	this.formatterPrefs = null;
11078
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.FALSE);
11079
	String source =
11080
		"package p;\n" + 
11081
		"\n" + 
11082
		"public class Comment {\n" + 
11083
		"	public static void main(String[] args) {\n" +
11084
		"		//                         internal indentation\n" +
11085
		"		int i = 1;// tabs\n" + 
11086
		"		int j = 2;// spaces\n" +
11087
		"		int k = 3;// mixed tabs and spaces\n" +
11088
		"		System.out.print(i);	/* does not affect block comments */\n" +
11089
		"	}\n" + 
11090
		"}\n";
11091
	formatSource(source,
11092
		"package p;\n" + 
11093
		"\n" + 
11094
		"public class Comment {\n" + 
11095
		"	public static void main(String[] args) {\n" +
11096
		"		// internal indentation\n" +
11097
		"		int i = 1;// tabs\n" + 
11098
		"		int j = 2;// spaces\n" +
11099
		"		int k = 3;// mixed tabs and spaces\n" +
11100
		"		System.out.print(i); /* does not affect block comments */\n" +
11101
		"	}\n" + 
11102
		"}\n"
11103
	);
11104
}
10984
}
11105
}

Return to bug 282988