Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 145317 - [formatter] Code formatter inserts extra blank lines
Summary: [formatter] Code formatter inserts extra blank lines
Status: CLOSED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P5 normal with 2 votes (vote)
Target Milestone: 4.5   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-05 07:45 EDT by Julien Dufour CLA
Modified: 2015-12-28 19:29 EST (History)
1 user (show)

See Also:


Attachments
Formatter settings and test case (3.43 KB, application/zip)
2006-06-08 04:06 EDT, Julien Dufour CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Dufour CLA 2006-06-05 07:45:41 EDT
Java's code formatter inserts too many blank lines at various locations within class declarations. Blank lines introduced by the various constraints look to be cumulated instead of being merged. Extra blank lines appear in the code when several constraints target a same location. The issue is especially visible when the "number of blank lines to preserve" is greater than 0.

I have noticed this issue since Eclipse 3.2RC6, I didn't noticed it in RC4, and I skipped RC5.
Comment 1 Olivier Thomann CLA 2006-06-05 20:03:37 EDT
There is no code formatter changes between RC4 and RC6.
Would it be possible to get the code formatter settings and a test case?
Thanks.
Comment 2 Julien Dufour CLA 2006-06-08 04:06:58 EDT
Created attachment 43840 [details]
Formatter settings and test case

- format.xml contains the formatter settings I'm using for the test case.
- step0.java contains the original test case file.
- step1.java contains the result after a first format action on the test case file.
- step2.java contains the result after a second format action on the test case file.
Comment 3 Julien Dufour CLA 2006-06-08 04:28:03 EDT
As you can see in the test case files, the first "format" action correctly insert blank lines between the methods of the class. However, a second blank line is also added in the "addValue" method. The second "format" action insert extra blank lines between the methods as well. The next "format" actions leave the code in the same state.
Comment 4 Julien Dufour CLA 2006-08-01 16:29:50 EDT
Hello

I believed I have identified and solved the issue. The incorrect behaviour occurs when setting the indentation policy to "tab only" and enabling indentation of the blank lines (a recently added feature).

With those settings, the "org.eclipse.jdt.internal.formatter.Scribe.printIndentationIfNecessary(StringBuffer)" method gets called and wrongly resets the value of the "lastNumberOfNewLines" member of the class (line 1056 and 1069 in Scribe.java of the 3.2 stable build). This value is not reset when setting the other indentation policies and it is clear that the calling "org.eclipse.jdt.internal.formatter.Scribe.getEmptyLines(int)" method does not expect the value to change. Removing those affectations seems to fix the issue.

Important: Those methods are dupplicated in the "org.eclipse.jdt.internal.formatter.Scribe2" class which should be fixed in the same way.

Best regards
Comment 5 Frederic Fusier CLA 2008-08-18 08:07:21 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 6 Mateusz Matela CLA 2015-12-28 19:29:49 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***