### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.7461
diff -u -r1.7461 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 18 May 2010 18:12:12 -0000 1.7461
+++ buildnotes_jdt-core.html 20 May 2010 09:03:15 -0000
@@ -48,9 +48,60 @@
Project org.eclipse.jdt.core v_A54
(cvs).
+This new preference is controlled with the option:
+DefaultCodeFormatterConstants.FORMATTER_KEEP_NESTED_EXPRESSIONS_ON_ONE_LINE
++/** + * FORMATTER / Option to wrap outer expressions in nested expressions + * - option id: "org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" + * - possible values: { TRUE, FALSE } + * - default: TRUE + * + * This option changes the formatter behavior when nested method calls are encountered. + * Since 3.6, the formatter tries to wrap outermost method calls first to have a better output. + * For example, let's say we are using the Eclipse built-in profile with a max line width=40+space for tab policy. + * Then consider the following snippet: + * + * public class X01 { + * void test() { + * foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8)); + * } + * } + * + * With this new strategy, the formatter will wrap the line earlier, between the arguments of the message call + * for this example, and then it will allow to keep each nested call on a single line. + * Hence, the output will be: + * + * public class X01 { + * void test() { + * foo(bar(1, 2, 3, 4), + * bar(5, 6, 7, 8)); + * } + * } + * + * Important notes: + * 1. This new behavior is automatically activated (ie. the default value for this preference is {@link #TRUE}). + * If the backward compatibility regarding previous versions formatter behavior (ie. before 3.6 version) is necessary, + * then the preference needs to be set to {@link #FALSE} to retrieve the previous formatter behavior. + * 2. The new strategy currently only applies to nested method calls, but might be extended to other nested expressions in future versions + * + * @see #TRUE + * @see #FALSE + * @since 3.6 + */ ++See bug 313524 for more details. +
+ * FORMATTER / Option to wrap outer expressions in nested expressions + * - option id: "org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" + * - possible values: { TRUE, FALSE } + * - default: TRUE + *+ *
+ * This option changes the formatter behavior when nested method calls are encountered. + * Since 3.6, the formatter tries to wrap outermost method calls first to have a better output.
+ *For example, let's say we are using the Eclipse built-in profile with a max line width=40+space for tab policy. + * Then consider the following snippet:
+ *+ * public class X01 { + * void test() { + * foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8)); + * } + * } + *+ *
With this new strategy, the formatter will wrap the line earlier, between the arguments of the message call + * for this example, and then it will allow to keep each nested call on a single line.
+ *Hence, the output will be:
+ *+ * public class X01 { + * void test() { + * foo(bar(1, 2, 3, 4), + * bar(5, 6, 7, 8)); + * } + * } + *+ *
+ *
+ *Important notes:
+ ** FORMATTER / The wrapping is done by indenting by one compare to the current indentation. ** @since 3.0 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.234 diff -u -r1.234 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 6 May 2010 16:29:32 -0000 1.234 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 20 May 2010 09:03:16 -0000 @@ -1364,7 +1364,9 @@ } startingPositionInCascade = 2; } - int tieBreakRule = size-startingPositionInCascade > 2 ? Alignment.R_OUTERMOST : Alignment.R_INNERMOST; + int tieBreakRule = this.preferences.wrap_outer_expressions_when_nested && size-startingPositionInCascade > 2 + ? Alignment.R_OUTERMOST + : Alignment.R_INNERMOST; Alignment cascadingMessageSendAlignment = this.scribe.createAlignment( Alignment.CASCADING_MESSAGE_SEND, @@ -1676,7 +1678,7 @@ Alignment messageAlignment) { if (messageAlignment != null) { - if (messageAlignment.canAlign()) { + if (!this.preferences.wrap_outer_expressions_when_nested || messageAlignment.canAlign()) { this.scribe.alignFragment(messageAlignment, 0); } this.scribe.printNextToken(TerminalTokens.TokenNameDOT); 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.107 diff -u -r1.107 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 6 May 2010 11:11:27 -0000 1.107 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 20 May 2010 09:03:17 -0000 @@ -325,6 +325,7 @@ public int tab_char; public boolean use_tabs_only_for_leading_indentations; public boolean wrap_before_binary_operator; + public boolean wrap_outer_expressions_when_nested; public int initial_indentation_level; public String line_separator; @@ -622,6 +623,7 @@ options.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, this.disabling_tag == null ? Util.EMPTY_STRING : new String(this.disabling_tag)); options.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, this.enabling_tag == null ? Util.EMPTY_STRING : new String(this.enabling_tag)); options.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, this.use_tags ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_OUTER_EXPRESSIONS_WHEN_NESTED, this.wrap_outer_expressions_when_nested ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); return options; } @@ -1997,6 +1999,10 @@ } } } + final Object wrapWrapOuterExpressionsWhenNestedOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_OUTER_EXPRESSIONS_WHEN_NESTED); + if (wrapWrapOuterExpressionsWhenNestedOption != null) { + this.wrap_outer_expressions_when_nested = DefaultCodeFormatterConstants.TRUE.equals(wrapWrapOuterExpressionsWhenNestedOption); + } } /** @@ -2310,6 +2316,7 @@ this.use_tags = false; this.disabling_tag = DEFAULT_DISABLING_TAG; this.enabling_tag = DEFAULT_ENABLING_TAG; + this.wrap_outer_expressions_when_nested = true; } public void setEclipseDefaultSettings() { @@ -2584,5 +2591,6 @@ this.use_tags = false; this.disabling_tag = DEFAULT_DISABLING_TAG; this.enabling_tag = DEFAULT_ENABLING_TAG; + this.wrap_outer_expressions_when_nested = true; } } Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v retrieving revision 1.209 diff -u -r1.209 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 6 May 2010 15:22:52 -0000 1.209 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 20 May 2010 09:03:18 -0000 @@ -1258,6 +1258,38 @@ } public void handleLineTooLong() { + if (this.formatter.preferences.wrap_outer_expressions_when_nested) { + handleLineTooLongSmartly(); + return; + } + // search for closest breakable alignment, using tiebreak rules + // look for outermost breakable one + int relativeDepth = 0, outerMostDepth = -1; + Alignment targetAlignment = this.currentAlignment; + while (targetAlignment != null){ + if (targetAlignment.tieBreakRule == Alignment.R_OUTERMOST && targetAlignment.couldBreak()){ + outerMostDepth = relativeDepth; + } + targetAlignment = targetAlignment.enclosing; + relativeDepth++; + } + if (outerMostDepth >= 0) { + throw new AlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth); + } + // look for innermost breakable one + relativeDepth = 0; + targetAlignment = this.currentAlignment; + while (targetAlignment != null){ + if (targetAlignment.couldBreak()){ + throw new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth); + } + targetAlignment = targetAlignment.enclosing; + relativeDepth++; + } + // did not find any breakable location - proceed + } + + private void handleLineTooLongSmartly() { // search for closest breakable alignment, using tiebreak rules // look for outermost breakable one int relativeDepth = 0, outerMostDepth = -1; #P org.eclipse.releng Index: apiexclude/exclude_list.txt =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.releng/apiexclude/exclude_list.txt,v retrieving revision 1.66 diff -u -r1.66 exclude_list.txt --- apiexclude/exclude_list.txt 19 May 2010 17:36:28 -0000 1.66 +++ apiexclude/exclude_list.txt 20 May 2010 09:03:20 -0000 @@ -284,4 +284,4 @@ org.eclipse.jdt.core(3.6.0):org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_USE_ON_OFF_TAGS # JDT/Core (bug 313524) -org.eclipse.jdt.core(3.6.0):org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_KEEP_NESTED_EXPRESSIONS_ON_ONE_LINE +org.eclipse.jdt.core(3.6.0):org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_WRAP_OUTER_EXPRESSIONS_WHEN_NESTED