To give your code a consistent style and improve readability, use the Format Code command in AnyLogic. You can apply the formatting to individual elements of the model or to the entire model.
AnyLogic allows you to preview the formatted code and specify the maximum line width of your code. These settings are adjusted in the Development section of the Preferences… menu. The option to preview the results of code formatting is selected by default. The default code line width is 60 symbols.
To format code
- Right-click (macOS: Ctrl + click) the model element containing the code you want to format either in the graphical editor or in the Projects view and choose the Format code... command from the context menu. To select the whole model for code formatting, right-click the model’s name.
- The Operation results preview dialog will appear.
- In the Changes to be performed list, you can select the elements for which you want to format the code.
- To navigate through the differences between the original and the formatted code, use the controls above the preview section of this dialog.
- If you want the code formatting to run in the background the next time, clear the Always preview the results check box.
- To apply the changes and finish the code formatting operation, click the OK button.
If the code you want to format contains errors, the formatting operation will not be executed and the following message will appear:
The same message will appear if you attempt to format the code that is already compliant with the AnyLogic suggested style.
Swap Left and Right View | Swap the Original Value and Refactored Value preview sections. |
Next Difference | Jump to the next section of code separated by a blank line from the one you are currently viewing. |
Previous Difference | Jump to the previous section of code separated by a blank line from the one you are currently viewing. |
Next Change | Highlight the next change suggested by the AnyLogic code formatting. |
Previous Change | Highlight the previous change suggested by the AnyLogic code formatting. |
-
How can we improve this article?
-