0

Any way to configure eclipse to only wrap if statements in braces if it is multiple lines, and leave alone single line statements? e.g.

if (x == y) z();

if (x == y){
    z();
}
Jonathan S.
  • 1,540
  • 1
  • 15
  • 26

2 Answers2

1

Use can use //formatter:off and //formatter:on tags to switch on or switch off formatting in a given range of code lines.

Refer this post: How to use eclipse's code formatter to remove new lines after 'case'?

Community
  • 1
  • 1
Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
1

How would it know? If you have a default of always using braces for multiple or single, you will avoid errors of putting in code that is supposed to be part of the if statement but ends up not.

ColWhi
  • 1,077
  • 6
  • 16
  • How would it know that your statement spans multiple lines? If it spans multiple lines... Maybe we are talking about something different – Jonathan S. Apr 14 '11 at 15:38
  • could you post some code to show what the formatting should look like? – ColWhi Apr 14 '11 at 15:40
  • 1
    For me this is a style issue, that you would best be choosing one style and sticking with it. Personally I would go for the second style at all times, so as to avoid incorrectly adding code to the if statement. You need to think about the reader of you code as well (which could be you in a couple of months time). – ColWhi Apr 15 '11 at 07:32