Eclipse: Lining up function arguments vertically

陌路散爱 提交于 2019-12-21 03:14:20

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/18744113/eclipse-lining-up-function-arguments-vertically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!