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

Bug 341065

Summary: [quick fix] Content Assist and Quick Fix fails to generate correct type of variable for overloading methods
Product: [Eclipse Project] JDT Reporter: Jerry Mising name <commer>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, markus.kell.r
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
overloading methods
none
ready to input a variable of type LinkedHashMap
none
finished input the variable name.
none
Quick Fix to define this variable.
none
wrong type.
none
this is what I want. none

Description Jerry Mising name CLA 2011-03-28 01:48:10 EDT
Build Identifier: 20110218-0911

For example, object x has 2 methods:
y(Type1 z);
y(Type2 z);

At x.y(|), I use ctrl+space to generate a parameter, IDE prompts me to select a type between Type1 and Type2. But after that, I use Quick Fix to generate the declaration of the variable, the generated variable may have different type than I selected before.

Reproducible: Always

Steps to Reproduce:
See attachments.
Comment 1 Jerry Mising name CLA 2011-03-28 01:50:37 EDT
Created attachment 191970 [details]
overloading methods

Ctrl+Space will prompt overloading methods, highlight 1st (type is LinkedHashMap) one and hit Enter.
Comment 2 Jerry Mising name CLA 2011-03-28 01:51:48 EDT
Created attachment 191971 [details]
ready to input a variable of type LinkedHashMap
Comment 3 Jerry Mising name CLA 2011-03-28 01:54:18 EDT
Created attachment 191972 [details]
finished input the variable name.

Hoping it will has a LinkedHashMap type later.
Comment 4 Jerry Mising name CLA 2011-03-28 01:55:38 EDT
Created attachment 191973 [details]
Quick Fix to define this variable.

Hoping it will have a LinkedHashMap type.
Comment 5 Jerry Mising name CLA 2011-03-28 01:56:30 EDT
Created attachment 191974 [details]
wrong type.

But the generated variable has a String type.
Comment 6 Jerry Mising name CLA 2011-03-28 01:58:29 EDT
Created attachment 191975 [details]
this is what I want.
Comment 7 Ayushman Jain CLA 2011-03-28 03:25:21 EDT
Comer, content assist and quick fix are 2 separate operations here and do not feed any info to and from each other. Using content assist inside the () will only tell you what all parameters are possible, and all the overloaded instances of the method. Quick fix does not know which overloaded method you intend to call here. It only tries to fix the error at hand in the best possible way, and the current quick fix is correct that way.

Moving to JDT/UI for comment. Perhaps, quick fix can prompt the user in case more than 1 suggestions make sense?
Comment 8 Jerry Mising name CLA 2011-03-28 04:15:24 EDT
In case of more than 1 types are available, prompt user for types is definitely of higher priority.

If "It only tries to fix the error at hand in the best possible way",  then providing only "create local variable" is enough, since user can always achieve "create field" or "create parameter" by refactoring.

If we compare:
1. providing options to create local variable, field or parameter
with
2. providing options to create available types,
personally I think the latter is more important.

What do you think?
Comment 9 Markus Keller CLA 2011-03-28 13:00:08 EDT
The problem is that we infer the type of the variable by looking at the binding of the enclosing method invocation. If the method is overloaded, we just get the first method with the right name and hence we take the type from there.

The fix will require a bit of infrastructure work: ASTResolving#guessBindingForReference(ASTNode) needs to return an ITypeBinding[] and the implementation needs to consider the alternatives (check similar methods in methodBinding.getDeclaringClass().getDeclaredMethods()).


Self-contained example:

package xy;
import java.util.LinkedHashMap;

public class Try {
    void foo(Column c) {
        c.setValueMap(valueMap);
    }
}

class Column {
    void setValueMap(String... valueMap) {}
    void setValueMap(LinkedHashMap<String, String> valueMap) {}
}
Comment 10 Eclipse Genie CLA 2019-12-02 09:00:29 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.