Community
Participate
Working Groups
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.
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.
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.
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.
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
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
This problem no longer occurs after the formatter redesign. *** This bug has been marked as a duplicate of bug 303519 ***