Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Lining up function arguments vertically

I'm running Eclipse 3.7.2 on Windows 7 professional.

If I type a method declaration like this:

private void processCode(String codename,
                         boolean doSomethingElse,
                         int num_of_repeats){
}

Then hit Ctrl + I with the whole file selected, Eclipse will mess up the alignment of the function arguments like this

private void processCode(String codename,
     boolean doSomethingElse,
     int num_of_repeats){
}

How can I get Eclipse to stop doing that?

like image 335
Steve Avatar asked Sep 11 '13 14:09

Steve


2 Answers

Follow these steps to achieve what you want:

  1. Open the preferences dialog (located in Windows -> Preferences on Windows/Linux or in the Eclipse menu on Mac).
  2. Go to Java > Code Style > Formatter in the tree on the left
  3. You see the active formatter profile. You can edit it using the "Edit ..." button. Click that.
  4. Go to the tab "Line Wrapping", select "Method Declarations" > "Parameters" on the lower left.
  5. On the bottom left you see the "Settings for parameters" group. Set the Line wrapping policy to "Wrap all elements, except first element if not necessary". Set the Indentation policy to "Indent on column".
  6. Close all dialogs by clicking ok.

You should now have the behavior you intended. If it fits your needs, you might want to apply the same settings for constructor parameters as well.

like image 76
Stefan Winkler Avatar answered Nov 13 '22 21:11

Stefan Winkler


All, I understand this is an old thread, but the MARS eclipse editor wont line up this correctly and like to see if anyone experienced the same in eclipse MARS edition? The String u indentation is not lined up with String k:

public Properties fc(String k,
                    String u) {
    return new Properties();
}

EDIT: I found out the font I used was Lucida Console which is not fix-space font. Eclipse's Java editor has various syntax with BOLD on in which it made the aligned "looked" unaligned, but in fact it was due the bold syntax that widen the characters.

like image 27
TX T Avatar answered Nov 13 '22 20:11

TX T