An edit can leave a method body at the wrong indentation even when the code still runs. In IntelliJ IDEA on the Linux desktop, Reformat Code applies the project's formatting rules to a selected block of Java code.
The formatter takes its rules from the project's code style. Settings in an .editorconfig file take precedence for the files and rules it covers.
The selection sets the boundary for the edit. With no selection, Reformat Code applies to the whole file, which can introduce formatting changes outside the block you meant to adjust.
Steps to format code in JetBrains IDE:
Start with your source file open in the editor and IntelliJ IDEA's main menu under the Main Menu button in the window header, as on a new installation.
- Select the block you want to format in the editor.
In
~/IdeaProjects/receipts/src/Receipt.java, the selection starts at thesubtotal()declaration and ends at its closing brace. Thetotal()method below stays outside the selection. - Click the Main Menu button in the window header.

- Point to Code in the menu row.

- Click Reformat Code in the Code menu.
PyCharm and WebStorm also put Reformat Code in the Code menu.
- Compare the editor with its state before formatting to verify that the selected block's indentation changed and everything outside the selection looks exactly the same.
In
Receipt.java, thepricedeclaration and return statement move one level deeper insidesubtotal(). Thetotal()method keeps the same text, spacing, and line breaks.