Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 508800

Summary: Quick Assists does not give "Convert to lambda" option in some cases
Product: [Eclipse Project] JDT Reporter: Dean Schulze <dean.w.schulze>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, noopur_gupta, stephan.herrmann
Version: 4.6   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Dean Schulze CLA 2016-12-06 18:33:45 EST
In the following code if I put the cursor after the = on the first line Ctrl+1 gives me the option of converting it into a lambda.  Ctrl+1 is very picky about where I place the cursor.  If it's on the first Runnable or on the System.out.println() Ctrl+1 does not give me the option to convert to lambda.

If I comment out the r.run() command then Ctrl+1 does not give me the option to convert to lambda at all.

I should not have to call r.run() to get the option to convert to lambda.  I also should not have to guess where to put the cursor to get the convert to lambda option.


Runnable r = new Runnable() {
    @Override
    public void run() {
        System.out.println("Hello World");
    }
};

r.run();



Eclipse Build:  20160613-1800
Comment 1 Jay Arthanareeswaran CLA 2016-12-06 23:53:58 EST
Reproduced on master. I planted a breakfast in QuickAssistProcessor#getAssists() and don't see it being hit in the buggy scenario.

Moving to UI for investigation. This might well be a problem in the core, but not sure where to start.
Comment 2 Noopur Gupta CLA 2016-12-07 01:27:21 EST
(In reply to Dean Schulze from comment #0)
> In the following code if I put the cursor after the = on the first line
> Ctrl+1 gives me the option of converting it into a lambda.  Ctrl+1 is very
> picky about where I place the cursor.  If it's on the first Runnable or on
> the System.out.println() Ctrl+1 does not give me the option to convert to
> lambda.

The quick assist to convert anonymous class creation to lambda is provided when you place the caret at the class instance creation node or the method declaration node in the anonymous class i.e. 
		new Runnable() {
			@Override
			public void run() {	
			}
		};
Hence, your observed behavior is as expected.

> If I comment out the r.run() command then Ctrl+1 does not give me the option
> to convert to lambda at all.

I cannot reproduce this. Where do you place the caret? If it's at the first line, then keep in mind that pressing Ctrl+1 first moves the caret position to the unused local variable 'r' warning and shows the list of quick fixes for that. You have to press Ctrl+1 once again to go to the original position and see the quick assists for that position (as mentioned at the bottom of the quick fix popup when the caret is moved to the warning position).
Comment 3 Dean Schulze CLA 2016-12-07 11:21:11 EST
(In reply to Noopur Gupta from comment #2)
> (In reply to Dean Schulze from comment #0)
> > In the following code if I put the cursor after the = on the first line
> > Ctrl+1 gives me the option of converting it into a lambda.  Ctrl+1 is very
> > picky about where I place the cursor.  If it's on the first Runnable or on
> > the System.out.println() Ctrl+1 does not give me the option to convert to
> > lambda.
> 
> The quick assist to convert anonymous class creation to lambda is provided
> when you place the caret at the class instance creation node or the method
> declaration node in the anonymous class i.e. 
> 		new Runnable() {
> 			@Override
> 			public void run() {	
> 			}
> 		};
> Hence, your observed behavior is as expected.
> 
> > If I comment out the r.run() command then Ctrl+1 does not give me the option
> > to convert to lambda at all.
> 
> I cannot reproduce this. Where do you place the caret? If it's at the first
> line, then keep in mind that pressing Ctrl+1 first moves the caret position
> to the unused local variable 'r' warning and shows the list of quick fixes
> for that. You have to press Ctrl+1 once again to go to the original position
> and see the quick assists for that position (as mentioned at the bottom of
> the quick fix popup when the caret is moved to the warning position).


I put the cursor on the Runnable after "new".

I see the functionality that you mention.  I never would have thought to press Ctrl+1 again.  I looked at the list of quick fix options but didn't notice the message at the bottom of the popup.

This is subtle.  I didn't see this mentioned in any of the documentation.

This issue can be closed, but I would encourage adding your explanation to the documentation.
Comment 4 Stephan Herrmann CLA 2016-12-07 14:11:55 EST
(In reply to Jay Arthanareeswaran from comment #1)
> Reproduced on master. I planted a breakfast

was it tasty? :p
Comment 5 Noopur Gupta CLA 2016-12-08 03:35:26 EST
(In reply to Dean Schulze from comment #3)
>
> This is subtle.  I didn't see this mentioned in any of the documentation.
> 
> This issue can be closed, but I would encourage adding your explanation to
> the documentation.

Thanks for the confirmation. It is mentioned in the first paragraph of the documentation here:
http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-java-editor-quickassist.htm&cp=1_4_8_3