Code layout option: Surround with brackets for if (/else)

It will be pretty good if Idea has a code layout option which puts '{' and '}' for if (/else) blocks which will reduce human errors. For example for code:

.
.
.
if (isDummy)
doSomething1();
else
doOtherthing1();
.
.
.
Someone will put "doSomething2();" like
.
.
.
if (isDummy)
doSomething1();
doSomething2();
else
doOtherthing1();
.
.
.

mistakenly (Case 1). It will be great if IDEA puts brackets (at least have an option to put) automatically like:

After reformat code:

.
.
.
if (isDummy) {
doSomething1();
} else {
doOtherthing1();
}
.
.
.
and after adding "doSomething2();"
.
.
.
if (isDummy) {
doSomething1();
doSomething2();
} else {
doOtherthing1();
}
.
.
.

There is no problem! (Case 2)

P.S: For IDEA users, IDEA automatically warns that code is not compiled for (Case 1) but especially for team work where there are users not using IDEA, putting brackets will increase quality of code...

3 comments
Comment actions Permalink

try reformat plugin

0
Comment actions Permalink

Thnaks Dani. ;)

0
Comment actions Permalink

Gokcer Gokdal wrote:

It will be pretty good if Idea has a code layout option which puts '{' and '}' for if (/else) blocks which will reduce human errors. For example for code:


The latest EAP (#887) does exactly that.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0

Please sign in to leave a comment.