Skip to content

Option "Place trailing closure arguments after closing parenthesis" should not apply to constructor calls #1093

@mauromol

Description

@mauromol

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:

MyClass c = new MyClass('foo', |)

If you type { at "|", you'll get:

MyClass c = new MyClass('foo', ) {

Apart from the fact that the comma is left behind, this won't produce a valid result because:

MyClass c = new MyClass('foo') {
}

is seen as a creation of an anonymous in-place extension of MyClass rather than a call to MyClass constructor with trailing closure, in fact:

MyClass c = new MyClass('foo') { foo, bar ->
}

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).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions