I've long been a "align curly braces" person. And with wide monitors I put long comments after code. So in Eclipse I want to do format things like this:
if(foo)
{
something();
}
else
{
somethingElse();
}
Fine; that's easy. But then I add a comment:
if(foo) //if foo is true
{
something();
}
else //if no foo
{
somethingElse();
}
Dratted Eclipse formats it like this:
if(foo) //if foo is true
{
something();
}
else
//if no foo
{
somethingElse();
}
Great. That whole wasted line. And it looks ugly. And it's not even precise, because I want to comment the else
line.
How can I get Eclipse to format my if
/else
with aligned braces, but allow my comments to be on the same line as else
?
This was tested on Eclipse 4.2.2, and I have just confirmed that it does not work in Eclipse 4.3M7, either.
I have filed a bug on the issue; let's see what the Eclipse developers have to say.
That did it for me in Galileo.
I'm using Eclipse Indigo (3.7), all I had to do was go to Control Statements -> check "insert newline before 'else' in an 'if' statement". (inside Properties/Java Code Style/Formatter/Edit...)
I'm using a copy of the default Eclipse built-in template. If you're sure you haven't tampered with the built-in template, please let us know what version you're using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With