问题
Eclipse has an option in Indentation: "Alignment of fields in class declarations" that will align assignments of class members as in:
class Foo {
int x = 3;
String y = "abc"
long z = 2;
}
Is there a setting that will do the same for method level assignments as in:
private void foo() {
int x = 3;
String y = "abc"
long z = 2;
}
I can not find such a setting.
回答1:
Try creating a new Java Code Style Formatter profile (Window->Prefernces->Java->Code Style->Formatter) or modifying an older one and check Indentation and Braces tabs.
回答2:
For future visitors.
There is no such option in Eclipse, but, as mentioned here, you can use plugin named OCDFormat that aligns assignments and declarations in a selected piece of code.
Installation: download the latest version of OCDFormat_*.jar from project page on github (click → Raw → Save as) and add it to your Eclipse plugins or dropins directory.
Usage: select a piece of code and press Ctrl+4.
回答3:
The Eclipse code style formatter cannot align assignment statements.
columns4eclipse is plug-in that allows you to do so. I had made a gif video illustrating its use but my answer got deleted by a moderator (as >10k users will see), so I let you try the plug-in and see by yourself.
来源:https://stackoverflow.com/questions/13748866/can-the-eclipse-code-style-formatter-align-assignment-statements