Bug 174329 - [quick fix] provide a "parameterize method" fix
Summary: [quick fix] provide a "parameterize method" fix
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 176734 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-02-15 11:26 EST by Tom P. Eicher CLA
Modified: 2009-01-23 11:36 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom P. Eicher CLA 2007-02-15 11:26:40 EST
3.3 M5
see also bug 174327

- Example taken from bug 174265: 

------- Try.java -----------
package org.example;

import java.util.Collections;
import java.util.Map;

public class Try {
    void caller() {
        method(Collections.emptyMap());
    }

    void method(Map<String, String> map) {
    }
}
------------------------------

- there is a compile error in the caller method

> a quick fix to parameterize the emptyMap call could be provided, resulting in the following code:

  method(Collections.<String,String>emptyMap());
Comment 1 Martin Aeschlimann CLA 2007-03-22 06:19:37 EDT
*** Bug 176734 has been marked as a duplicate of this bug. ***
Comment 2 Wassim Melhem CLA 2007-06-27 11:33:07 EDT
Wake up, Becker!

:)
Comment 3 Chris Aniszczyk CLA 2007-06-27 11:58:43 EDT
Hey Becker, instead of working on fancy not-opensourced screenshot tools, what about this one :)?
Comment 4 Karsten Becker CLA 2007-06-27 12:17:03 EDT
Ok, I'm working on it ;)
Infact I had several longer discussions with Martin about this one. And the problem we do have with this one is, that the return type of the Collections.emptyMap() Statement does not contain the parametrized information. This is due to fact of the way the compiler is implemented.
The parameter case differs from the local variable assignment case. In the following case:
Map<String,String> map=Collections.emptyMap();
The compiler would provide resolved parameter Types. In the parameter case these information is discarded as it is not needed, because of the Type Erasure.
The first solution to get these informations would be to create a workingcopy, create an assignment to a variable, parse it, throw the working copy away, and insert it using the newly gained resolved information. Obviously this is not what a quickfix is meant to be, because it is not quick.
The other option would be to as JDT Core for a resolved type for this, which would mean changes to the compiler and changes to the IType+ hierarchy.
As I got assigned to this bug after API freeze the second option was not applicable, and the first too slow.
But I heard that you have some good contacts to JDT Core, so feel free to ask them for the new API ;)
Comment 5 Wassim Melhem CLA 2007-06-28 08:21:29 EDT
Agreed.  Solution #1 may be a fix, but it's not quick by any means.
Comment 6 Martin Aeschlimann CLA 2007-08-17 06:45:42 EDT
Evaluating the type that is needed to case to is quite tricky unless we get extra information from the compiler.
At the moment there are no plans for this.