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

Collapse All | Expand All

(-)buildnotes_jdt-core.html (+40 lines)
Lines 48-53 Link Here
48
<br>Project org.eclipse.jdt.core v_A36
48
<br>Project org.eclipse.jdt.core v_A36
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A36">cvs</a>).
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A36">cvs</a>).
50
<h2>What's new in this drop</h2>
50
<h2>What's new in this drop</h2>
51
<ul>
52
<li>
53
Added a new formatter preferences to insert a new line after a label.
54
<p>
55
This new preference is controlled with the option:<br>
56
<code>DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL</code>
57
<pre>
58
/**
59
 * FORMATTER / Option to insert a new line after a label
60
 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_label"
61
 *     - possible values:   { INSERT, DO_NOT_INSERT }
62
 *     - default:           INSERT
63
 *
64
 * @see JavaCore#INSERT
65
 * @see JavaCore#DO_NOT_INSERT
66
 * @since 3.6
67
 */
68
</pre>
69
</p>
70
For example, the following snippet:
71
<pre>
72
public class X {
73
	void foo() {
74
		LABEL:for (int i = 0; i < 10; i++) {
75
		}
76
	}
77
}
78
</pre>
79
formatted with this preference activated, will produce the following output:
80
<pre>
81
public class X {
82
	void foo() {
83
		LABEL:
84
		for (int i = 0; i < 10; i++) {
85
		}
86
	}
87
}
88
</pre>
89
</li>
90
</ul>
51
91
52
<h3>Problem Reports Fixed</h3>
92
<h3>Problem Reports Fixed</h3>
53
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=295619">295619</a>
93
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=295619">295619</a>
(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+12 lines)
Lines 1155-1160 Link Here
1155
	public static final String FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_in_empty_type_declaration";	//$NON-NLS-1$
1155
	public static final String FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_in_empty_type_declaration";	//$NON-NLS-1$
1156
	/**
1156
	/**
1157
	 * <pre>
1157
	 * <pre>
1158
	 * FORMATTER / Option to insert a new line after a label
1159
	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_label"
1160
	 *     - possible values:   { INSERT, DO_NOT_INSERT }
1161
	 *     - default:           INSERT
1162
	 * </pre>
1163
	 * @see JavaCore#INSERT
1164
	 * @see JavaCore#DO_NOT_INSERT
1165
	 * @since 3.6
1166
	 */
1167
	public static final String FORMATTER_INSERT_NEW_LINE_AFTER_LABEL = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_label";	//$NON-NLS-1$	
