问题
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:
- Open the preferences dialog (located in Windows -> Preferences on Windows/Linux or in the Eclipse menu on Mac).
- Go to Java > Code Style > Formatter in the tree on the left
- You see the active formatter profile. You can edit it using the "Edit ..." button. Click that.
- Go to the tab "Line Wrapping", select "Method Declarations" > "Parameters" on the lower left.
- 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".
- 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