Bug 444870 - [quick assist] Ctrl+2, L or Ctrl+2, F should also import the required type to avoid a syntax error
Summary: [quick assist] Ctrl+2, L or Ctrl+2, F should also import the required type to...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 479030 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-09-23 14:47 EDT by Lars Vogel CLA
Modified: 2015-10-28 19:20 EDT (History)
6 users (show)

See Also:


Attachments
Animated Gif (46.56 KB, image/gif)
2015-10-27 09:52 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2014-09-23 14:47:00 EDT
I frequently use the Ctrl+2, L and end up with an syntax error. For example in Android:

findViewByID(R.id.text1) 

Ctrl+2, L create the following:

View view = findViewByID(R.id.text1);

But I also need to trigger the organize import (of a save action) to also add the import statement. 

I think JDT should also add the import statement. If you agree and don't have the capacity to implement this, let me know, we (Simon or I) can look into this.
Comment 1 Noopur Gupta CLA 2014-09-24 01:30:46 EDT
I cannot reproduce the issue. Example:

import java.util.ArrayList;

class Test extends BugExample {
	{
		(new ArrayList<String>()).stream();
	}
}

Ctrl+2, L also adds the "import java.util.stream.Stream;" by default.

Please provide a stand-alone example where it does not work.
Comment 2 Noopur Gupta CLA 2014-10-01 02:23:30 EDT
Closing as WORKSFORME. Please re-open with a stand-alone example to reproduce the issue.
Comment 3 Lars Vogel CLA 2014-10-01 15:42:27 EDT
Noopur, I have a hard time reproducing this outside of an Android project and I guess you don't want to install the ADT tools.

Could you tell me the class which is triggered by this shortcut? I can try to debug it, and see why it does not work in the Android example.
Comment 4 Markus Keller CLA 2014-10-03 11:20:58 EDT
To find out what happens when you press a shortcut, set a breakpoint in 
KeyBindingDispatcher#executeCommand(..) and step through. I know this became a bit painful with E4, but maybe you could work on that?

QuickAssistProcessor#getAssists(..) and ExtractTempRefactoring#checkInitialConditions(..) are potential entry points.
Comment 5 Lars Vogel CLA 2015-10-27 09:52:48 EDT
Created attachment 257542 [details]
Animated Gif

Here is a simple code example in a standard Java program:

1.) Create the following class
public class Main {

	public static void main(String[] args) {
	}

}

2.) Copy and paste new ArrayList<>() into it (do not type it)
3.) Use Ctrl+2, l to assign it to a local variable

-> Import is not added. See animated Gif as example
Comment 6 Lars Vogel CLA 2015-10-27 09:53:10 EDT
See comment 5
Comment 7 Dani Megert CLA 2015-10-28 04:44:39 EDT
*** Bug 479030 has been marked as a duplicate of this bug. ***
Comment 8 Stephan Herrmann CLA 2015-10-28 19:20:58 EDT
title and comment 0 should probably say "resolve error" instead of "syntax error", right? I would be weird if a quick assist really creates a syntax error.