Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 546931 - [content assist] Automatically insert at correct position - Braces - Lambda
Summary: [content assist] Automatically insert at correct position - Braces - Lambda
Status: CLOSED DUPLICATE of bug 560919
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.11   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.16 M1   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-02 10:50 EDT by T3rm1 CLA
Modified: 2021-04-27 17:16 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description T3rm1 CLA 2019-05-02 10:50:18 EDT
Does not work.

	static class Clazz {		
		public Clazz(Foo foo) {
		}
	}

	@FunctionalInterface
	public interface Foo extends Serializable {
		public void buttonClick(String event);
	}

Somewhere in code we have:

	new Clazz(e -> e.chars());

Then we place the cursor after the arrow and insert a curly brace.

Not possible. It is inserted at the end of the line.
Comment 1 Dani Megert CLA 2019-05-02 11:58:38 EDT
Please provide a working example/snippet.
Comment 2 Stephan Herrmann CLA 2019-05-02 16:22:04 EDT
Minimally extended:

//---
package n;
import java.io.Serializable;

class Clazz {		
	public Clazz(Foo foo) {
	}
	static void test() {
		new Clazz(e -> e.chars());
	}
}

@FunctionalInterface
public interface Foo extends Serializable {
	public void buttonClick(String event);
}
//---

Indeed trying to create
		new Clazz(e -> { e.chars());
produces
		new Clazz(e -> e.chars()); {


Similarly, I just tried to insert { into a string literal. Also broken:

//---
class Page {
	void test(Page page) {
		page.setStatus(new Status(
				"Sources {0} and cannot patch different modules because both share the same output location"));
	}
	public void setStatus(Status status) {
	}
}
class Status {
	public Status(String string) {
	}
}
//---

Try to type {1} between "and" and "cannot". Not possible.
Comment 3 T3rm1 CLA 2019-05-03 02:41:46 EDT
Thank you Stephan. What does Dani Megert mean with "provide a working example/snippet"?
All he has to do is copy & paste 9 lines of code into a class :o
Comment 4 Noopur Gupta CLA 2019-05-03 03:02:55 EDT
Once you type '{' which is moved to the end, you can press 'Backspace' key to bring it back to the original position where you typed. Or, you can disable it in the preferences.

But pressing 'Enter' after that (if you wanted to insert the lambda body in braces) will result in bug 466723. The suggestion is to use the quick assist "Change body expression to block" at lambda expression until that bug is fixed.
Comment 5 Dani Megert CLA 2019-05-03 04:35:36 EDT
(In reply to T3rm1   from comment #3)
> Thank you Stephan. What does Dani Megert mean with "provide a working
> example/snippet"?
> All he has to do is copy & paste 9 lines of code into a class :o
What I mean that one should be able to copy & paste without getting errors or having to do additional work. See the snippets from Stephan.
Comment 6 T3rm1 CLA 2019-05-03 05:16:03 EDT
Oh, I see, you mean the missing import of java.io.Serializable. That's indeed reason enough to set the status to INVALID and RESOLVED.

Pro tip: If your IDE is set up correctly, it can do the work for you!
Comment 7 Dani Megert CLA 2019-05-03 05:54:07 EDT
(In reply to T3rm1   from comment #6)
> Oh, I see, you mean the missing import of java.io.Serializable. That's
> indeed reason enough to set the status to INVALID and RESOLVED.
> 
> Pro tip: If your IDE is set up correctly, it can do the work for you!
I do not need the pro tip ;-). The (missing) import was added by the IDE but the given snippet does not compile. In addition, the the mentioned code "new Clazz(e -> e.chars());" is not part of your snippet.

Yes, I could have left the bug open and wait for the snippet, but many times, there's no further answer and the bug then remains open forever. There's no problem reopening the bug report once the complete example is provided.
Comment 8 Stephan Herrmann CLA 2019-05-03 09:49:07 EDT
(In reply to Noopur Gupta from comment #4)
> Once you type '{' which is moved to the end, you can press 'Backspace' key
> to bring it back to the original position where you typed. Or, you can
> disable it in the preferences.

I read this as a workaround, not an excuse for the current behavior, right?

Dani, I had raised the severity since some of this business of "I know better where the brace should go" business left even me quite clueless (and angry :) ). Neither is the backspace workaround obvious, nor should the editor ever misplace any keystrokes sent into a string literal, never.

Generally, this feature should probably be more careful to prefer erring on the side of not helping rather than breaking a perfectly valid workflow.
Comment 9 Dani Megert CLA 2019-05-03 10:09:24 EDT
(In reply to Stephan Herrmann from comment #8)
> (In reply to Noopur Gupta from comment #4)
> > Once you type '{' which is moved to the end, you can press 'Backspace' key
> > to bring it back to the original position where you typed. Or, you can
> > disable it in the preferences.
> 
> I read this as a workaround, not an excuse for the current behavior, right?
Yes.

 
> Dani, I had raised the severity since some of this business of "I know
> better where the brace should go" business left even me quite clueless (and
> angry :) ). Neither is the backspace workaround obvious, nor should the
> editor ever misplace any keystrokes sent into a string literal, never.
> 
> Generally, this feature should probably be more careful to prefer erring on
> the side of not helping rather than breaking a perfectly valid workflow.
Yes, but AFAIK we classified those under 'normal'. Feel free to raise the severity again if it is really major for you (compared to other major issues). I'd be fine with that.
Comment 10 Eclipse Genie CLA 2021-04-23 11:33:14 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 11 Jeff Johnston CLA 2021-04-27 16:12:27 EDT
This appears to have been fixed.  I am using 4.20 M1 and both scenarios from Stephan work fine (i.e. the bracket is not added to the end of the line).

Stephan can you confirm that we can close this bug?
Comment 12 Stephan Herrmann CLA 2021-04-27 17:13:34 EDT
(In reply to Jeff Johnston from comment #11)
> This appears to have been fixed.  I am using 4.20 M1 and both scenarios from
> Stephan work fine (i.e. the bracket is not added to the end of the line).
> 
> Stephan can you confirm that we can close this bug?

Cool it works! :)

Fixed apparently via bug 520081 and bug 560919. The latter is the one for the lambda case.

*** This bug has been marked as a duplicate of bug 560919 ***