### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v retrieving revision 1.98 diff -u -r1.98 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 27 Aug 2009 15:27:02 -0000 1.98 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 17 Feb 2010 14:41:33 -0000 @@ -1155,6 +1155,18 @@ 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$ /** *
+ * FORMATTER / Option to insert a new line after a label + * - option id: "org.eclipse.jdt.core.formatter.insert_new_line_after_label" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + *+ * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.6 + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_LABEL = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_label"; //$NON-NLS-1$ + /** + *
* FORMATTER / Option to insert a space after and in wilcard * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" * - possible values: { INSERT, DO_NOT_INSERT } Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.225 diff -u -r1.225 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 12 Feb 2010 09:51:08 -0000 1.225 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 17 Feb 2010 14:41:34 -0000 @@ -4012,6 +4012,9 @@ if (this.preferences.insert_space_after_colon_in_labeled_statement) { this.scribe.space(); } + if (this.preferences.insert_new_line_after_label) { + this.scribe.printNewLine(); + } final Statement statement = labeledStatement.statement; statement.traverse(this, scope); if (statement instanceof Expression) { Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v retrieving revision 1.94 diff -u -r1.94 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 8 Dec 2008 15:54:27 -0000 1.94 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 17 Feb 2010 14:41:35 -0000 @@ -139,6 +139,7 @@ public boolean insert_new_line_in_empty_enum_declaration; public boolean insert_new_line_in_empty_method_body; public boolean insert_new_line_in_empty_type_declaration; + public boolean insert_new_line_after_label; public boolean insert_space_after_and_in_type_parameter; public boolean insert_space_after_assignment_operator; public boolean insert_space_after_at_in_annotation; @@ -418,6 +419,7 @@ 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); 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); 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); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL, this.insert_new_line_after_label? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); 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); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, this.insert_space_after_assignment_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AT_IN_ANNOTATION, this.insert_space_after_at_in_annotation? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); @@ -1192,6 +1194,10 @@ if (insertNewLineInEmptyTypeDeclarationOption != null) { this.insert_new_line_in_empty_type_declaration = JavaCore.INSERT.equals(insertNewLineInEmptyTypeDeclarationOption); } + final Object insertNewLineAfterLabelOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL); + if (insertNewLineAfterLabelOption != null) { + this.insert_new_line_after_label = JavaCore.INSERT.equals(insertNewLineAfterLabelOption); + } final Object insertSpaceAfterAndInWildcardOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AND_IN_TYPE_PARAMETER); if (insertSpaceAfterAndInWildcardOption != null) { this.insert_space_after_and_in_type_parameter = JavaCore.INSERT.equals(insertSpaceAfterAndInWildcardOption); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v retrieving revision 1.254 diff -u -r1.254 FormatterRegressionTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 14 Oct 2009 15:50:54 -0000 1.254 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 17 Feb 2010 14:41:40 -0000 @@ -10622,4 +10622,27 @@ DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions); runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150741 +public void testONLY_724() { + this.formatterPrefs.insert_new_line_after_label = true; + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " LABEL:for (int i = 0; i < 10; i++) {\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + ""; + formatSource(source, + "public class X {\n" + + " public static void main(String[] args) {\n" + + " LABEL:\n" + + " for (int i = 0; i < 10; i++) {\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + ); +} }