Allows you to print statement blocks in just one line when possible, i.e. when the block only contains one statement and does not exceed the maximal line length. Please note that white space before a compacted block is not controlled by your general brace settings, but with the "Space before braces" option.
When enabled, method and constructor bodies will be printed in one line when possible.
Since 1.2
When enabled, single if statement bodies will be printed in
one line when possible.
Since 1.2
When enabled, statement bodies of the if the part of
if/else statement will be printed in one line when possible.
Since 1.2
Example 2.76. Standard if/else block
if (cond) { | return getMagicNumber(); | } else { | return -1 | }
Example 2.77. Compact if of if/else block
if (cond) { return getMagicNumber(); } | else { | return -1; | } |
Please note that when the if block has been compacted, the
following else if or else statement
always starts on a new line.
When enabled, prints else if statement bodies of if/else
statements in one line when possible.
Example 2.78. Standard else of if/else block
if (cond1) { | return getMagicNumber(); | } else if (cond2) { | throw new IllegalStateException(); | } |
Example 2.79. Compact else if block
if (cond1) { | return getMagicNumber(); | } else if (cond2) { throw new IllegalStateException(); } |
Please note that when the else if block has been compacted,
the following else statement always starts on a new line.
Since 1.2
Example 2.80. Compact if block
if (cond1) { | return getMagicNumber(); | } else if (cond2) { throw new IllegalStateException(); } | else { | return 0; | } |
When enabled, prints else statement bodies in one line
when possible.
Since 1.2
Example 2.81. Standard else block
if (cond1) { | return getMagicNumber(); | } else if (cond2) { | throw new IllegalStateException(); | } else { | return 0 | } |
Example 2.82. Compact else block
if (cond1) { | return getMagicNumber(); | } else if (cond2) { | throw new IllegalStateException(); | } else { return 0; } |
When enabled, array initializers will be printed in one line when possible.
Since 1.7
When enabled, enum declaration bodies will be printed in one line when possible.
Since 1.4
When enabled, enum constants will be printed in one line when possible. This option is only useful if you use constant-specific methods in your enums.
Since 1.4
Example 2.87. Enum constants with constant specific methods
public enum Operation { | PLUS { | double eval(double x, double y) { | return x + y; | } | }, | MINUS { | double eval(double x, double y) { | return x - y; } | }, | TIMES { | double eval(double x, double y) { | return x * y; | } | }, | | // Do arithmetic op represented by this constant | abstract double eval(double x, double y); | } |
Example 2.88. Compact enum constants with constant specific methods
public enum Operation { | PLUS { double eval(double x, double y) { return x + y; } }, | MINUS { double eval(double x, double y) { return x - y; } }, | TIMES { double eval(double x, double y) { return x * y; } }, | | // Do arithmetic op represented by this constant | abstract double eval(double x, double y); | } |
You can narrow the scope for the above mentioned options by selecting whether
all statements should be printed on one line when possible or
only throw and return statements.
Since 1.2
When enabled, all statements are compacted when possible.
Example 2.89. All statements on same line
if (true) { return result; } else if (false) { System.out.println("unexpected condition"); } else { throw new Error(); }
When enabled, only throw and return statements are compacted when possible. All other statements are printed in normal block style.
Example 2.90. Only throw and return statements on same line
if (true) { return result; } else if (false) { System.out.println("unexpected condition"); } else { throw new Error(); }