Bug 258049 - [formatter] Linebreak before trailing statement semicolon not preserved
Summary: [formatter] Linebreak before trailing statement semicolon not preserved
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.6 M5   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-09 05:56 EST by Philipe Mulet CLA
Modified: 2010-01-25 03:34 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2008-12-09 05:56:59 EST
Version: 3.5.0 - Build id: I20081209-0100

With formatter preferences set to:
org.eclipse.jdt.core.formatter.join_wrapped_lines=false
org.eclipse.jdt.core.formatter.join_lines_in_comments=false

The following code:

public class X {
	void foo() {
		System.out.println()
		;
	}
}

becomes:

public class X {
	void foo() {
		System.out.println();
	}
}
Comment 1 Philipe Mulet CLA 2008-12-09 05:57:27 EST
Not even sure if it would make sense to preserve... could be argued to be a feature.
Comment 2 Olivier Thomann CLA 2008-12-09 11:07:23 EST
The line breaks are only preserved when there is a line wrapping involved. In this case there is no line wrapping, so the trailing semicolon is moved to the end of the statement.
Personally I don't want it to be preserved in this case. 
Comment 3 Frederic Fusier CLA 2008-12-09 11:40:11 EST
(In reply to comment #2)
> The line breaks are only preserved when there is a line wrapping involved. In
> this case there is no line wrapping, so the trailing semicolon is moved to the
> end of the statement.
> Personally I don't want it to be preserved in this case. 
> 
I do not want to preserve it either (not only to avoid to fix the bug...<g>)
Dani, what's your mind?
Comment 4 Dani Megert CLA 2008-12-09 12:01:14 EST
If I enable that preference I expect no lines to be joined. However, as Philippe reported: it is a minor issue.
Comment 5 Olivier Thomann CLA 2008-12-09 12:19:10 EST
For me the intent of this new option was never to preserve the line break in this situation. If this is the case, then I don't want this new option.
The purpose of this new option is to preserve line breaks inside line wrapping to make it possible for the user to "wrap" the long lines as he/she expects them to be wrapped and preserve this wrapping during formatting.
Maybe we should rename the option.

I don't see the point of using this option when no line wrapping is involved.

Having the behavior described in comment 0 would be a bug for me, not a feature!
Comment 6 Dani Megert CLA 2008-12-09 12:25:01 EST
My point is that a normal user would never write code like in your example and if he really did then he wants it preserved.
Comment 7 Olivier Thomann CLA 2008-12-09 12:32:50 EST
Then this should be a new option.
Comment 8 Olivier Thomann CLA 2008-12-09 12:33:15 EST
I don't want it mixed up with the current option used in line wrapping.
Comment 9 Dani Megert CLA 2008-12-09 12:34:42 EST
Olivier, are you really having/writing code like that so that you are affected by this?
Comment 10 Olivier Thomann CLA 2008-12-09 12:42:36 EST
I hope not, but I don't want that kind of line breaks preserved. Ever! It is just ugly and pointless.
You might have that kind of line breaks not on purpose by editing some code and having an extra-line break just before the semi-colon.
On the next formatting, I don't want to preserve it even if this option is set to false, because I have some long lines that the code formatter doesn't handle the way I like them.
Comment 11 Dani Megert CLA 2008-12-10 02:36:55 EST
Don't get me wrong I can live with both behaviors. I just expressed my expectation, like you did yours. I suggest that we ask those that really use and requested the new feature i.e. poll in bug 198074.
Comment 12 Olivier Thomann CLA 2009-12-09 12:12:46 EST
Frédéric, please check if this is still a problem.
Comment 13 Denis Ballant CLA 2009-12-17 16:37:47 EST
I personally agree with Dani:  "... a normal user would never write code like in your example and if he really did then he wants it preserved."
Also "it is a minor issue" we can just ignore.
Comment 14 Olivier Thomann CLA 2009-12-17 22:43:08 EST
My point of view is that the "Join lines option" should only be used in the context of line wrapping. The biggest issue is when line wrapping is involved and user formatting is lost.
In the test case in comment 0, I certainly don't want the line break to be preserved.
Comment 15 Denis Ballant CLA 2009-12-18 10:39:17 EST
(In reply to comment #14)
> My point of view is that the "Join lines option" should only be used in the
> context of line wrapping. The biggest issue is when line wrapping is involved
> and user formatting is lost.
> In the test case in comment 0, I certainly don't want the line break to be
> preserved.

But, when the formatter is going to remove the line break in this special case, aren't we also in the context of line wrapping ?  I don't see in which case the formatter thinks that it is in "line wrapping" context or not.

By the way, a ";" alone on a line might be used by some developers to indicate explicitly that an IF or LOOP control statement is followed by an empty statement, e.g.:

if (doSomething())
  ;
else
  react();

for (...)
 ;
Comment 16 Dan Forward CLA 2009-12-18 11:25:45 EST
I am one who requested bug 198074 to be fixed, primarily to preserve multi-line concatenated strings. We had one class we could never use the formatter with because it contained all our SQL queries.

As mentioned in bug 198074, we only wanted it applied to line wrapping. Other newline rules set in the formatter should still be enforced, such as whether empty statements should be on their own line.

The example given in this bug is technically manual wrapping, but I would not want it "fixed". If necessary, add another rule for no space between the end of a statement and a semi-colon, but I doubt there would be much demand for the reverse.
Comment 17 Olivier Thomann CLA 2009-12-18 11:38:44 EST
Empty statements are handled already. There is no problem with this as far as I know.
Comment 18 Dani Megert CLA 2010-01-04 08:43:09 EST
I suggest to close this as WONTFIX. To clarify the behavior we can change the UI preference to "Never join already wrapped lines".
Comment 19 Frederic Fusier CLA 2010-01-04 08:53:22 EST
(In reply to comment #18)
> I suggest to close this as WONTFIX. To clarify the behavior we can change the
> UI preference to "Never join already wrapped lines".

+1
Comment 20 Dani Megert CLA 2010-01-04 09:22:09 EST
> To clarify the behavior we can change the
>UI preference to "Never join already wrapped lines".
Done.
Comment 21 Frederic Fusier CLA 2010-01-04 10:33:50 EST
Closed as WONTFIX
Comment 22 Satyam Kandula CLA 2010-01-25 03:22:15 EST
Verified for 3.6M5 using Build id: I20100122-0800
Comment 23 Srikanth Sankaran CLA 2010-01-25 03:34:49 EST
Verified.