Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactoring tool in Eclipse

My need is pretty simple: I want to change a method call objClass1.method1() by a call objClass2.method2() in my whole Eclipse project. Unfortunately, I can't find a plugin able to do this. Can you help?

Edit:

To be more accurate, objClass1 is part of a third party library, so I need to change the method calls. I can't start at the method definition. When I right-click on a method1 call, I have no "rename" option in my "Refactor" menu.

I don't want to change or rename my methods. I want to exchange one call by another in my whole project.

An example of what needs to be done:

Before refactoring:

Injector injector=Guice.createInjector(new IContactModule());

After refactoring:

Injector injector=IContactInjectorSingleton.getInjector();

And this needs to be done a several points in my project.

like image 223
Alexis Dufrenoy Avatar asked Jun 14 '26 07:06

Alexis Dufrenoy


1 Answers

What you ask for is no refactoring. A refactoring is defined as "a change that alters the code while not changing the behavior of the code". In this sense renaming a class or renaming a method is a refactoring (you change the code but the program does the same as before). But what you suggest does NOT preserve the behavior of the code so there will never be a "refactoring" for this.

Of course one might be able to write a plugin that is able to perform the text changes you want in a more or less safe way. But this will only work in very specific circumstances (what if your new method needs an argument the old one dons't need? What if there are more than one method with the same name but different parameters? ...). So I don't believe such a plugin exists, nor it makes much sense to develop such a plugin.

like image 178
Arne Deutsch Avatar answered Jun 16 '26 02:06

Arne Deutsch