AppCode 2016.3 Help

Move Refactorings

On this page:

Move refactorings: basics

The Move refactorings allow you to move classes, protocols, methods, functions, files and directories within a project. So doing, AppCode automatically corrects all references to the moved symbols in the source code.

Moving a file or a directory to another directory

To move a file or directory to another directory, follow these steps:

  1. Select the file or directory in the Project tool window.
  2. Do one of the following:
    • On the main menu, choose Refactor, and then choose Move.
    • On the context menu of the selection, choose Refactor, and then choose Move.
    • Press F6.

    The dialog that opens depends on the type of the selected symbol.

  3. In the To directory field, specify the folder to move the selected file or folder to. Choose an existing folder from the drop-down list or type the full path to the parent folder to be created.
  4. To have the references to the selected file or folder updated according to the refactoring result, select the Search for references check box.

Moving declarations or members

To move declarations or members, follow these steps:

  1. In the editor, place the caret at the class, protocol or the member you want to move.
  2. Do one of the following:
    • On the main menu, choose Refactor, and then choose Move.
    • On the context menu of the selection, choose Refactor, and then choose Move.
    • Press F6.
  3. In the dialog box that appears, select declarations/members you want to move.
  4. Select the target file/class or specify a name if you want to create a new file/class.
  5. Do one of the following:
    • Click Move to finish the refactoring.
    • Click Preview to see the changes that will be performed. All the usages of the moved element are grouped by type and location. To exclude a usage you don’t want to modify, right-click on it and choose Exclude from the drop-down menu. AppCode will search all references of these members and make sure they are updated. The IDE will notify you about potential problems and suggest to look through the conflicts in the separate Find Conflicts window. You can still proceed with refactoring or cancel it by clicking the corresponding buttons.

Moving function/method to the top-level

This refactoring moves local functions or methods to the top-level by converting references to instance attributes or variables from enclosing scopes to parameters and updating existing usages accordingly.

To move a function or a method to top-level, follow these steps:

  1. Place the caret at the local function or method name.
  2. On the main menu, or on the context menu of the editor, choose Refactor | Move, or press F6.
  3. In the Make Method Top-Level dialog box that opens, specify the destination of move. You can type it manually, or click the browse button /help/img/idea/2016.3/browseButton.png and locate the destination file in the Choose Destination File dialog.
  4. Click Refactor to perform the refactoring, or Preview, to shows the preview in the Find tool window. If satisfied with the preview results, confirm move by clicking Do Refactor.

Example

BeforeAfter
import math class Solver(object): def __init__(self,a,b,c): self.a = a self.b = b self.c = c def demo(self, a, b, c): d = self.b ** 2 - 4 * self.a * self.c if d >= 0: disc = math.sqrt(d) root1 = (- self.b + disc) / (2 * self.a) root2 = (- self.b - disc) / (2 * self.a) print(root1, root2) return root1, root2 else: raise Exception Solver(2, 123, 0.025).demo()
import math class Solver(object): def __init__(self, a, b, c): self.a = a self.b = b self.c = c def demo(b, a, c): d = b ** 2 - 4 * a * c if d >= 0: disc = math.sqrt(d) root1 = (- b + disc) / (2 * a) root2 = (- b - disc) / (2 * a) print(root1, root2) return root1, root2 else: raise Exception s = Solver(2, 123, 0.025) demo(s.b, s.a, s.c)

See Also

Last modified: 6 December 2016