Community
Participate
Working Groups
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.
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.
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.
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.
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.
I agree, let us leave it as is then.
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;
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?
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.
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;
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.
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'
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.
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
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
JDT/Core is patched in HEAD.
patch released for I20051011
Verified using I20051031-2000