Can the Eclipse code style formatter align assignment statements?

扶醉桌前 提交于 2019-12-22 12:25:32

问题


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

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