Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Eclipse formatting of one-line if statements

Tags:

java

eclipse

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?

like image 811
Synaero Avatar asked Feb 22 '13 04:02

Synaero


People also ask

How do I format a line in Eclipse?

Go to Source | Format Document or press Ctrl+Shift+F.

How do I change line width in eclipse?

In preferences Java -> Code Style -> Formatter, edit the profile. Under the Line Wrapping tab is the primary option for line width (Maximum line width:).

How do I turn off auto format in Eclipse?

If you are using multi-line comments (/* */), the fix to prevent Eclipse from applying its auto-formatting is very simple: just add a dash (-) after the asterisk at the beginning of the comment (see below).


2 Answers

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
like image 184
Synaero Avatar answered Oct 24 '22 14:10

Synaero


  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.
like image 35
Eric Galluzzo Avatar answered Oct 24 '22 15:10

Eric Galluzzo