Bug 286601 - [formatter] Code formatter formats anonymous inner classes wrongly when 'Never join lines' is on
Summary: [formatter] Code formatter formats anonymous inner classes wrongly when 'Neve...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 303107 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-08-14 02:44 EDT by misja CLA
Modified: 2010-02-17 17:18 EST (History)
4 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (5.32 KB, patch)
2009-08-14 05:34 EDT, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (6.71 KB, patch)
2009-08-17 05:21 EDT, Frederic Fusier CLA
no flags Details | Diff
My formatting profile (27.97 KB, text/xml)
2009-10-08 02:41 EDT, misja CLA
no flags Details
Additional patch (9.21 KB, patch)
2009-10-08 10:11 EDT, Frederic Fusier CLA
no flags Details | Diff
New additional patch (49.81 KB, patch)
2009-10-25 10:20 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 misja CLA 2009-08-14 02:44:06 EDT
Example:

public class Test
{
    public void aMethod()
    {
        Object anObject = new Object()
        {
            boolean aVariable;
        };
    }
}

When I click source->format and a have the 'never join lines' checkbox on in my code formatter, my class is turned into:

public class Test
{
    public void aMethod()
    {
        Object anObject = new Object()
                    {
            boolean aVariable;
        };
    }
}

So the first brace of my anonymous inner class is moved to the right.
When I uncheck 'never join lines' this doesn't happen.
Comment 1 Dani Megert CLA 2009-08-14 02:45:58 EDT
Which build id?
Comment 2 misja CLA 2009-08-14 03:15:57 EDT
Build id: I20090611-1540
Comment 3 Frederic Fusier CLA 2009-08-14 03:48:56 EDT
Reproduced even using M20090807-0800, hence this is not a duplicate of bug 283467...
Comment 4 Frederic Fusier CLA 2009-08-14 05:34:46 EDT
Created attachment 144516 [details]
Proposed patch

This patch adds a new flag on alignment to know whether the break indentation should be used when keeping existing break lines. This is typically the case while preserving line breaks inside a binary expression alignment. Currently in all other alignment kind, the current indentation level is used instead...
Comment 5 Frederic Fusier CLA 2009-08-17 05:21:11 EDT
Created attachment 144650 [details]
New proposed patch

This new patch also fixes potential issue with binary expressions other than string literal concatenation...
Comment 6 Frederic Fusier CLA 2009-08-17 05:24:50 EDT
Olivier, I would like you to review this patch as I needed to change the builder.size() > 4 condition to builder.size() > 2 to make binary expressions formatted as soon as 2 terms are in the condition instead of 4...

