Controls miscellaneous brace options.
Per definition braces are superfluous on single statements, but it is
a common recommendation that braces should be always used in such cases.
With this option, you can specify whether missing braces for single
statements should be inserted for the control statements if,
for, while and do-while
and labeled statements inside switch
blocks. Inserting and removing braces is mutually exclusive.
When enabled, braces are inserted around the body of
single if statements when necessary.
Since 1.9.1
Example 2.56. Brace insertion for if statement
if (condition) break;
would become
if (condition) { break; }
When enabled, braces are inserted around the body of
if...else statements when necessary.
Example 2.57. Brace insertion for if-else statement
if (true) break; else return;
would become
if (true) { break; } else { return; }
When enabled, braces are inserted around the body of
for statements when necessary.
Example 2.58. Brace insertion of for statements
for (int i = 0; i < count; i++) System.out.println(i);
would become
for (int i = 0; i < count; i++) { System.out.println(i); }
When enabled, braces are inserted around the body of
while statements when necessary.
Example 2.59. Brace insertion for while statements
while (!isDone)
doSomething();
would become
while (!isDone) {
doSomething();
}
When enabled, braces are inserted around the body of
do...while statements when necessary.
Example 2.60. Brace insertion for do...while statements
do something(); while (condition);
would become
do { something(); } while (condition);
When enabled, braces are inserted around the body of
labeled statements inside switch blocks when necessary.
Braces are only inserted if the statement is not empty.
Since 1.4
Example 2.61. Brace insertion for labeled statements
switch (c) { case 'a': case 'b': System.out.println(); break; }
would become
switch (c) { case 'a': case 'b': { System.out.println(); break; } }
When enabled, brace insertion only happens when the block statement takes more than just one line to print.
Since 1.8
Example 2.62. Missing braces
if (arg == null) for (int i = 0; i < 10; i++) System.out.println("arg " + i);
Above you see an example with two block statements. Enabling brace insertion for if and for statements would yield:
Example 2.63. Inserted braces
if (arg == null) { for (int i = 0; i < 10; i++) { System.out.println("arg " + i); } }
You see braces inserted for both block statements. But when you’ve enabled the multi-line option, you will get:
Example 2.64. Inserted braces limited to multi-line statements
if (arg == null) { for (int i = 0; i < 10; i++) System.out.println("arg " + i); }
The statement of the if-block happens to be another block statement which is printed in two lines here, therefore the braces are inserted for the if-statement. The for-statement on the other hand does not have any braces inserted, because here the block can be printed in just one line.