Guys, here is my problem: I have some class which is used in many places in my project. And I must replace this class with another from jar provided. Is there any ways to refactor this? I suppose this is a simple problem, but I dont know how to solve it.
Its not about replacing source code - what I want is to replace all class usages by class from my library and be able to completely remove my own class. Imagine I have created my own StringUtils and have found out that there is a apache.common StringUtils library, and now I want to use it everywhere in my code. And the signatures of class methods are not a problem: they coincide.
?
Rename Dialog for a Class or an Interface. Shift+F6. Use this dialog to rename a class or an interface. In addition to renaming the class or the interface itself, IntelliJ IDEA can also look for the usages of the class or the interface name. If found, the changes you are making to the class or the interface name can also be applied to these usages.
This is more likely to "find and replace" operation, to find something like Name:String = "***"; and replace it with Name:String = ""; in all cases. How can i do this with Intellij IDEA? if it is in one file : ctrl + r check the tick box Regex and look for Name:String = " [^"]*" : this should match what you want.
IntelliJ IDEA lists the search strings and the files that contain them. If the search string is found several times on the same line of code, IntelliJ IDEA merges the results in one line.
IntelliJ IDEA lists the search strings and the files that contain them. If the search string is found several times on the same line of code, IntelliJ IDEA merges the results in one line. To do a multi-line search, click the icon to enter a new line, and press Ctrl+Alt+Down / Ctrl+Alt+Up to browse through occurrences.
There is this "migrate" function. Right click in whatever class -> Refactor -> Migrate.
It's a bit annoying that you have to create a new migrate set and you can't run it from scratch. But it does exactly what you need.
You pick class or package to migrate and tell it to which class or package it should change. Press run and all usages are rewritten. Then you're free to delete the old class because there will be no usages.
EDIT: In the newer versions it isn't in the context menu anymore. Just go to the menu on top - Refactor - Migrate (or simply pres shift twice and type migrate).
Cheers!
If you are using static methods (like your StringUtils example suggests), delegate to the new class in your previous implementation like
public static String myOldMethod(String argument) {
return MyNewClass.myNewMethod(argument);
}
then select Refactor->Inline and select "All invocations and remove the method" in the option dialog. In this way you can handle method name changes and argument order changes are well.
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