1168
	/**
1169
	 * <pre>
1158
	 * FORMATTER / Option to insert a space after and in wilcard
1170
	 * FORMATTER / Option to insert a space after and in wilcard
1159
	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter"
1171
	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter"
1160
	 *     - possible values:   { INSERT, DO_NOT_INSERT }
1172
	 *     - possible values:   { INSERT, DO_NOT_INSERT }
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (+3 lines)
Lines 4012-4017 Link Here
4012
		if (this.preferences.insert_space_after_colon_in_labeled_statement) {
4012
		if (this.preferences.insert_space_after_colon_in_labeled_statement) {
4013
			this.scribe.space();
4013
			this.scribe.space();
4014
		}
4014
		}
4015
		if (this.preferences.insert_new_line_after_label) {
4016
			this.scribe.printNewLine();
4017
		}
4015
		final Statement statement = labeledStatement.statement;
4018
		final Statement statement = labeledStatement.statement;
4016
		statement.traverse(this, scope);
4019
		statement.traverse(this, scope);
4017
		if (statement instanceof Expression) {
4020
		if (statement instanceof Expression) {
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+6 lines)
Lines 139-144 Link Here
139
	public boolean insert_new_line_in_empty_enum_declaration;
139
	public boolean insert_new_line_in_empty_enum_declaration;
140
	public boolean insert_new_line_in_empty_method_body;
140
	public boolean insert_new_line_in_empty_method_body;
141
	public boolean insert_new_line_in_empty_type_declaration;
141
	public boolean insert_new_line_in_empty_type_declaration;
142
	public boolean insert_new_line_after_label;
142
	public boolean insert_space_after_and_in_type_parameter;
143
	public boolean insert_space_after_and_in_type_parameter;
143
	public boolean insert_space_after_assignment_operator;
144
	public boolean insert_space_after_assignment_operator;
144
	public boolean insert_space_after_at_in_annotation;
145
	public boolean insert_space_after_at_in_annotation;
Lines 418-423 Link Here
418
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_DECLARATION, this.insert_new_line_in_empty_enum_declaration? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
419
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_DECLARATION, this.insert_new_line_in_empty_enum_declaration? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
419
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY, this.insert_new_line_in_empty_method_body? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
420
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY, this.insert_new_line_in_empty_method_body? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
420
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, this.insert_new_line_in_empty_type_declaration? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
421
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, this.insert_new_line_in_empty_type_declaration? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
422
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL, this.insert_new_line_after_label? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
421
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AND_IN_TYPE_PARAMETER, this.insert_space_after_and_in_type_parameter? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
423
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AND_IN_TYPE_PARAMETER, this.insert_space_after_and_in_type_parameter? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
422
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, this.insert_space_after_assignment_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
424
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, this.insert_space_after_assignment_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
423
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AT_IN_ANNOTATION, this.insert_space_after_at_in_annotation? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
425
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AT_IN_ANNOTATION, this.insert_space_after_at_in_annotation? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
Lines 1192-1197 Link Here
1192
		if (insertNewLineInEmptyTypeDeclarationOption != null) {
1194
		if (insertNewLineInEmptyTypeDeclarationOption != null) {
1193
			this.insert_new_line_in_empty_type_declaration = JavaCore.INSERT.equals(insertNewLineInEmptyTypeDeclarationOption);
1195
			this.insert_new_line_in_empty_type_declaration = JavaCore.INSERT.equals(insertNewLineInEmptyTypeDeclarationOption);
1194
		}
1196
		}
1197
		final Object insertNewLineAfterLabelOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL);
1198
		if (insertNewLineAfterLabelOption != null) {
1199
			this.insert_new_line_after_label = JavaCore.INSERT.equals(insertNewLineAfterLabelOption);
1200
		}
1195
		final Object insertSpaceAfterAndInWildcardOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AND_IN_TYPE_PARAMETER);
1201
		final Object insertSpaceAfterAndInWildcardOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AND_IN_TYPE_PARAMETER);
1196
		if (insertSpaceAfterAndInWildcardOption != null) {
1202
		if (insertSpaceAfterAndInWildcardOption != null) {
1197
			this.insert_space_after_and_in_type_parameter = JavaCore.INSERT.equals(insertSpaceAfterAndInWildcardOption);
1203
			this.insert_space_after_and_in_type_parameter = JavaCore.INSERT.equals(insertSpaceAfterAndInWildcardOption);
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+23 lines)
Lines 10622-10625 Link Here
10622
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10622
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
10623
	runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10623
	runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10624
}
10624
}
10625
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150741
10626
public void test724() {
10627
	this.formatterPrefs.insert_new_line_after_label = true;
10628
	String source =
10629
		"public class X {\n" + 
10630
		"	public static void main(String[] args) {\n" + 
10631
		"		LABEL:for (int i = 0; i < 10; i++) {\n" + 
10632
		"		}\n" + 
10633
		"	}\n" + 
10634
		"\n" + 
10635
		"}\n" + 
10636
		"";
10637
	formatSource(source,
10638
		"public class X {\n" + 
10639
		"	public static void main(String[] args) {\n" + 
10640
		"		LABEL:\n" + 
10641
		"		for (int i = 0; i < 10; i++) {\n" + 
10642
		"		}\n" + 
10643
		"	}\n" + 
10644
		"\n" + 
10645
		"}\n"
10646
	);
10647
}
10625
}
10648
}

Return to bug 150741