Bug 286912 - [formatter] Never join lines preferences makes the formatter unstable in certain circumstances
Summary: [formatter] Never join lines preferences makes the formatter unstable in cert...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-18 04:51 EDT by Frederic Fusier CLA
Modified: 2009-10-08 03:53 EDT (History)
5 users (show)

See Also:


Attachments
Proposed patch (18.44 KB, patch)
2009-08-18 12:42 EDT, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (18.86 KB, patch)
2009-08-21 04:24 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 Frederic Fusier CLA 2009-08-18 04:51:16 EDT
Using I20090811-0800 but it also happens in 3.5.0

I discovered that using HEAD the formatter was unstable while performing the bug 286668 comment 2 test case:

public class Test {

	void foo() {
		StringBuilder builder = new StringBuilder();
		builder.append("abc").append("def").append("ghi").append("jkl").append("mno")
		.append("pqr").append("stu").append("vwx").append("yz");
	}
}

is formatted as follow:

public class Test {

	void foo() {
		StringBuilder builder = new StringBuilder();
		builder.append("abc").append(
				"def").append("ghi")
				.append("jkl").append(
						"mno")
				.append("pqr").append(
						"stu").append(
						"vwx").append(
						"yz");
	}
}

That looks not too bad, but if I format again this code, expecting that nothing changes, I get the following wrong output:

public class Test {

	void foo() {
		StringBuilder builder = new StringBuilder();
		builder.append("abc").append(
				"def").append("ghi")
				.append("jkl").append(
				"mno")
				.append("pqr").append(
				"stu").append(
				"vwx").append(
				"yz");
	}
}
Comment 1 Frederic Fusier CLA 2009-08-18 04:54:35 EDT
I'm currently trying to figure out how fixing this problematic issue...
Comment 2 Frederic Fusier CLA 2009-08-18 12:42:45 EDT
Created attachment 144846 [details]
Proposed patch

A tricky one... This patch should hopefully fix most of the issue around the 'Never join lines' preferences. It removes fix done for bug 286601 which was not enough solid to cover all cases.

The current strategy is now to analyze the current indentation which exist on the broken line and apply the same after having indented the current alignment.

This allow to get rid of the path currently followed in the CodeFormatterVisitor when trying to preserve the broken line, hence make this fix more general than the previous one.

Of course it also fixes, and that was obviously its main goal, the stability problem of the formatter...
Comment 3 Frederic Fusier CLA 2009-08-18 12:44:01 EDT
Olivier, could you please review and let me know if you agree with the strategy applied in this patch?
Thanks
Comment 4 Frederic Fusier CLA 2009-08-21 04:24:02 EDT
Created attachment 145241 [details]
New proposed patch

This patch fixes regression observed while running massive formatter tests. Note that with this new patch all the changes done in patch for bug 286601 have been reverted (especially the change done in bug 286601 comment 6).

With this new patch we're back to the 3.6M1 and 3.5.0 behavior, which was unfortunately not the case since bug 286601 fix was released...
Comment 5 Frederic Fusier CLA 2009-08-21 12:13:09 EDT
Released for 3.6M2 in HEAD stream.
Comment 6 Frederic Fusier CLA 2009-08-25 04:13:58 EDT
(In reply to comment #4)
> 
> With this new patch we're back to the 3.6M1 and 3.5.0 behavior, which was
> unfortunately not the case since bug 286601 fix was released...
> 
May be this was not crystal clear... I meant that with this new patch, the bug
286601 is still fixed but without the regressions introduced by the patch
initially released to fix it.
Comment 7 Satyam Kandula CLA 2009-09-15 09:44:11 EDT
Verified for 3.6M2 using I20090914-1800
Comment 8 Olivier Thomann CLA 2009-09-15 16:00:41 EDT
Verified.
Comment 9 Frederic Fusier CLA 2009-10-08 03:53:45 EDT
*** Bug 286601 has been marked as a duplicate of this bug. ***