Bug 377658

Summary: [quick fix] 'Add Import' Quickfix should consider return type of RHS of an assignment
Product: [Eclipse Project] JDT Reporter: Marcel Bruch <marcel.bruch>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, deepakazad, markus.kell.r
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 87950    
Bug Blocks:    
Attachments:
Description Flags
not that smart quickfix for type imports
none
Another scenario in throw/catch statements none

Description Marcel Bruch CLA 2012-04-25 12:01:11 EDT
Created attachment 214541 [details]
not that smart quickfix for type imports

Given a field declaration of

Logger log = org.slf4j.LoggerFactory.getLogger(getClass());

with Logger not being imported yet, quickfix proposes all types of Logger but the only correct one is at the bottom of the list (see screenshot).

It would be nice if quickfix would consider the right hand side of the assignment to determine the best matching type.
Comment 1 Marcel Bruch CLA 2012-04-27 10:03:53 EDT
Created attachment 214704 [details]
Another scenario in throw/catch statements

In this case an instance of the aether exception is thrown. It's not a supertype of the other exception which makes the first proposal a false recommendation.
Comment 2 Markus Keller CLA 2012-04-27 13:29:30 EDT
This would be even more useful for Organize Imports (bug 87950).
Comment 3 Marcel Bruch CLA 2012-05-12 04:31:44 EDT
Since this is an "old" bug (origins in bug 87950): Is this something that waits for external contributions or will it become part of the planned features for 3.9?



BTW:
Each semester we organize an Eclipse hands-on in which students develop a feature for one of our university projects. These topics should be solvable in ~180 hours by a student in the 5th semester. To me these enhancements look like good candidate topics for this hands-on. 

Let me know if JDT team would be interested in this. Give a (short) list of non-urgent features you think can be solved by students, I can announce these topics, search for students that do open-source coding for grades, and assist them to get going. In conjunction with Gerrit I can imagine this to work out quite well for JDT.
Comment 4 Dani Megert CLA 2012-05-14 04:41:59 EDT
(In reply to comment #3)
> Since this is an "old" bug (origins in bug 87950): Is this something that waits
> for external contributions or will it become part of the planned features for
> 3.9?

The JDT team will have to focus its time during Kepler on Java 8 plus critical bug fixes. Most likely we won't have time for any other feature work. This also means, no time to accept larger contributions.
Comment 5 Markus Keller CLA 2012-05-14 07:06:45 EDT
Another common problem for such bugs is that the right solution is usually not to add code that implements the request, but to find existing code that already implements most of the feature (ASTResolving#guessBindingForReference(ASTNode) in this case) and then
- make the code reusable without breaking existing clients
- make sure you don't add performance problems (not a big deal for "Add Import", but a crucial point for "Organize Imports")