Bug 38151 - Code formatter adds an unwanted blank line after an abstract method with a "throws" clause.
Summary: Code formatter adds an unwanted blank line after an abstract method with a "t...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-27 11:19 EDT by Deven T. Corzine CLA
Modified: 2004-01-29 06:51 EST (History)
0 users

See Also:


Attachments
Screen shot to set the new formatter (26.29 KB, image/png)
2004-01-27 10:21 EST, Olivier Thomann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Deven T. Corzine CLA 2003-05-27 11:19:26 EDT
If the code formatter option "Insert a new line before an opening brace" is
enabled, this bug appears.  (For the sake of this example, assume the "Insert a
new line inside an empty block" option is also enabled, but it's not relevant to
the bug.)

Here is an example block of code, properly formatted:

abstract class Foo
{
	void foo1()
	{
	}
	abstract void foo2() throws Exception;
	void foo3()
	{
	}
}

However, "Source->Format" adds an unwanted blank line to this code:

abstract class Foo
{
	void foo1()
	{
	}
	abstract void foo2() throws Exception;
	void foo3()
	
	{
	}
}

If the "throws Exception" clause is removed from foo2() above, the formatter
does not add the unwanted blank line.  This bug only seems to affect method
definitions which follow abstract method declarations where the abstract method
throws an exception.
Comment 1 Olivier Thomann CLA 2003-10-03 10:29:20 EDT
This is addressed in the new formatter.
Fixed and released in HEAD.
Regression test added.
Comment 2 David Audel CLA 2003-10-14 07:30:28 EDT
Verified.
Comment 3 Deven T. Corzine CLA 2004-01-27 10:10:45 EST
This bug was filed against version 2.1, but it also exists in version 3.0M6,
with exactly the same broken behavior -- even though this bug WAS previously fixed.

If a regression test was added, why didn't it catch this regression?
Comment 4 Olivier Thomann CLA 2004-01-27 10:21:39 EST
Created attachment 7588 [details]
Screen shot to set the new formatter

Are you using the new formatter?
The old formatter won't be fixed. The fix is in the new formatter. So if you
switch to the new formatter, it should work as expected.
I checked it using a M6 build.
See the screen shot to see how to use the new formatter.
Close as fixed in the 3.0 stream.
Comment 5 Olivier Thomann CLA 2004-01-27 10:21:51 EST
Close as FIXED.
Comment 6 Deven T. Corzine CLA 2004-01-27 11:57:12 EST
No, I wasn't using the new formatter.  I had no idea that "new formatter" was a
different mode entirely -- I assumed it meant just a newer version of the code.
 It's strange, though -- I seem to recall testing (with the old formatter) and
seeing that the bug was fixed.  Or maybe I'm misremembering -- it seems to be
broken on the 3.0 milestone from August 28 I was using before today...

Anyway, the new formatter does not appear to be adding these unwanted blank
lines, although it doesn't remove them if they're already there (say, from a
previous auto-format from the old formatter) -- is this a bug?
Comment 7 Olivier Thomann CLA 2004-01-27 12:00:24 EST
You have to check the value of the number of blank lines to preserve.
In your case, you want zero.
See the code formatter preference page. You can define your own settings.
Comment 8 Deven T. Corzine CLA 2004-01-27 12:25:29 EST
If I understand that setting correctly, it won't do what I want.  If a blank
line appears in the middle of the declaration like this bug created under the
old formatter, I would want the formatter to remove that blank line.  Similarly,
if there are blank lines in the middle of a statement being formatted that
wouldn't normally be there, I'd want those removed too.

However, I want to keep blank lines (or at least one) between statements, since
I regularly group statements by strategic use of blank lines in the code.

It seems that I can't do both at the same time.  If I set the number of lines to
preserve to zero, won't it remove all my carefully-placed blank lines between
groups of statements?
Comment 9 Olivier Thomann CLA 2004-01-27 13:02:11 EST
You are right. There is no way to have both.
In your case, get rid of your extra line and it won't be added again when you 
format your code.
Comment 10 Deven T. Corzine CLA 2004-01-27 14:00:38 EST
Would it be feasible to add an option for the number of blank lines to preserve
between statements?  There's already a lot of fine-grained control, so why not?