简体   繁体   English

Eclipse重构所有方法调用

[英]Eclipse Refactor all method call

In eclipse java i used a static method call in several places. 在Eclipse Java中,我在多个地方使用了静态方法调用。

A.method1();

How can i change these all calls in one change using refacor to B.method2() 如何使用refacor对B.method2()进行一次更改来更改所有这些呼叫

Solution based on code refactoring called "Inline ...", it replaces every method call with its implementation. 基于代码重构的解决方案称为“ Inline ...”,它将其实现替换为每个方法调用。 Example: Before we have: obj1.method1(){}; 示例:在拥有之前: obj1.method1(){}; and obj2.method2(obj1){ obj1.method1(); }; obj2.method2(obj1){ obj1.method1(); }; obj2.method2(obj1){ obj1.method1(); };

After applying eclipse refactoring "Inline ..." we will have every call of obj2.method2(obj1); 在应用eclipse重构“ Inline ...”之后,我们将调用obj2.method2(obj1); replaced with call obj1.method1() ; 替换为调用obj1.method1() ;

That was easy! 那很简单!

I think the easy way is by press ctrl+f to open find/replace window, then you can replace your code in one shot by clicking "Replace All" like this: 我认为最简单的方法是按ctrl + f打开查找/替换窗口,然后您可以通过单击“全部替换”来一次性替换代码:

在此处输入图片说明

if you are trying to replace the signature only not the method name then you can do so by alt+shift+c here is a reference : 如果您仅尝试替换签名而不是方法名称,则可以通过alt + shift + c进行替换, 这是一个参考

if you are trying to change the method name, then go to class which you defined the method in it the press alt+shift+r to rename the method declaration in that class and everywhere you call it. 如果要更改方法名称,请转到在其中定义了方法的类,请按alt + shift + r重命名该类中以及调用该类的方法声明。 and here is a reference: 这里是参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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