Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a blank line between static and non-static imports in Eclipse automatically

I want to format my code according to the Google Java Style.

There are some issues when it comes to import statements. The one rule I can not fulfill other than by manual editing each class is this one:

If there are both static and non-static imports, a single blank line separates the two blocks.

Apparently, there is no way to configure the Organize Imports action in Eclipse to add this blank line.

Are there any workarounds, plugins or plans to add such a feature (or is my only choice to write one myself or use a different IDE)?

like image 439
martin Avatar asked May 02 '18 10:05

martin


2 Answers

I think this issue is related to the formatter used rather than the Organize Imports action per se.

The formatter options are available at Window > Preferences > Java > Code Style > Formatter. When editing a profile, there's a tab named Blank Lines and an option Between import groups which you may find useful.

When I have this option set to 1, Organize Imports action inserts a blank line between import group and import static group.

like image 149
Kamil Jarosz Avatar answered Oct 19 '22 09:10

Kamil Jarosz


It's quite straightforward in Eclipse, here's how to do it:

In "Organize imports" define only two groups:

  1. * - all unmatched static imports
  2. * - all unmatched type imports

In the formatter set Blank LinesBlank lines in compilation unitBetween import groups to 1.

like image 8
Speedstone Avatar answered Oct 19 '22 09:10

Speedstone