Reformat code style in Eclipse

一曲冷凌霜 提交于 2019-12-08 16:03:13

问题


I'm looking for an automatic way in eclipse to reformat curly braces to K&R style, eliminating braces for single statements if, etc. Is there such a way?

Thanks.


回答1:


Before you reformat you need to customize the formatter settings in the Preferences Dialog Java/ Code Style / Formatter to your K&R settings if the default settings don't match your requirements.

The Preferences Dialog is opened from Mainmenu / Window / Preferences

You can even configure a save action Java / Editor / Save Action to format source code on save.




回答2:


A lot of options for formatting can be chosen in the preferences dialog (Java -> Code Style -> Formatter).

After that, you can simply format your code by pressing ctrl-shift-f (windows)

Also, you can choose to automatically format your code whenever you save your file. This is also in the preferences dialog (Java -> Editor -> Save Actions)




回答3:


You can customize how Java code is formatted going to Window > Preferences. There, choose Java > Code Style > Formatter, click on New... to create a new profile. Then Edit... it.

However, I'm quite sure Eclipse's code formatter won't add or remove braces, it will simply position them according to your style rules. You will need a separate tool to do this or a fancy search and replace.




回答4:


right click in your editor => source => format



来源:https://stackoverflow.com/questions/2411024/reformat-code-style-in-eclipse

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