Synaero
Synaero

Reputation: 489

Change Eclipse formatting of one-line if statements

So when I use shift+ctrl+f to reorganize a class I have the following happen to my one-line if statements

if (true) doThis();

changed to

if (true)
    doThis();

How can I make shift+ctrl+f auto organize to be like the first statement?

Upvotes: 9

Views: 5625

Answers (4)

Iswanto San
Iswanto San

Reputation: 18569

Try this :

  1. Open your eclipse
  2. Go to Window - Preferences
  3. Go to Java - Code Style - Formatter
  4. In Active Profile : Eclipse [built-in] choose Edit
  5. Go to Control Statements tab
  6. Check keep 'then' statement on same line
  7. Change your Profile name
  8. OK

Upvotes: 4

Synaero
Synaero

Reputation: 489

After some more exploring it seems I can change it.

  1. Open preferences in Eclipse
  2. Expand Java
  3. Expand Code Style
  4. Click Formatter
  5. Click Edit
  6. Open Tab Control Statement
  7. Adjust "Keep 'then' statement on line

Upvotes: 8

Eric Galluzzo
Eric Galluzzo

Reputation: 3241

  1. Go to Window > Preferences (Windows/Linux) or Eclipse > Preferences (OS X).
  2. Go to Java > Code Style > Formatter.
  3. Create your own code formatter if you haven't already.
  4. Go to Control Statements.
  5. Check the check box that says "Keep simple 'if' on one line."
  6. Hit OK.

Upvotes: 3

purxiz
purxiz

Reputation: 103

Rather than use CTRL + SHIFT + f, you might try using CTRL + I (as in Ireland) It doesn't actually reformat the code, but does fix all indents and whitespaces, so it won't affect one line if statements.

Upvotes: 1

Related Questions