I do not understand the reason why the formatter should skip expressions with 2 or 3 terms, hence I changed it, but may be there's an important undocumented reason I'm currently missing...
Comment 7 Olivier Thomann CLA 2009-08-17 14:48:13 EDT
As long as we can get a good formatting, I don't see anything wrong in changing this value.
Comment 8 Frederic Fusier CLA 2009-08-18 05:38:24 EDT
Released for 3.6M2 in HEAD stream.
Comment 9 Satyam Kandula CLA 2009-09-15 04:23:54 EDT
Verified for 3.6M2 using I20090914-1800 build
Comment 10 Olivier Thomann CLA 2009-09-15 16:00:17 EDT
Verified.
Comment 11 misja CLA 2009-10-07 10:18:50 EDT
I am using 3.6M2 now, build I20090917-0100, but the formatting is still broken.
Formatting the original example with 'never join lines' on still gives the same result.
Comment 12 Frederic Fusier CLA 2009-10-07 11:40:56 EDT
(In reply to comment #11)
> I am using 3.6M2 now, build I20090917-0100, but the formatting is still broken.
> Formatting the original example with 'never join lines' on still gives the same
> result.

I'm also using 3.6M2 and cannot longer reproduce. Could you attach your formatting profile?
Comment 13 misja CLA 2009-10-08 02:41:40 EDT
Created attachment 149093 [details]
My formatting profile

Attached my formatting profile
Comment 14 Frederic Fusier CLA 2009-10-08 03:53:45 EDT
(In reply to comment #13)
> Created an attachment (id=149093) [details]
> My formatting profile
> 
> Attached my formatting profile

OK, thanks for the input. So, I didn't investigate a lot but this is fixed in last I-build. IMO, your issue was certainly similar than the one I got when I opened bug 286912.

So, closed as duplicate of that bug...

*** This bug has been marked as a duplicate of bug 286912 ***
Comment 15 Frederic Fusier CLA 2009-10-08 03:56:05 EDT
(In reply to comment #14)
> (In reply to comment #13)
> > Created an attachment (id=149093) [details] [details]
> > My formatting profile
> > 
> > Attached my formatting profile
> 
> OK, thanks for the input. So, I didn't investigate a lot but this is fixed in
> last I-build. IMO, your issue was certainly similar than the one I got when I
> opened bug 286912.
> 
> So, closed as duplicate of that bug...
> 
> *** This bug has been marked as a duplicate of bug 286912 ***

Ooops, forget this comment, bug 286912 was also targeted 3.6M2. So, I need to investigate a little bit more. However, as I cannot reproduce with HEAD, the good news is that it will be really fixed for 3.6M3. I just need to find which bug fix also fixed this issue...
Comment 16 Frederic Fusier CLA 2009-10-08 06:03:00 EDT
Hmmm, it seems that I needed a coffee this morning as I can reproduce with HEAD... This is a tricky one as it's not reproducible with Eclipse built-in formatter profile + 'Never Join Lines' preference ON.

After investigation, it appears that the difference comes from the Brace preferences? They are all set to 'Next line' in the given profile (except for Array initializers) although they are all equals to 'Same line' in the Eclipse built-in profile...

I'm trying to figure out what could be the best fix for this peculiar issue...
Comment 17 Frederic Fusier CLA 2009-10-08 10:11:20 EDT
Created attachment 149117 [details]
Additional patch

Do not print the comment before processing the opening brace fixes the problem. It's necessary to first print the new line (if any) and then after print the comment. With this print order, the formatter can keep the correct indentation on the new line (if any).
Comment 18 Frederic Fusier CLA 2009-10-08 11:00:17 EDT
(In reply to comment #17)
> Created an attachment (id=149117) [details]
> Additional patch
> 
Released for 3.6M3 in HEAD stream.
Comment 19 Frederic Fusier CLA 2009-10-08 11:02:54 EDT
No change noticed while running FormatterMassiveRegressionTests with the patch vs v_A13 for all full source workspaces...
Comment 20 Frederic Fusier CLA 2009-10-25 10:14:25 EDT
With the released patch, running formatter massive tests with the bug profile has shown several instability (i.e. files having different formatting output while repeating it twice) in all the full source workspaces, e.g.:
 - 31 while running massive on an Eclipse 3.0 wksp (0 existing)
 - 93 while running massive on a Galileo wksp (47 existing)
 - 148 while running massive on a JDKs wksp (115 existing)

Hence, some rework needs to be done to try to fix these instabilities...
Comment 21 Frederic Fusier CLA 2009-10-25 10:20:10 EDT
Created attachment 150464 [details]
New additional patch

With this new patch I get the following instabilities:
 - 3 while running massive on an Eclipse 3.0 wksp (0 existing)
 - 29 while running massive on a Galileo wksp (47 existing)
 - 125 while running massive on a JDKs wksp (115 existing)

which is of course not perfect but really better than previous patch behavior...

So, I'll release it for 3.6M3 and I will continue to improve the behavior in this area...
Comment 22 Frederic Fusier CLA 2009-10-25 11:57:11 EDT
(In reply to comment #21)
> Created an attachment (id=150464) [details]
> New additional patch
> 
Released for 3.6M3 in HEAD stream.
Comment 23 Dani Megert CLA 2009-10-26 04:47:08 EDT
>So, I'll release it for 3.6M3 and I will continue to improve the behavior in
>this area..
Frédéric, is there a follow-up bug for that work?
Comment 24 Frederic Fusier CLA 2009-10-26 07:53:03 EDT
(In reply to comment #23)
> >So, I'll release it for 3.6M3 and I will continue to improve the behavior in
> >this area..
> Frédéric, is there a follow-up bug for that work?

I opened bug 293300 for this follow-up.
Comment 25 Frederic Fusier CLA 2009-10-26 08:08:17 EDT
I don't why this bug was reopened...!?
Comment 26 Olivier Thomann CLA 2009-10-27 14:54:13 EDT
Verified for 3.6M3 using I20091027-0100
Remaining issues will be verified once bug 293300 is fixed.
Comment 27 Olivier Thomann CLA 2010-02-17 17:18:02 EST
*** Bug 303107 has been marked as a duplicate of this bug. ***