Bug 111139 - Add FORMATTER_INSERT_SPACE_BEFORE_PARENTHESIZED_EXPRESSION_IN_RETURN to the code formatter preference page
Summary: Add FORMATTER_INSERT_SPACE_BEFORE_PARENTHESIZED_EXPRESSION_IN_RETURN to the c...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Benno Baumgartner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 110304
Blocks:
  Show dependency tree
 
Reported: 2005-09-29 16:38 EDT by Olivier Thomann CLA
Modified: 2005-11-01 09:33 EST (History)
1 user (show)

See Also:


Attachments
Proposed fix (4.34 KB, patch)
2005-09-30 09:34 EDT, Benno Baumgartner CLA
no flags Details | Diff
fix (4.36 KB, patch)
2005-10-03 03:27 EDT, Benno Baumgartner CLA
no flags Details | Diff
fix (6.29 KB, patch)
2005-10-06 03:53 EDT, Benno Baumgartner CLA
no flags Details | Diff
fix (7.35 KB, patch)
2005-10-06 11:29 EDT, Benno Baumgartner CLA
no flags Details | Diff
rename in core (3.92 KB, patch)
2005-10-06 11:30 EDT, Benno Baumgartner CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2005-09-29 16:38:29 EDT
This new option should be added in the whitespace section (control statements)
of the code formatter preference page.
It makes the insertion of a space after the return keyword optional when the
following expression is a cast expression, a parenthesized expression, a string
literal or prefix expression. For all other types of expressions, the insertion
of a space is mandatory.
Comment 1 Benno Baumgartner CLA 2005-09-30 09:34:31 EDT
Created attachment 27721 [details]
Proposed fix

Adds the preference.

This formatter option seams to have no effect for a prefixed expression like:
return -1;

It's difficult to add this option to a syntax element category in the
preference page. If it would only work before opening paranthesis, as proposed
in bug 110304, then it could be added to the 'Before opening
paranthesis'category.
Comment 2 Olivier Thomann CLA 2005-09-30 12:16:10 EDT
The problem is that this is not always before parenthesis. It is really after
return keyword and only if the following expression is:
- a string literal, or
- a parenthesized expression, or
- a prefix expression, or
- a cast expression.

-1 is not a prefix expression. This is an int literal.
A prefix expression is: ++i or --i or !b, etc.
I can change the option name if it helps to categorize it.
Comment 3 Benno Baumgartner CLA 2005-10-03 03:27:31 EDT
Created attachment 27754 [details]
fix

The option name is okay. I just thought maybe you could make 4 options out of
it? Like:

FORMATTER_INSERT_SPACE_BEFORE_OPENING_PARENTESIS_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_TYPE_CAST_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_PREFIX_EXPRESSION_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_CAST_EXPRESSION_IN_RETURN

Would be great if this is possible.
Comment 4 Olivier Thomann CLA 2005-10-03 08:46:49 EDT
This is possible, but I doubt this is useful. From my perspective the use wants
a space always or never (when that space can be optional). Giving 4 options is
simply more confusing and requires more work when they have to be set.
If we add four options I would rename them to:


FORMATTER_INSERT_SPACE_BEFORE_PARENTESIZED_EXPRESSION_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_STRING_LITERAL_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_PREFIX_EXPRESSION_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_CAST_EXPRESSION_IN_RETURN

I don't see what type cast is doing there.
I am not convinced we need a really fine grained option at this level. Look at
the bug 110304.
Comment 5 Benno Baumgartner CLA 2005-10-04 03:29:39 EDT
I agree, let us leave it as is then.
Comment 6 Martin Aeschlimann CLA 2005-10-04 04:35:11 EDT
Olivier, I also think we should limit the option to opening paranthesis only.
I don't see why sombody would use
return++i; or return"hello"
even if its possible.
I think the parenthesis case is special as these users would always have
parenthesis after a return.
Don't rush in cases like return++i as then you would also have to offer
formattings like Type[]a; or Type<S>a;



