【问题标题】:IntelliJ or Eclipse refactoring all usages of a method to a method on a different class/interfaceIntelliJ 或 Eclipse 将方法的所有用法重构为不同类/接口上的方法
【发布时间】:2018-03-29 07:59:08
【问题描述】:

Java 类 com.company.session.old.SessionContext 在我们的代码库中以下列方式使用(大约 1k 次使用):

import com.company.session.old.SessionContext;

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

我想将它迁移到一个新的实现,内容如下:

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

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

通过全文搜索和替换,导入很容易迁移。实际呼叫SessionContext.create(SessionContextManager.instance().create( 的迁移也可以通过这种方式完成。现在的问题是,这会使SessionContextManager 不导入,并且需要打开所有这些文件并替换为自动组织导入。

IntelliJ 或 Eclipse 是否提供功能来搜索方法的所有用法并用完全不同的方法替换它,而不是通过纯文本搜索,而是通过一些代码处理机制?

【问题讨论】:

    标签: java eclipse intellij-idea automated-tests refactoring


    【解决方案1】:

    在 IntelliJ IDEA 中,执行此重构的最简单方法是更改​​ SessionContext.create() 的实现,使其调用 SessionContextManager.instance().create(),然后内联该方法。在内联更新所有用法后,您可以恢复旧实现。

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多