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

Bug 159262

Summary: [rename method] renames wrong method
Product: [Eclipse Project] JDT Reporter: Sergey Yevtushenko <sergey.yevtushenko>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: frederic_fusier
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Sergey Yevtushenko CLA 2006-09-29 08:10:03 EDT
Consider following hierarchy:

--------------------------------
public interface Zhope 
{
    void method();
}

public class ZhopeBase 
{
    public void method() 
    {
        System.out.println("method!");
    }
}

public class ZhopeChild extends ZhopeBase implements Zhope 
{
} 
--------------------------------

Renaming method name in interface Zhope renames it also in ZhopeBase, although this class does not implement Zhope interface.
Comment 1 Olivier Thomann CLA 2006-09-29 09:21:30 EDT
Move to JDT/UI
Comment 2 Frederic Fusier CLA 2006-09-29 09:52:52 EDT
It sounds to be a Search Engine issue as searching for declaration of Zhope.method() in project returns ZhopeBase.method-) as exact match!
Comment 3 Frederic Fusier CLA 2006-09-29 10:59:33 EDT
Finally, problem is in JDT/UI land as it search for declaration ignoring declaring and return types...
Perform a search using Java Search dialog correctly returns only one match...
=> move back to JDT/UI
Comment 4 Markus Keller CLA 2006-12-06 11:26:37 EST
This is a feature, not a bug ;-)

The Rename Method refactoring renames all related methods in the ripple (up and down the type hierarchies). If we would not do this, the refactoring would produce compile errors.

See also explanation in bug 83293.
Comment 5 Sergey Yevtushenko CLA 2006-12-06 14:16:34 EST
Although I agree that current solution for #83293 makes sense, this case is a bit different, because a) method in ZhopeBase has a bit different signature and b) there are not two interfaces but base class AND interface. I can even imagine situation when such a splitup (i.e. partil renaming of the methods) may be what is really necessary. Perhaps it worth to add a warning + checkbox and let user decide if to rename all implementations/declarations or just part of them. In case of large hierarchy selecting each class manually might be very inconvenient and error prone.
Comment 6 Markus Keller CLA 2006-12-06 14:33:31 EST
> a) method in ZhopeBase has a bit different signature

No, the signatures are the same (no parameters). Modifiers don't matter here (and are actually also equal because interface methods are implicitly public).

> b) [..] I can even imagine situation when such a splitup (i.e. partil
> renaming of the methods) may be what is really necessary.

I agree that this is sometimes necessary, but unfortunately, it can't be done with an automated refactoring. If you have a variable 'ZhopeChild ch' and a call 'ch.method()', then there's no way to tell which method was "really" meant.
Comment 7 Sergey Yevtushenko CLA 2006-12-06 14:38:07 EST
Agree. But I did mean just warn user about the conflict and let him decide which branch (or both) to rename. Silent operation here is not a best choice.
Comment 8 Sergey Yevtushenko CLA 2006-12-06 14:38:20 EST
Agree. But I did mean just warn user about the conflict and let him decide which branch (or both) to rename. Silent operation here is not a best choice.