Comment 7 Olivier Thomann CLA 2005-10-04 08:55:21 EDT
Ok, no problem, but then we should change the name as it would be misleading for
prefix expression or string literals.
We can either have two options:
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIZED_EXPRESSION_IN_RETURN
FORMATTER_INSERT_SPACE_BEFORE_CAST_EXPRESSION_IN_RETURN

or:

FORMATTER_INSERT_SPACE_BEFORE_PARENTESIS_FOR_EXPRESSION_IN_RETURN

Any preference?
Comment 8 Benno Baumgartner CLA 2005-10-05 11:07:03 EDT
I prefere:
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIS_FOR_EXPRESSION_IN_RETURN
because I can then add it in "Sort options by syntax element" view to
Before opening Parenthesis -> 'return'

With two options I could add it to:
Before opening Parenthesis -> 'return' -> parentesized expression
Before opening Parenthesis -> 'return' -> type cast

Doesn't matter too much to me.
Comment 9 Martin Aeschlimann CLA 2005-10-05 11:28:56 EDT
I would just go for
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIS_FOR_EXPRESSION_IN_RETURN
and only handle the case

return(x);  but not  return(V)h;
Comment 10 Olivier Thomann CLA 2005-10-05 11:39:31 EDT
I can understand why you don't want to get it for prefix expression and string
literals, but in case of cast expressions or parenthesized expressions, the
support should be consistent.
I will need to adjust the implementation for bug 110304 in case we change the
option.
For me the idea of this new option was to make the insertion of the space
optional when the space is not mandatory. There are four cases where the space
is not mandatory: cast expressions, parenthesized expressions, string literals
and prefix expressions.
From comment 6, I understood that adding the last two cases would push us to
offer more support for spacing after types.
If we call the option
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIS_FOR_EXPRESSION_IN_RETURN, then we need
to handle the cast case.
If we call it FORMATTER_INSERT_SPACE_BEFORE_PARENTESIZED_EXPRESSION_IN_RETURN,
then we can reduce it to handle only the case of parenthesized expressions.
Comment 11 Benno Baumgartner CLA 2005-10-06 03:53:51 EDT
Created attachment 27923 [details]
fix

Adds preferences for
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIZED_EXPRESSION_IN_RETURN
to
sort options by java element -> control stmts -> 'return'
sort options by syntax element -> before opening paranthesis -> 'return'
Comment 12 Olivier Thomann CLA 2005-10-06 08:33:30 EDT
Hi Benno,

My mistake. I have a spelling mistake in the option name. I forgot a 'H'.
It should be:
FORMATTER_INSERT_SPACE_BEFORE_PARENTHESIZED_EXPRESSION_IN_RETURN

Can you make adjustements on your side?

Also talking with Martin yesterday, we agreed that in the syntax element section
we should replace 'return' with 'return with parenthesized expression' or
something like that. This would clarify that this works only for parenthesized
expressions and not for cast expressions.
Thanks for your help.
Comment 13 Benno Baumgartner CLA 2005-10-06 11:29:10 EDT
Created attachment 27945 [details]
fix

Adds preferences for
FORMATTER_INSERT_SPACE_BEFORE_PARENTHESIZED_EXPRESSION_IN_RETURN
to
sort options by java element -> control stmts -> 'return'
sort options by syntax element -> before opening parenthesis -> 'return' ->
parenthesized expression
Comment 14 Benno Baumgartner CLA 2005-10-06 11:30:00 EDT
Created attachment 27946 [details]
rename in core


renames:
FORMATTER_INSERT_SPACE_BEFORE_PARENTESIZED_EXPRESSION_IN_RETURN
to
FORMATTER_INSERT_SPACE_BEFORE_PARENTHESIZED_EXPRESSION_IN_RETURN
in core
Comment 15 Olivier Thomann CLA 2005-10-06 11:37:08 EDT
JDT/Core is patched in HEAD.
Comment 16 Martin Aeschlimann CLA 2005-10-11 04:11:14 EDT
patch released for I20051011
Comment 17 Benno Baumgartner CLA 2005-11-01 09:33:20 EST
Verified using I20051031-2000