Bug 49298 - Code formatter does not correctly space closing bracket on method calls
Summary: Code formatter does not correctly space closing bracket on method calls
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Silvio Böhler CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 49634 49668 50845 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-12-22 23:40 EST by Ian Brown CLA
Modified: 2004-02-12 14:40 EST (History)
3 users (show)

See Also:


Attachments
Saved settings for Java code formatter (15.03 KB, text/xml)
2003-12-28 19:58 EST, Ian Brown CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Brown CLA 2003-12-22 23:40:21 EST
Although the new code formatter is good, there is one annoyance that I have 
spotted that I can't see logged elsewhere.

I like to format my lines to have spaces in-between brackets (see code below), 
and it would seem that the formatter preferences allow this configuration.

    // Desired results
    System.out.println( title + " world" ); //$NON-NLS-1$
    System.out.println( test.toString() );

However, if I format these statements, the space before the closing bracket is 
removed, leaving:

    // Wrong results - space removed before ');' construct
    System.out.println( title + " world"); //$NON-NLS-1$
    System.out.println( test.toString());

This formatting behaviour happens consistently on method calls, but not 
constructor calls - which format properly.

I have played with various options to see if this is a case where one option 
is overriding another, but can't resolve it.

Ian
Comment 1 Ian Brown CLA 2003-12-22 23:42:36 EST
This occurs on Eclipse 3, build M6 - and also on the Integration builds 
between M5 and M6 in which the new formatting preferences featured.
Comment 2 Ian Brown CLA 2003-12-28 19:58:03 EST
Created attachment 7287 [details]
Saved settings for Java code formatter

This is the saved settings file used to create the reported problem
Comment 3 Ian Brown CLA 2003-12-31 15:05:51 EST
Another perspective on this issue (spacing in-between braces on method calls), 
the following code:

      Runtime.getRuntime().loadLibrary( filename );
      System.loadLibrary( filename );

gets incorrectly formatted as:

      Runtime.getRuntime( ).loadLibrary( filename );
      System.loadLibrary( filename);

What is odd here (and the reason I have included it in the same report) is 
that:

a) on the Runtime line, it has inserted a space in the getRuntime() call 
(wrong, in my opinion), but not removed the space after filename (correct, 
with this configuration) - BUT
b) on the System line, it has incorrectly removed the space after filename 
(consistent with the original bug report).

So it would seem that the method brace spacing behaviour is not consistent.

I would like to vote that empty-brace method calls - eg getRuntime() - have no 
spaces, not 1 or 2. I mention this only because I don't want the fix for the 
removed space in the non-empty-brace method calls to mean that empty-brace 
method calls suddenly get 2 spaces!
Comment 4 Olivier Thomann CLA 2004-01-05 09:48:00 EST
I am investigating.
Comment 5 Olivier Thomann CLA 2004-01-05 11:01:36 EST
This is fixed.
I added a new option to distinguish between empty arguments in method
declarations vs empty argument in method invocations.
Fixed and released in HEAD.
Regression test added.
Comment 6 Olivier Thomann CLA 2004-01-05 11:50:14 EST
This is still fixed, but I am reusing the old option in method invocations as
well. The new option is ready, but won't be released till Martin is back.
So I will properly close it once the new option is used.
Comment 7 Ian Brown CLA 2004-01-07 09:51:37 EST
For your info, I have downloaded the latest nightly build (20040107).

The basic condition is fixed, but one issue appears to still be there...

Going back to a comment I added previously, the following code:

      Runtime.getRuntime().loadLibrary( filename );
      System.loadLibrary( filename );

now gets formatted as:

      Runtime.getRuntime( ).loadLibrary( filename );
      System.loadLibrary( filename );

So the method-call closing brackets on the loadLibrary calls are both now 
correctly formatted, but the space in the "getRuntime( )" brackets was 
unexpected. Not sure if this is:

- Eclipse behaving itself - in which case I will create a new report to 
request the ability to configure that no-parameter method calls get no spaces 
in the brackets - giving "getRuntime()" OR
- Expected behaviour based on one of the comments about the applied fix using 
an old option OR
- An outstanding issue within the fix

Comment 8 Olivier Thomann CLA 2004-01-07 10:04:54 EST
Hopefully the fix will be completed today. You must have the option to add a 
white space between empty method arguments sets to true. I had to remove the 
new setting since one committer was not back from vacations yet.
Don't worry once fixed, you should be able to configure if you want the 
whitespace between empty method arguments in a method invocation.
Check your settings in:
White Space>Declarations>Member Functions>between empty parenthesis.
This option should be set. Uncheck it and it should work the way you want. A 
new option will be added soon to distinguish empty arguments in method 
declarations vs method invocations.
Comment 9 Olivier Thomann CLA 2004-01-07 12:19:30 EST
*** Bug 49634 has been marked as a duplicate of this bug. ***
Comment 10 Olivier Thomann CLA 2004-01-07 12:44:54 EST
Fixed and released in HEAD.
Silvio, please add the new option
FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_MESSAGESEND_ARGUMENTS in the code formatter
preference page.
By default this is false.
Your last test case has been added as a regression test. I had a bug. I missed
one case. Thanks for the report and the feedback.
Comment 11 Olivier Thomann CLA 2004-01-08 08:57:49 EST
*** Bug 49668 has been marked as a duplicate of this bug. ***
Comment 12 Silvio Böhler CLA 2004-01-13 05:04:15 EST
>= 20040113

FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_MESSAGESEND_ARGUMENTS added to 

White Space -> Expressions -> Method and constructor calls -> between empty
parentheses
Comment 13 Olivier Thomann CLA 2004-01-29 12:12:23 EST
*** Bug 50845 has been marked as a duplicate of this bug. ***
Comment 14 Olivier Thomann CLA 2004-02-12 14:40:44 EST
Verified in 200402121200.