I'm trying to rename a method in my Eclipse Java project, but it seems to be renaming every method which has the same name. (Perhaps I'm misunderstanding what this feature 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 f
method in C2
, and select "rename" from the "refactor" menu to rename it to g
, C1.Listener.f
is also renamed, resulting with C1
being changed to this:
public class C1 {
interface Listener {
void g();
}
public C2.Listener c2l = new C2.Listener() {
public void g() {
}
};
}
I expected it 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 make it only rename C2.Listener.f
?
I tried in Eclipse Helios and Android Development Tools 22.3.0.
This seems like a bug in Eclipse and seems to happen on Kepler too. Even so you can work around it by following the steps below:
Goto Preferences > Java. On that page in under the header "Refactor Java Code", uncheck the option "Rename in editor without dialog"
Now when you Refactor it gives you an option to Preview your changes and here you can uncheck the box to apply the changes to C1.Listener()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With