Move refactoring moves routine away

AppCode offers a wide variety of code refactorings, which track down and correct the affected code references automatically. Some of them are widely known and often used, others are just missed. Move refactoring is present in AppCode since 2.1 version, but have you ever used it? Let’s take a closer look at it.

Generally speaking there’s nothing special about Move refactoring, but in complex projects with a large code base it really saves your time when, for example, you move a method to a new place that turns out to be a lot harder than you thought it would be. The Move refactoring allows you to move classes, protocols, methods, functions within a project – AppCode automatically corrects all references to the moved symbols in the source code.

To invoke Move action press F6. Another way is to call ‘Refactor This’ action with Ctrl+T and select Move there.

When moving class members AppCode lists all available members in a dialog form and highlights with red those that are used by the selected members (hover the mouse on any of these red members to find out which one exactly is using it):
move_member_dialog
AppCode also groups members and marks properties, instance variables, interface methods, etc. with an appropriate icons to help you navigate easier through the list.

You can move members to an existing class – start typing the name and AppCode will help you completing it. Another option is to search it by its name or just look through the whole project. In any case, for easier navigation over the items AppCode highlights matches for you – just type a couple of letters from the name you are looking for:
search_class_in_project
If the proper class doesn’t exist just type its name in the destination field and AppCode will create it for you.

You can now refactor immediately, or use the Preview button to see the changes that will be performed. All the usages of the moved element are grouped by type and location, plus you can easily exclude usages you don’t want to modify:
refactoring_preview

AppCode will search all references of these members and make sure they are updated. The IDE will notify you about potential problems as well and suggest to look through the conflicts in a separate window:
find_conflicts

You can still refactor if you are sure or cancel it, if you agree with the usage conflicts.

Try the same workflow to also move functions, classes or protocols!
See more tips’n’tricks.

This entry was posted in Tips'n'Tricks and tagged , . Bookmark the permalink.

2 Responses to Move refactoring moves routine away

  1. Jay says:

    I’d just wish AppCode refactorings weren’t horribly buggy as they still are.. Reliable refactorings..? ROTFL. 3 out of 5 refactorings create just plain wrong code that won’t compile (and doesn’t make much sense either).
    Extremely disappointing if you’re used to rock-solid refactoring provided by other JetBrains products – in particular ReSharper….

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">