-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option "Place trailing closure arguments after closing parenthesis" should not apply to constructor calls #1093
Comments
Oh, yes, you're right, I thougth it was the other option, which then I guess only controls generated code rather then live typing... |
ready to test |
Tested with 3.8.0.v202005052348-e1912, there's still one broken case: package test68
class GBean {
public GBean(Closure c) {}
} package test68
class Test68 {
void foo() {
def g = new GBean(|)
}
} Let "|" be the cursor position, hit "{". The result is:
which is not the most common behaviour, IMHO, which is instead to invoke |
I think that is a separate issue. In the original example, there was a trailing comma that clearly indicates an upcoming expression. In the case of "new T()", it is difficult to separate intent to pass a closure from intent to create anon. inner class. |
Well, to be honest the original issue was that when calling a constructor with a closure as its last parameter, the editor was moving the "{" outside the round parenthesis so that the final syntax is expressing something else (i.e.: an anonymous inner class creation). The presence of the trailing comma was an additional problem described while describing the former issue. But if you prefer I'll open another report. |
If the option
Place trailing closure arguments after closing parenthesis
is checked and you try to write a constructor call with a closure as the last parameter, Greclipse pushes the opening brace outside the closing round parenthesis:If you type
{
at "|", you'll get:Apart from the fact that the comma is left behind, this won't produce a valid result because:
is seen as a creation of an anonymous in-place extension of
MyClass
rather than a call toMyClass
constructor with trailing closure, in fact:is seen as a syntax error ("unexpected token: foo").
For constructor calls, you can't use the syntax that puts the trailing closure parameters outside the round parenthesis, at least in Groovy 2.x (I don't know how it works in Groovy 3, but I think it would be ambiguous if it let do it).
The text was updated successfully, but these errors were encountered: