Guides for SE student projects »

Intellij IDEA: Configuring the code style

IntelliJ’s default style is mostly compliant with ours but it uses a different import order from ours but some tweaks may be needed.

Legend: basic tweak | intermediate tweak | advanced tweak

Tweak: switch-case style

  1. Go to FileSettings…​ (Windows/Linux), or IntelliJ IDEAPreferences…​ (macOS).
  2. Click on EditorCode styleJava (see the screenshot below).
  3. Click on the Wrapping and Braces tab and un-tick the Indent 'case' branches option (as shown in the screenshot above).

Tweak: import order

  1. Go to FileSettings…​ (Windows/Linux), or IntelliJ IDEAPreferences…​ (macOS).
  2. Select EditorCode StyleJava.
  3. Click on the Imports tab to set the import order.
    • For Class count to use import with '*' and Names count to use static import with '*': Set to 999 to prevent IntelliJ from contracting the import statements.
    • For Import Layout: The order is:

Tweak: Auto-remove trailing spaces

You can configure Intellij to automatically strip trailing white space in code lines, as follows:

  1. Go to Settings.
  2. On the left side of the dialog, click on Editor -> General.
  3. On the right side, scroll to the On Save section.
  4. Change Remove trailing spaces on: to Modified lines.

More useful settings

The tweaks given above are specific to code style. A few more useful settings (not related to the code style) can be found here.