Previewing and Applying Refactoring Operations

From RAD Studio
Jump to: navigation, search

Go Up to Refactoring Procedures Index


You can preview most refactoring operations in the Refactorings pane (Delphi) and in the Apply Patch pane (C++). Some refactorings occur immediately and allow no preview. The preview shows you how the refactoring engine evaluates and applies refactoring operations to various types of identifiers and other refactoring targets. Previewing is set as the default behavior. When you preview a refactoring operation, the engine gathers refactoring information in a background thread and fills in the information as the information is collected.

If you apply a refactoring operation right away, it is performed in a background thread also, but a modal dialog blocks the UI activity. If the refactoring engine encounters an error during the information gathering phase of the operation, it will not apply the refactoring operation. The engine only applies the refactoring operation if it finds no errors during the information gathering phase.

Preview and apply a Rename operation in Delphi

Follow the steps below to preview and apply a Rename operation in Delphi:

  1. In the Code Editor, right-click an identifier to display the context menu.
  2. Select Refactor > Rename identifierType 'identifierName' context menu command. The Rename context menu command is context-sensitive; it shows the actual name identifierName of the selected identifier and its type identifierType (method, type, variable, field, etc.). This displays the Rename identifierType 'identifierName' dialog box.
  3. Type a new identifier name in the New name text box.
    Rename delphi.png
  4. Select the View references before refactoring check box.
  5. Click OK. The Refactorings pane opens and displays a hierarchical list of all items potentially to be renamed. You can jump to each of these items in the Code Editor.
    Rrdelphirefactorings.png
  6. Click the Apply Refactoring icon Apply.png in the Refactorings pane to apply all refactoring operations.

Note: Clear the View references before refactoring option to apply the refactoring operations immediately after clicking OK, without a preview of the changes..

Note: To remove an item from the refactoring operation, select the item in the Refactorings pane and click the Remove Refactoring icon Remove.png in the toolbar.

Warning: If the refactoring engine encounters errors, the refactoring is not applied and the Refactorings pane displays the list of errors registered.

To jump to a refactoring target from the Refactorings pane:

  1. Expand any of the nodes that appear in the Refactorings pane.
  2. Double-click the target refactoring identifier to highlight it in the Code Editor.
  3. Make any changes you would like in the Code Editor.

Warning: If you change an item in the Code Editor, the refactoring operation is not possible. You need to reapply the refactoring after making changes to any files during the refactoring process.

Preview and apply a Rename operation in C++

Follow the steps below to preview and apply a Rename operation in C++:

  1. In the Code Editor, right-click an identifier to display the context menu.
  2. Select Refactor > Rename context menu command. This displays the Rename Symbol dialog box.
  3. Enter the new identifier name in the text field.
    Rename c++.png
  4. Select the Preview changes before applying check box to preview the changes to your project files.
  5. Click OK to open the Apply Patch pane opens displaying a hierarchical list of all items potentially to be renamed. You can jump to each of these items in the Code Editor.
    Rrcppapplypatch.png
  6. Click the Apply icon Apply.png in the Apply Patch pane to apply all refactoring operations.

Note: Clear the Preview changes before applying option to apply the refactoring operations immediately after clicking OK, without a preview of the changes..

Note: To remove an item from the refactoring operation, select the item in the Apply Patch pane and click the Delete icon Remove.png in the toolbar.

Warning: If the refactoring engine encounters errors, the refactoring is not applied and the Apply patch pane displays the list of errors registered.

To jump to a refactoring target from the Apply Patch pane:

  1. Expand any of the nodes that appear in the Apply Patch pane.
  2. Double-click the target refactoring identifier to highlight it in the Code Editor.
  3. Make any changes you would like in the Code Editor.

Warning: If you change an item in the Code Editor, the refactoring operation is not possible. You need to reapply the refactoring after making changes to any files during the refactoring process.

See Also