Bug 313524 - [formatter] Add preference for improved lines wrapping in nested method calls
Summary: [formatter] Add preference for improved lines wrapping in nested method calls
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.6 RC2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: readme
Depends on:
Blocks: 313586
  Show dependency tree
 
Reported: 2010-05-19 09:57 EDT by Dani Megert CLA
Modified: 2018-04-17 23:33 EDT (History)
10 users (show)

See Also:
daniel_megert: pmc_approved+
daniel_megert: review+
srikanth_sankaran: review+


Attachments
Proposed patch (70.24 KB, patch)
2010-05-19 13:08 EDT, Frederic Fusier CLA
no flags Details | Diff
New proposed patch + doc (11.67 KB, patch)
2010-05-20 04:16 EDT, Frederic Fusier CLA
daniel_megert: review+
Details | Diff
Previous patch + incorporated my comments (12.35 KB, patch)
2010-05-20 05:05 EDT, Dani Megert CLA
no flags Details | Diff
previous patch + missing tests (74.23 KB, patch)
2010-05-20 05:15 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2010-05-19 09:57:28 EDT
3.6 M7.

See bug 59891 for details. Possible name of the preference:
[ ] Try to keep nested expressions on one line
Comment 1 Laurent Goubet CLA 2010-05-19 10:01:18 EDT
I'll re-vote here for the same,
+1 for "Try to keep nested expressions on one line"


For the sake of avoiding full reading of bug 59891 , the five proposed choices for now are

