-

Refactoring Variables and FB Types

Refactoring means modifying (improving) the structure of existing source code while preserving its functional behavior.

PLCnext Engineer supports refactoring by providing a mechanism for the automatic and consistent modification of object (variable, FB instance, etc.) properties. Consistent means that the properties to be replaced are considered throughout the solution: in each variables table, Data List, at each code location and within the HMI application. This way, an object can, for example, be renamed with a single step without any functional impact on the code.

The 'Refactoring' context menu command is available if exactly one object is selected in the following editors:

WARNING
Unintended machine operation
  • Prior to refactoring safety-related variables, make certain that suitable organizational measures (according to applicable sector standards) have been taken to avoid hazardous situations if the application logic functions in an unintended or incorrect way.
  • Verify the impact of refactored variables.

Proceed as follows:

  1. If required: First rebuild the project manually ('Project > Rebuild') after adding a variable. (The 'Refactoring' command is only available after rebuilding the project or the cross references are up to date.)
  2. In the editor, right-click the object to be modified and select the 'Refactoring' command from the context menu.

    In the Cross Function Area, the REFACTORING window is opened.
    The window lists all locations where the respective object is used in your project : declarations, code accesses and usages in the HMI application.

    Double-clicking a location in the list opens the respective editor (data list, code etc.) with the object highlighted.

  3. In the first grid row, under the 'New Values' group, enter or select a new name, type or comment (all other properties are read-only)

    The 'Type' field provides a list of the data types and FB types (FB names) available in your project. When selecting another type, ensure that the new type matches the type of the defined type.

  4. Specify the locations, where the properties are to be replaced by the new values.

     : the new values will replace all existing values when executing the refactoring command.
     : location will be kept unchanged.

    The window toolbar provides two icons for deselecting or selecting all locations.

    Note
    Make sure that your selection does not result in a code error due to inconsistencies.

  5. Click the icon on the toolbar to apply the refactoring to the selected locations.

    After completion of the process, click the icon on the toolbar to refresh the content of the REFACTORING window.

    Note
    After the refactoring process is completed, check the MESSAGES window for any errors that result from using the refactoring command.

    Note
    If the instance name of a function block will be changed, the corresponding instance variable in the associated variables table will be renamed too if there exists exactly one variable with the old name and no variable with the new name.

    Note
    If a function block type will be changed, the corresponding type of the instance variable in the associated variables table will be modified too.

Window toolbar

Icon / Command1
Refreshes the list of locations.
Replaces the existing values at the selected locations by the new values entered under the 'New Values' group. The list is automatically updated after refactoring is completed.
Selects (activates) all locations listed in the window.
Deselects (deactivates) all locations listed in the window.

Double-clicking a location in the list opens the respective editor (data list, code etc.) with the object highlighted.