IntelliJ IDEA 2016.3 Help

Move Refactorings

On this page:

Move refactorings: basics

Move refactorings allow you to move packages and classes between the source roots of a project, class members to other classes and inner classes to upper hierarchy levels. The move refactorings automatically correct all references to the moved packages, classes and members in the source code.

The following move refactorings are available:

  • Move Package moves a package and its contents to another package or directory under the specified source root. When you move a package, you can choose between the following refactorings:
    • Move package to another package.
    • Move directory to another source root.
    • Move directory to another directory.
  • Move Class refactoring enables you to:
    • Move a class to a package under the specified source root.
    • Make a class an inner class.
  • Move Static Members moves a static field, method or inner class to another class.
  • Move Inner to Upper Level:
    • In Java, this refactoring moves an inner class to a higher level.
    • In ActionScript, this refactoring moves out-of-package classes, functions, variables, constants and namespaces into a package. (In this case the word inner is used to refer to entities (classes, functions, etc.) that are declared outside of packages. The upper level means a package.)
  • Move Instance Method refactoring moves an instance method to another class.
  • Move File refactoring moves a file to another directory.

Performing Move refactoring

To perform a Move refactoring, follow these general steps:

  1. Select the symbol to be moved and do one of the following:
    • On the Refactor menu, or on the context menu, choose Move.
    • Press F6.
    • In the Project tool window, drag the symbol to the new location.

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

  2. Specify the move options according to the type of the item to be moved. See option descriptions in the Move dialog box reference.
  3. Preview and apply the changes.

Moving a package

To move a package, follow these steps:

  1. Select the package in the Project tool window, and press F6, or just drag the selected package.
  2. In the Select Refactoring dialog box, click one of the options to specify which refactoring should be performed.
    • To move the whole package to another package select the first option, click OK, then specify the move options in the Move dialog box.
    • To move the directory to another source root, select the second option, click OK, and specify the destination source root.
    • To move the directory to another directory, select the third option, click OK, and specify the destination directory.

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.


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: 7 December 2016