Bug 164946 - Spaces in control statements
Summary: Spaces in control statements
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 164947 (view as bug list)
Depends on:
Blocks: 165050
  Show dependency tree
 
Reported: 2006-11-17 06:24 EST by Marvin Fröhlich CLA
Modified: 2006-12-12 12:35 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Fröhlich CLA 2006-11-17 06:24:36 EST
hi

First let me thank you for all the great work on the Eclipse code formatter. It
is a really great tool. But it lacks some important possibilities.

I use to format return- and throw-statements like this:

public MyClass getMyObject()
{
    MyClass o = new MyClass();

    doSomehting( 1 );

    if (somethingBad)
        throw( new IllegalBlaException( "bad bla" ) );

    return( o );
}

If I ran my formatter over this code, it would produce the following:

public MyClass getMyObject()
{
    MyClass o = new MyClass();

    doSomething( 1 );

    if (somethingBad)
        throw (new IllegalBlaException( "bad bla" ));

    return(o);
}

See the missing spaces between the opening brance and the closing brace of the
throw- and return-statement and the mistakenly added space after the throw
statement.

The code formatter doesn't support this formatting. I know, that not too many
people do it like that, but I find it just logic. I guess (or hope) it is not a
too big task to improve the formatter to also support this formatting. Could
you maybe do that? It would also be cool, if one could configure the formatter
to add these braces, if they're missing.

Marvin
Comment 1 Olivier Thomann CLA 2006-11-17 07:53:00 EST
*** Bug 164947 has been marked as a duplicate of this bug. ***
Comment 2 Olivier Thomann CLA 2006-11-17 07:55:52 EST
(In reply to comment #0)
> See the missing spaces between the opening brance and the closing brace of the
> throw- and return-statement and the mistakenly added space after the throw
> statement.
Note that the space is mandatory if the expression is not a parenthesized expression.

> The code formatter doesn't support this formatting. I know, that not too many
> people do it like that, but I find it just logic. I guess (or hope) it is not a
> too big task to improve the formatter to also support this formatting. Could
> you maybe do that? It would also be cool, if one could configure the formatter
> to add these braces, if they're missing.
The code formatter doesn't add any characters. It simply formats whitespaces.
Comment 3 Olivier Thomann CLA 2006-11-17 08:00:08 EST
(In reply to comment #0)
> See the missing spaces between the opening brance and the closing brace of the
> throw- and return-statement and the mistakenly added space after the throw
> statement.
Note that the space is mandatory if the expression is not a parenthesized expression.

> The code formatter doesn't support this formatting. I know, that not too many
> people do it like that, but I find it just logic. I guess (or hope) it is not a
> too big task to improve the formatter to also support this formatting. Could
> you maybe do that? It would also be cool, if one could configure the formatter
> to add these braces, if they're missing.
The code formatter doesn't add any characters. It simply formats whitespaces.
Comment 4 Olivier Thomann CLA 2006-11-17 16:15:47 EST
> See the missing spaces between the opening brace and the closing brace of the
> throw- and return-statement and the mistakenly added space after the throw
> statement.
You need to set that you want a space after the opening parenthesize and before the closing one in a parenthesized expression.
Go to the java formatter prefererence page and make your changes.

The only option that is missing the optional space (in case of parenthesized expression) for the throw statement. The return statement has its corresponding option already.
I'll add this one for throw statement as well, otherwise this is inconsistent.
Will be done only in the 3.3 stream, since this requires API addition and this is prohibited for maintenance releases.
Comment 5 Olivier Thomann CLA 2006-11-17 17:00:03 EST
Released for 3.3M4.
Need fix from bug 165050 to be visible in the UI.
Comment 6 Marvin Fröhlich CLA 2006-11-17 21:22:28 EST
>You need to set that you want a space after the opening parenthesize and before
>the closing one in a parenthesized expression.
>Go to the java formatter prefererence page and make your changes.

Well, it's not exactly, what I want. This would format
(1 + 2)
to
( 1 + 2 )
, which I don't like. Would be great to see two additional options in
White Space->Control Statements->'return'
which can be found in many other settings in this group.
"after opening parenthesis" and "before closing parenthesis".

>The only option that is missing the optional space (in case of parenthesized
>expression) for the throw statement. The return statement has its corresponding
>option already.

>I'll add this one for throw statement as well, otherwise this is inconsistent.
>Will be done only in the 3.3 stream, since this requires API addition and this
>is prohibited for maintenance releases.

>Released for 3.3M4.
>Need fix from bug 165050 to be visible in the UI.

Thank you very much espeacially for the quick reply and fix.

I don't like beta- or pre-versions. When will the final 3.3 be released?

Marvin
Comment 7 Olivier Thomann CLA 2006-11-17 22:06:12 EST
(In reply to comment #6)
> >You need to set that you want a space after the opening parenthesize and before the closing one in a parenthesized expression.
> >Go to the java formatter prefererence page and make your changes.
> 
> Well, it's not exactly, what I want. This would format
> (1 + 2)
> to
> ( 1 + 2 )
> , which I don't like. Would be great to see two additional options in
> White Space->Control Statements->'return'
> which can be found in many other settings in this group.
> "after opening parenthesis" and "before closing parenthesis".
This lacks of consistency. In return (1), (1) is a parenthesized expression the same way that (1 + 2) is a parenthesized expression. If we add a new option for each usage of parenthesized expression, we will end up with too many options. So I am not too tempted to add more options.

I added this one, because it was inconsistent with the handling of the return statement.

> I don't like beta- or pre-versions. When will the final 3.3 be released?
late June 2007. See http://www.eclipse.org/eclipse/development/eclipse_project_plan_3_3.html#Milestones
Comment 8 Marvin Fröhlich CLA 2006-11-18 08:45:32 EST
I added this one, because it was inconsistent with the handling of the return
statement.

Thanks. It indeed was.

> I don't like beta- or pre-versions. When will the final 3.3 be released?
late June 2007.

Oh, that's a little late. Maybe I'll get a 3.3 milestone before. Is the return space fix also included in M4?

Marvin
Comment 9 David Audel CLA 2006-12-12 12:35:27 EST
Verified for 3.3M4 with I20061212-0010.