Code refactoring

Code refactoring is the process of improving the source code of a program without changing the overall result. Generally, code refactoring improves code readability and maintainability.

ColdFusion Builder supports various refactoring techniques like renaming, searching, and previewing of CFCs, CFMs, and UDFs at the project and workspace levels.

Refactor CFC or CFM filenames

When you rename a CFC or CFM, you can refactor all valid instances of the CFM or CFC, including all references to the CFM or CFC.

  1. Right-click the file in the Navigator pane.

  2. Select Refactor > Rename.

  3. Enter the new name and preview the changes. When you preview the changes, you can review the selected instances and deselect any instance that you do not want to rename.

  4. To rename CFCs or CFMs across all projects in the workspace, select Update All Projects In The Workspaces.

Note: You cannot rename a CFC or CFM in HTTP or Web server URLs unless the server is registered and running.

To undo refactoring, use the keyboard shortcut Ctrl+Z (Windows) or Command+Z (Mac).

Refactor UDFs in CFC or CFM files

  1. Open the CFM or CFC file in the editor.

  2. Point to the function name, right-click, and select Refactor > Rename

  3. Specify the UDF name and click OK.

    Note: Currently, function renaming is supported only through the main function declaration and not from function calls.

Notes and considerations

  • The location of a CFM or CFC file cannot be changed although the inherent Eclipse editor provides the capability to move files using the Move option.

  • The CFML Editor does not support renaming a folder although Eclipse provides this option.

Refactoring methods

You can refactor methods created for application variables by creating variable mappings.

For example, consider a scenario where an application variable is defined for a CFC object as follows:

<cfset Application.appVar = createObject("component","abc.AppCFM.a")>

Say, you have a CFC function, Method(), that you call as follows:

<cfset Application.appVar.Method()>
To refactor the Method() function, create a variable mapping for the application variable Application.appVar as follows:
  1. In the Navigator view, right-click the project and select Properties.

  2. In the Properties dialog box, select ColdFusion Variable Mappings.

  3. Click New, enter the following details in the Add Mappings dialog box:
    • Variable Name: Application.appVar

    • Mapped To: abc.AppCFM.a

Reference search

You can search for a CFC, CFM, or UDF in a project or workspace.

  1. Right-click the project in the Navigator pane.

  2. Click References and select Project or Workspace. The results are displayed in the Search window in ColdFusion Builder.

Other than searching for references at the project or workspace level, you can search for references while working in the CFML code editor. Right-click in the CFML editor and select References > File to search for file references. You can also search for references at the project and workspace level from within the CFML editor.