groovy / groovy/groovy-eclipse
"Editor > Typing > Automatically insert at correct position > Braces" conflicts with typing constructors with single Closure or SAM-type parameter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 681
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
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...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Java > Editor > Typing > Automatically insert at correct position > Braces setting and the code-assist path exercised by the two GBean constructor examples. Compare the behavior addressed by #1093; done means both constructor calls keep the opening brace inside the parentheses, while an explicitly positioned anonymous-class brace still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100