Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 127367 - [quick fix] Quick Fix should suggest "add generic parameter to class type"
Summary: [quick fix] Quick Fix should suggest "add generic parameter to class type"
Status: RESOLVED DUPLICATE of bug 124848
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 07:45 EST by Max Gilead CLA
Modified: 2006-03-02 08:03 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Gilead CLA 2006-02-11 07:45:02 EST
I suggest to add a Quick Fix: "add generic parameter to class type" when invoked over piece of code like this:

public class Test {
  Class<String> get() { return null; }
  void foo() {
    // WARNING: Class is a raw type.
    // References to generic type Class<T> should be parameterized
    Class c = get(); // <--- warning
  }
}

Solution is to convert line with warning to "Class<String> c = get();" and Eclipse can easily infer what the type should be from the right side of the expression.
I'm just converting large piece of code to generics and most if not all of cases could be solved by quick fix like this.
Comment 1 Martin Aeschlimann CLA 2006-02-12 13:08:14 EST
That's already fixed in the latest 
Comment 2 Max Gilead CLA 2006-03-02 07:36:58 EST
I'm afraid that latest changes are not what this bug report was about or they don't work properly.

Current Eclipse is unable to fix the above example. I would expect that quick fix can detect that proper type of Class should be String, instead:
- 'Add type parameter to Class' suggest two options: ? and Object
- 'Infer Generic Type Arguments' does nothing or adds <?> type to Class (depending on the user interface option selected)

Additionally, problem with the latter is that it works on entire file instead of just single problem (like all other Quick Fix-es seem to do). Problem with this is that, in complicated code, each such correction need to be reviewed individually (which is currently impossible). Saving file before/after each fix is also time-consuming.

Tested with:
Version: 3.2.0
Build id: I20060221-1300
Comment 3 Benno Baumgartner CLA 2006-03-02 08:03:49 EST
Sorry, you're right, it does not work. But it's a dup.

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