Bug 286668 - [formatter] 'Never Join Lines' joins lines that are split on method invocation
Summary: [formatter] 'Never Join Lines' joins lines that are split on method invocation
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-14 14:46 EDT by Travis Mising name CLA
Modified: 2009-09-15 16:00 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Travis Mising name CLA 2009-08-14 14:46:20 EDT
Build ID: 20090621-0832

Steps To Reproduce:
1. Enable "Never Join Lines" on source code for the java formatter.
2. Attempt to format the following code.  Note the @@\n@@ below should be replaced with a newline after pasting.

StringBuilder builder = new StringBuilder();
builder.append("abc").append("def").append("ghi").append("jkl").append("mno")@@\n@@.append("pqr").append("stu").append("vwx").append("yz");

3. The previous string of appends should fall on two lines.  "abc" through "mno" are on one line, the next line starts with ".append".
4. Format the code.
5. Note how eclipse incorrectly places all of the code on a single line.
6. Change the code to:

builder.append("abc").append("def").append("ghi").append("jkl").append(@@\n@@"mno").append("pqr").append("stu").append("vwx").append("yz");
7. The code should still be on two lines, but is split after a ".append(".
8. Format the code.
9. Note how the code correctly stays on two lines.


More information:
Comment 1 Frederic Fusier CLA 2009-08-17 06:50:46 EDT
I have some problems with your scenario. Using Eclipse built-in profile, I cannot reproduce step 5 (i.e. on a single line), I always get 3 lines:

>> >> builder.append("abc").append("def").append("ghi").append("jkl").append(
>> >> >> >> "mno")
>> >> >> >> .append("pqr").append("stu").append("vwx").append("yz");

(where '>> ' shows a tabulation)

Do you modify the default Eclipse built-in profile?

I also see on step 9 that the second line is indented:

>> >> builder.append("abc").append("def").append("ghi").append("jkl").append(
>> >> >> >> "mno").append("pqr").append("stu").append("vwx").append("yz");

although it should not:
>> >> builder.append("abc").append("def").append("ghi").append("jkl").append(
>> >> "mno").append("pqr").append("stu").append("vwx").append("yz");

So, I definitely agrees that there's a real issue... I just need a clear test case to highlight it. Here's my proposal using '>>  ' as a tabulation:

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");
>>  }
}

Currently, using Eclipse built-in profile + 'Never join lines'=true + 'Maximum Line width'=40, the test case above 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");
>>  }
}

Instead we should have:
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 2 Frederic Fusier CLA 2009-08-17 07:20:07 EDT
Another variation which may be more convincing...

Here's the 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");
>>  }
}

Currently, using Eclipse built-in profile + 'Never join lines'=true + 'Maximum
Line width'=60, the test case above 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");
>>  }
}

although it should be unchanged...
Comment 3 Travis Mising name CLA 2009-08-17 11:46:41 EDT
I forgot to mention that I have the line length set to something exorbitantly high, like 200 characters.  That is probably why you are seeing three lines instead of the two.
Comment 4 Frederic Fusier CLA 2009-08-18 03:32:21 EDT
(In reply to comment #3)
> I forgot to mention that I have the line length set to something exorbitantly
> high, like 200 characters.  That is probably why you are seeing three lines
> instead of the two.
> 
This was my assumption, thanks to confirm it.
Comment 5 Frederic Fusier CLA 2009-08-18 12:45:07 EDT
This bug will be fixed by the patch of bug 286912:
https://bugs.eclipse.org/bugs/attachment.cgi?id=144846
Comment 6 Frederic Fusier CLA 2009-08-21 12:13:21 EDT
Released for 3.6M2 in HEAD stream.
Comment 7 Satyam Kandula CLA 2009-09-15 09:47:52 EDT
Verified for 3.6M2 using I20090914-1800
Comment 8 Olivier Thomann CLA 2009-09-15 16:00:29 EDT
Verified.