简体   繁体   中英

IntelliJ or Eclipse refactoring all usages of a method to a method on a different class/interface

Java class com.company.session.old.SessionContext is used throughout our code base among other in the following way (around 1k usages):

import com.company.session.old.SessionContext;

...
SessionContext ctx = SessionContext.create();

I would like to migrate it to a new implementation, which would read:

import com.company.session.SessionContext;
import com.company.session.SessionContextManager;

...
SessionContext ctx = SessionContextManager.instance().create();

Imports are easy to migrate with full text search and replacement. The migration of the actual call SessionContext.create( to SessionContextManager.instance().create( could also be done that way. Now the problem is that this would leave SessionContextManager not imported and one would need to open all those files with replacements to auto-organise imports.

Does IntelliJ or Eclipse provide functionality to search for all usages of a method and replace that with a completely different method not via plain text search but via some code processing mechanism?

In IntelliJ IDEA, the easiest way to perform this refactoring is to change the implementation of SessionContext.create() so that it calls SessionContextManager.instance().create() and then to inline the method. You can restore the old implementation after the inline has updated all the usages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM