如何在Eclipse中设置Java代码使throws/implements/extends换行?
Eclipse Java代码格式化:让throws/implements/extends单独换行
完全可以实现这个需求,具体操作步骤如下:
打开格式化配置面板
- Windows/Linux:点击顶部菜单
Window->Preferences - Mac:点击顶部菜单
Eclipse->Preferences - 依次展开
Java->Code Style->Formatter,点击Edit按钮(若使用默认配置,需先复制一份自定义配置,避免修改全局默认规则)
- Windows/Linux:点击顶部菜单
配置
throws关键字换行- 切换到
Line Wrapping标签页 - 展开
Method Declarations下的Throws clause - 将
Line wrapping policy设置为Wrap all elements, every element on a new line - 把
Indentation policy改为Indent,确保throws语句会缩进显示
- 切换到
配置
extends/implements关键字换行- 同样在
Line Wrapping标签页,展开Type Declarations下的Extends/implements clause - 重复上述设置:
Line wrapping policy选Wrap all elements, every element on a new line,Indentation policy设为Indent
- 同样在
设置完成后,选中目标代码按下 Ctrl+Shift+F(Mac为Cmd+Shift+F)执行格式化,就能得到你想要的效果:
原代码:
public DataRecord fromFile(File file, InputStream inputStream) throws IOException {
格式化后:
public DataRecord fromFile(File file, InputStream inputStream) throws IOException {
内容的提问来源于stack exchange,提问作者caduceus
相关产品推荐
相关产品推荐

