我想在 Eclipse 中配置一个格式化程序,当大括号包围 return/break/continue 控制语句时删除大括号:
if (x == y) {
return true;
} //that's bad
if (x == y) return true; //that's better
我在 Preferences --> Java --> Code Style --> Formatter --> Control Statements
下找到了如何保持 if
和 else
语句在一行中,但不知道如何去掉不必要的大括号。 Eclipse 是否允许您定义消除冗余大括号的格式化程序?
最佳答案
Preferences > Java > Code Style > Clean Up,按 Edit...,Code Style 选项卡,将 Use blocks in if/while/for/do statements
设置为仅在必要时
。之后,您可以使用 Source > Clean Up... 选项简单地处理特定文件甚至整个项目:)
附言尽管如此,我的选择是“永远”。
关于java - 自定义 Eclipse 格式化程序以删除不必要的大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17865275/