How to automatically rename a Java method in Eclipse?

I am trying to rename a method in my Java Eclipse project, but it seems to rename each method with the same name. (Maybe I don't understand what this function is for - maybe it's just using sed?)

Here is a simplified example:

public class C1 { interface Listener { void f(); } public C2.Listener c2l = new C2.Listener() { public void f() { } }; } 

  public class C2 { interface Listener { void f(); } } 

If I select the method f in C2 and select “rename” from the “refactoring” menu to rename it to g , C1.Listener.f also renamed, as a result of which C1 will be changed to this:

  public class C1 { interface Listener { void g(); } public C2.Listener c2l = new C2.Listener() { public void g() { } }; } 

I expected this to be changed to this:

  public class C1 { interface Listener { void f(); } public C2.Listener c2l = new C2.Listener() { public void g() { } }; } 

Is there a way to do this by only renaming C2.Listener.f ?

I tried in Eclipse Helios and Android Development Tools 22.3.0.

+6
source share
1 answer

This seems like a bug in Eclipse, and it seems like Kepler too. Even so, you can get around it by following these steps:

Go to settings> Java. On this page, under the heading "Refactor Java Code", uncheck the box "Rename in editor without dialog"

Now that you are Refactor, you get the opportunity to view your changes, and here you can uncheck the box to apply the changes to C1.Listener ()

+4
source

All Articles