In this blog post, we will cover the Move refactoring option as we continue to explore the refactorings provided by the IDE.
If you want to check out the other articles from this series, you can find them all here (links will be updated as new articles are published):
This is currently my second favorite refactoring, especially during the phase of the project that needs me to restructure how the code is organized.
With the Move refactoring, you can take any top-level named identifier from your source code and move it either to a separate file or to an entirely different package, existing or new.
In the example below, we can see how to move a function declaration to a new file.
The Move refactoring does not only move the declarations, but will also add the required imports, update the references to the identifier, and perform a cleanup of the previous definition place of the identifier so that your code can still work.
You can choose to export declarations when using this move, move related declarations, or move multiple declarations at once. And if you want to see which code paths are affected by this change, you can preview the locations that will be affected, with the option to atomically undo everything using the Undo shortcut.
That’s it for today. We hope the Move refactoring will become an invaluable tool under your toolbelt if it isn’t already!
As we approach the end of this series on refactorings, we look forward to your feedback both on what we can talk about in future posts, as well as what features you’d like to see in the IDE.