* "Avoid wrapping nested expressions if possible"
* "Try to keep nested expressions on one line"
* "Allow aesthetic wrapping" (general)
* "Improve message sends wrapping" (msg send specific)
* "Improve message sends wrapping (tries to keep nested expressions on one line)"
Comment 2 Olivier Thomann CLA 2010-05-19 10:04:34 EDT
This will need PMC approval as the new preference is an API constant.
Comment 3 Dani Megert CLA 2010-05-19 10:07:27 EDT
>This will need PMC approval as the new preference is an API constant.
+1.
Comment 4 Frederic Fusier CLA 2010-05-19 10:10:26 EDT
(In reply to comment #0)
> 3.6 M7.
> 
> See bug 59891 for details. Possible name of the preference:
> [ ] Try to keep nested expressions on one line

I agree that words like "improve" or "aesthetic" might be not enough objective to precisely describe what is the intended behavior... So, I agree with this proposal.

Note that the default value for this preference will be unset, to let users
give a try with the new formatter behavior in this area. Users who will not
appreciate it or need to keep the old behavior, will need to explicitly check
this preference to cancel the fix for this current bug...

Will this make everyone happy?
Comment 5 Frederic Fusier CLA 2010-05-19 10:11:25 EDT
(In reply to comment #4)
>...
> this preference to cancel the fix for bug 59891...
> 
should be read instead
Comment 6 Laurent Goubet CLA 2010-05-19 10:14:44 EDT
(In reply to comment #4)
> (In reply to comment #0)
> > 3.6 M7.
> > 
> > See bug 59891 for details. Possible name of the preference:
> > [ ] Try to keep nested expressions on one line
> 
> I agree that words like "improve" or "aesthetic" might be not enough objective
> to precisely describe what is the intended behavior... So, I agree with this
> proposal.
> 
> Note that the default value for this preference will be unset, to let users
> give a try with the new formatter behavior in this area. Users who will not
> appreciate it or need to keep the old behavior, will need to explicitly check
> this preference to cancel the fix for this current bug...
> 
> Will this make everyone happy?

No problem with it being unset by default, when the remaining bugs are fixed these will indeed be seen as improvements by some ... but they must know it even exists in the first place :).
Comment 7 Dani Megert CLA 2010-05-19 10:19:29 EDT
> but they must know it even exists in the first place :).
Right. We'll advertise it in the 'What's New' and can also put a note into the readme.
Comment 8 Frederic Fusier CLA 2010-05-19 13:08:13 EDT
Created attachment 169154 [details]
Proposed patch

This patch adds the new formatter constant FORMATTER_KEEP_NESTED_EXPRESSIONS_ON_ONE_LINE allowing users to disable the fix for bug 59891 as required.

I've added many new tests which are all the tests I changed while implementing fix for bug 59891 but with this new preference set to verify that one retrieves the behavior of v_A45 (ie. before the fix was released...)
Comment 9 Frederic Fusier CLA 2010-05-19 13:30:29 EDT
Olivier, Dani, could you please review?
TIA
Comment 10 Olivier Thomann CLA 2010-05-19 13:31:18 EDT
Renaming the method the way you did is the simplest way to handle the new preference.
+1.
Comment 11 Olivier Thomann CLA 2010-05-19 13:53:20 EDT
Exclude list has been updated for the API freeze check.
Comment 12 Markus Keller CLA 2010-05-19 17:41:46 EDT
(In reply to comment #8)
+ * FORMATTER / Option to try to keep nested expressions on one line
+ *     - option id:         "org.eclipse.jdt.core.formatter.keep_nested_expressions_on_one_line"
+ *     - possible values:   { TRUE, FALSE }
+ *     - default:           FALSE

Frederic's patch shows that the label "Try to keep nested expressions on one line" can be misunderstood. The way I meant it was that if the option is TRUE, then the formatter will try to put each nested expression on only one line, i.e. it will avoid wrapping nested expressions to multiple lines (if possible). The consequence of that is that it wraps *earlier* than the old strategy, with the implicit benefit that less wrapping is necessary in the nested expressions.

The way you apparently understood it was "keep filling lines as much as possible".

I think the preference should be TRUE (checked) by default, and it should tell what the new formatter strategy is (and if possible, even explain or imply *why* it is better). It shouldn't describe what the old strategy was.

The tricky point about the right wording is that it's not an absolute choice. Even when the option is set, the formatter may still wrap inside nested expressions if the expression is just too long for a single line.

More ideas:
* Try to avoid wrapping inside nested expressions
* Avoid wrapping inside nested expressions
* Wrap earlier if that avoids wrapping nested expressions again
* Try to keep nested expressions on one line (wrap outer expressions first)
* Prefer wrapping outer expressions (keep nested expression on one line)
Comment 13 Olivier Thomann CLA 2010-05-19 18:00:23 EDT
(In reply to comment #12)
> The tricky point about the right wording is that it's not an absolute choice.
> Even when the option is set, the formatter may still wrap inside nested
> expressions if the expression is just too long for a single line.
Then why not something like?
"Preserve Eclipse < 3.6 wrapping"

Should be off by default and a readme entry should specify that old behavior can be retrieved by enabling it.
Comment 14 Frederic Fusier CLA 2010-05-19 19:12:44 EDT
(In reply to comment #10)
> Renaming the method the way you did is the simplest way to handle the new
> preference.
> +1.
Yes, even if it's not very smart, I did it that way to minimize the changes in the formatter and reduce at the minimum the risk of side effects with a so late change in the game...
Comment 15 Frederic Fusier CLA 2010-05-19 19:15:48 EDT
(In reply to comment #12)
> 
> Frederic's patch shows that the label "Try to keep nested expressions on one
> line" can be misunderstood. The way I meant it was that if the option is TRUE,
> then the formatter will try to put each nested expression on only one line,
> i.e. it will avoid wrapping nested expressions to multiple lines (if 
> possible).
> The consequence of that is that it wraps *earlier* than the old strategy,
> with the implicit benefit that less wrapping is necessary in the nested 
> expressions.
> 
> The way you apparently understood it was "keep filling lines as much as
> possible".
> 
> I think the preference should be TRUE (checked) by default, and it should tell
> what the new formatter strategy is (and if possible, even explain or imply
> *why* it is better). It shouldn't describe what the old strategy was.
> 
I understand better now and that sounds reasonable to me. I'll prepare a new patch tomorrow early morning and with a more worded Javadoc to explain the new strategy...

> The tricky point about the right wording is that it's not an absolute choice.
> Even when the option is set, the formatter may still wrap inside nested
> expressions if the expression is just too long for a single line.
> 
> More ideas:
> * Try to avoid wrapping inside nested expressions
> * Avoid wrapping inside nested expressions
> * Wrap earlier if that avoids wrapping nested expressions again
> * Try to keep nested expressions on one line (wrap outer expressions first)
> * Prefer wrapping outer expressions (keep nested expression on one line)

The last one sounds perfect for me. This is exactly what the new strategy intends to do... And it's clear that it's only a best guess, if this strategy fails to fit in the max line width, then the formatter might decide to wrap nested expressions first.
Comment 16 Frederic Fusier CLA 2010-05-19 19:21:24 EDT
(In reply to comment #13)
> (In reply to comment #12)
> > The tricky point about the right wording is that it's not an absolute choice.
> > Even when the option is set, the formatter may still wrap inside nested
> > expressions if the expression is just too long for a single line.
> Then why not something like?
> "Preserve Eclipse < 3.6 wrapping"
> 
> Should be off by default and a readme entry should specify that old behavior
> can be retrieved by enabling it.

I was also tempted by something like that, but I guess it's better to explain the formatter new strategy as suggested by Markus in comment 12...

But in fact, I think you're right at some point and that we should inform users of this new preference that disabling it will put back the formatter to behave as it did in versions before 3.6... I'll add something about this point in the Javadoc.
Comment 17 Olivier Thomann CLA 2010-05-19 19:56:54 EDT
(In reply to comment #16)
> I was also tempted by something like that, but I guess it's better to explain
> the formatter new strategy as suggested by Markus in comment 12...
What I don't like with Markus's suggestion is that it is not clear the relationship between this new preference and the Eclipse wrapping policy prior to 3.6.
Since the point of adding it is to preserve former line wrapping, I believe this should be reflected in the preference description.
Comment 18 Dani Megert CLA 2010-05-20 02:50:39 EDT
>> * Prefer wrapping outer expressions (keep nested expression on one line)
>The last one sounds perfect for me.
Me too. Using '3.6' in the preference doesn't mean anything for new users but we should point out in the 'What's New' and readme that this preference can be used to restore the 3.6 behavior.
Comment 19 Laurent Goubet CLA 2010-05-20 03:13:46 EDT
> >> * Prefer wrapping outer expressions (keep nested expression on one line)
> >The last one sounds perfect for me.
> Me too.

I'd third that as the one we chose previously can be misunderstood as pointed out in comment 12.
Comment 20 Mauro Molinari CLA 2010-05-20 03:55:08 EDT
I think you don't care, however since I voted also in the previous occasion, I would like to say that I also like the latest Markus's proposal :-)
Comment 21 Frederic Fusier CLA 2010-05-20 04:16:35 EDT
Created attachment 169285 [details]
New proposed patch + doc

This patch takes into account all remarks. I hope this is clear enough now and ready to be released for the today's integration build.

All JDT/Core formatter tests are OK, all JDT/Core tests are currently running (but as they are not impacted by this changes, there's no reason not to be ok as well...).
Comment 22 Frederic Fusier CLA 2010-05-20 04:18:46 EDT
Markus, Srikanth, could you review this new patch?
TIA
Comment 23 Frederic Fusier CLA 2010-05-20 04:20:52 EDT
Dani, could you review the patch?
TIA
Comment 24 Dani Megert CLA 2010-05-20 04:27:09 EDT
<(In reply to comment #22)
> Markus, Srikanth, could you review this new patch?
> TIA
Markus is busy with other stuff. Looking into now and starting our tests on the
patch. I assume the new patch doesn't differ much from the first one - hence Olivier's review should still be good.
Comment 25 Frederic Fusier CLA 2010-05-20 04:58:05 EDT
(In reply to comment #24)
> <(In reply to comment #22)
> > Markus, Srikanth, could you review this new patch?
> > TIA
> Markus is busy with other stuff. Looking into now and starting our tests on the
> patch. I assume the new patch doesn't differ much from the first one - hence
> Olivier's review should still be good.

Yes, that was only refactoring + documentation.
Comment 26 Frederic Fusier CLA 2010-05-20 04:58:59 EDT
Ooops, As I removed Oliver's + review, I can't set it back, hence he'll need to put it back this afternoon...
Comment 27 Dani Megert CLA 2010-05-20 05:05:06 EDT
Created attachment 169295 [details]
Previous patch + incorporated my comments

Verified the patch. Some minor issues (fixed in this new patch):
- removed the "first" from the preference and updated all code
- "set to the {@link #FALSE} value" ==> "set to {@link #FALSE}"
- updated the API exclude list
Comment 28 Frederic Fusier CLA 2010-05-20 05:15:45 EDT
Created attachment 169296 [details]
previous patch + missing tests

This final patch adds the additional tests to Dani's changes. Those tests were unfortunately missing in my new proposed patch :-(
Comment 29 Frederic Fusier CLA 2010-05-20 06:54:32 EDT
Srikanth please review, thanks
Comment 30 Srikanth Sankaran CLA 2010-05-20 07:37:56 EDT
Looks reasonable to me.

Noticed a couple of minor nits in the javadoc:

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,

ie. ==> should be i.e. (but I suspect it is coded as ie. in many other places too)

previous versions formatter ==> previous version's formatter
Comment 31 Olivier Thomann CLA 2010-05-20 07:42:21 EDT
The buildnotes should reflect the right constant's name.
Comment 32 Frederic Fusier CLA 2010-05-20 07:49:05 EDT
(In reply to comment #30)
> Looks reasonable to me.
> 
> Noticed a couple of minor nits in the javadoc:
> 
> 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,
> 
> ie. ==> should be i.e. (but I suspect it is coded as ie. in many other places
> too)
> 
It seems that the correct English version is ie. (in French it's i.e.).

> previous versions formatter ==> previous version's formatter

In fact it was: previous versions' formatter => fixed and put in v_A54

Thanks Srikanth

(In reply to comment #31)
> The buildnotes should reflect the right constant's name.

Thanks Oliver => fixed and put in v_A54
Comment 33 Frederic Fusier CLA 2010-05-20 07:49:26 EDT
Released for 3.6RC2 in HEAD stream.
Comment 34 Markus Keller CLA 2010-05-20 08:05:12 EDT
> It seems that the correct English version is ie. (in French it's i.e.).

Nope, it's also i.e., see e.g. http://www.merriam-webster.com/dictionary/i.e.
Comment 35 Olivier Thomann CLA 2010-05-20 08:20:37 EDT
(In reply to comment #34)
> > It seems that the correct English version is ie. (in French it's i.e.).
> 
> Nope, it's also i.e., see e.g. http://www.merriam-webster.com/dictionary/i.e.
I opened bug 313706 to clean this.
Comment 36 Olivier Thomann CLA 2010-05-20 08:27:24 EDT
Opened bug 313708 for the readme entry.
Comment 37 Satyam Kandula CLA 2010-05-24 05:33:58 EDT
Verified for 3.6RC2 using build I20100520-1744
Comment 38 Jay Arthanareeswaran CLA 2010-05-24 05:42:34 EDT
Verified.