Bug 199265 - [formatter] 3.3 Code Formatter mis-places commented-out import statements
Summary: [formatter] 3.3 Code Formatter mis-places commented-out import statements
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M4   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-08 10:42 EDT by trent cobham CLA
Modified: 2009-12-08 03:42 EST (History)
3 users (show)

See Also:


Attachments
Proposed patch (74.36 KB, patch)
2009-11-05 09:42 EST, Frederic Fusier CLA
no flags Details | Diff
Proposed patch (store elapsed time in massive tests) (79.08 KB, patch)
2009-11-05 12:43 EST, 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 trent cobham CLA 2007-08-08 10:42:53 EDT
Build ID: I20070621-1340

Steps To Reproduce:
1. Use default Code Formatter settings: Eclipse: [built-in]
2. Enter this code fragment:

import a.b;
// import c.d;
import e.f;

3. Run the Code Formatter

4. Result is this:

import a.b; // import c.d;
import e.f;

This doesn't make a lot of sense; but also:

- it happens even if you switch off all comment formatting in the Comments tab;
- it didn't happen in 3.2;
- it isn't consistent, because if you format just this:

import a.b;
// import c.d;

you get this:

import a.b;

// import c.d;

So it looks like buggy behaviour to me.


More information:
Comment 1 Frederic Fusier CLA 2008-08-18 08:07:53 EDT
Ownership has changed for the formatter, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5.
Please provide a patch if you definitely need the bug to be fixed in this version and I'll have a look at it...
TIA
Comment 2 Frederic Fusier CLA 2009-11-03 12:15:42 EST
I'll have look on this as it could be interesting to fix it before fixing bug 293300...
Comment 3 Frederic Fusier CLA 2009-11-03 12:17:20 EST
Here's a simple test case to show this issue:

import java.util.List;
//import java.util.HashMap;
import java.util.Set;

public class X {
}

Using the Eclipse built-in profile, it is formatted as follow:

import java.util.List; //import java.util.HashMap;
import java.util.Set;

public class X {
}

Note that this was properly formatted with Eclipse 3.2.2
Comment 4 Frederic Fusier CLA 2009-11-05 09:42:33 EST
Created attachment 151423 [details]
Proposed patch

This is a big patch as it also remove duplicated methods to print comment:
 - printTrailingComment()
 - printTrailingComment(int)

Note that the strategy for trailing comments has not been really modified, just integrated in the printComment(int, int) method to allow fixes around comments consuming easier to do (e.g. bug 293300).

Note also the specific algorithm for trailing comments consumed in import declarations area. This was a little bit tricky as in some cases, comments have to be consumed as trailing comments and in some other cases as common comments...

This patch passes all JDT/Core tests (of course) but also all formatter massive regression tests on the 3 full sources workspaces (Eclipse 3.0, Galileo and JDKs) where it fixes respectively 9, 31 and 61 invalid formatting outputs produced by the current version in HEAD...
Comment 5 Frederic Fusier CLA 2009-11-05 12:43:10 EST
Created attachment 151464 [details]
Proposed patch (store elapsed time in massive tests)

Same patch but improve FormatterMassiveRegressionTests to dump the time spent to format all units and save the results in log file. Doing this I also verified that the new algorithm didn't introduce performance regression.
Comment 6 Frederic Fusier CLA 2009-11-05 12:44:37 EST
I also run the massive tests for different formatter profiles
 - Eclipse built-in
 - Eclipse built-in + no comments
 - Eclipse built-in + join lines only in comments
 - Eclipse built-in + join lines only in comments + all braces on next line

and didn't notice any regression either...

So, as all tests are green, I have released the patch for 3.6M4 in HEAD stream.
Comment 7 Olivier Thomann CLA 2009-11-05 12:51:05 EST
(In reply to comment #6)
> So, as all tests are green, I have released the patch for 3.6M4 in HEAD stream.
Definitely. Thanks for the good work, Frédéric!
Comment 8 Satyam Kandula CLA 2009-12-08 01:57:43 EST
Verified for 3.6M4 using I20091207-1800