Skip to content

"Editor > Typing > Automatically insert at correct position > Braces" conflicts with typing constructors with single Closure or SAM-type parameter #1108

@mauromol

Description

@mauromol

Consider this:

package test68

class GBean {
	
	public GBean(String foo, Closure c) { }
	
	public GBean(Closure c) {}
}

and this:

package test68

class Test68 {

	void foo() {
		def g1 = new GBean('foo', |)
		def g2 = new GBean(|)
	}
}

Invoke code assist at "|".

If the option "Automatically insert at correct position" | "Braces" in Java | Editor | Typing is checked and you try to write a constructor call with a closure as its last parameter, the opening brace is pushed outside the round parenthesis, so that the final result is the creation of an anonymous inner class instead of a constructor call.

#1093 fixed the issue for the g1 case in the above example, by considering the presence of the "comma" the discriminator to avoid such a behaviour.
However in the g2 case the problem persists.

I think the common case here is to call the constructor, while creating an anonymous inner class is a much less common case. Especially in Groovy, especially in Java 8+ days.
It's more natural to me to move the cursor after the round closing parenthesis and then opening the brace whenever I really want to create an inner class, rather than letting the editor decide for me that I do not want to call the constructor, but rather to create an anonymous inner class, and hence moving away the cursor from the point where I really wanted to insert my brace...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions