强制 Eclipse 源代码格式化程序在 80 个字符处换行的替代方法或方法?
每当我使用 Eclipse 源代码格式化程序/美化器(通过菜单项 Source - Clean Up 或 CTRL - SHIFT - f)时,它会将我已分成多行的语句重新格式化回长度超过 80 个字符的一行,例如我有:
public CDataCacheContainer loadDataset(CDataFileDef dsd)
throws IOException {
并且它
public CDataCacheContainer loadDataset(CDataFileDef dsd) throws IOException {
的长度超过了 80 个字符,并且打印时看起来很差。
我可以阻止 eclipse 这样做吗?或者是否有替代的 Eclipse 源代码格式化程序可以很好地包装 80 个字符?
编辑1: 在 Eclipse 中,Window - Preferences - Java - Code Style - Formatter - Edit
下的最大行宽设置为 80。我已将其更改为 78,并且还启用了赋值表达式的换行,这很有帮助。现在唯一没有换行的表达式是这个:
datasetsNode.add(new TreeUtil.PanelViewNode(this, table)); // NOPMD
以及其他类似的表达式。
Whenever I use the Eclipse source code formatter / beautifier (via the menu item Source - Clean Up or CTRL - SHIFT - f) it reformats statements that I have broken into multiple lines back into one line that is longer than 80 chars, eg I have:
public CDataCacheContainer loadDataset(CDataFileDef dsd)
throws IOException {
and it becomes
public CDataCacheContainer loadDataset(CDataFileDef dsd) throws IOException {
which is longer than 80 characters and looks poor when printed.
Can I prevent eclipse from doing this? Or is there an alternative eclipse source code formatter that wraps at 80 characters nicely?
EDIT 1:
In Eclipse under Window - Preferences - Java - Code Style - Formatter - Edit
the maximum line width was set at 80. I've changed it to 78 and also enabled wrapping on Assignment expressions and this has helped. Now the only expression that isn't wrapping is this one:
datasetsNode.add(new TreeUtil.PanelViewNode(this, table)); // NOPMD
and others like it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您的首选项中
Java > 下的代码风格>格式化程序
您创建一个新的活动配置文件。编辑它并在换行下确保将最大线宽设置为 80。Make sure that the in your preferences under
Java > Code Style > Formatter
you create a new active profile. Edit it and under line wrapping make sure you have Maximum Line Width set to 80.如果我想强制执行特定格式,我总是在代码中执行以下操作:
public CDataCacheContainer loadDataset(CDataFileDef dsd) //
抛出 IOException { //
// ...
}
I always do the following in my code if I want to enforce specific formatting:
public CDataCacheContainer loadDataset(CDataFileDef dsd) //
throws IOException { //
// ...
}
从菜单栏:窗口>首选项>爪哇>代码风格>格式化程序>编辑(按钮)>换行(选项卡)。您可以自定义最大线宽并更改换行策略。
From menu bar: Window > Preferences > Java > Code Style > Formatter > Edit (button) > Line Wrapping (tab). You can customize the maximum line width and change the line wrapping policy.