在 Eclipse 中格式化字段声明
问候溢出者,
问题(变量名称不是按类型对齐):
public abstract class Filter {
private long id;
protected String expression;
}
如何在 Eclipse 中自动对齐字段,例如:
public abstract class Filter {
private long id;
protected String expression;
}
注意 long
之前的空格,谢谢!
更新:我在 Eclipse 格式化程序选项下找不到用于对齐类成员类型(例如:long
和 String
)的自定义选项。是的,有一个可以对齐类成员的名称(例如:id
和表达式
),但不能对齐它们的类型。请在我上面的示例中看看这个问题。有什么解决办法吗?
Greetings Overflowers,
Problem (names of variables are aligned by not their types):
public abstract class Filter {
private long id;
protected String expression;
}
how can I align fields automatically in Eclipse, such in:
public abstract class Filter {
private long id;
protected String expression;
}
Note the space before long
, thank you !
UPDATE: I cannot find a customization option to align types of class members (e.g.: long
and String
) under Eclipse formatter options. Yes, there is one to align names of class members (e.g.: id
and expression
) but not their types. Please, take a look at this issue in my examples above. Any solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
窗口 - 首选项 - Java - 代码样式 - 格式化程序 ->新... -> 缩进 ->对齐列中的字段。
现在,按
ctrl-shift-f
将修复您的代码:)或
窗口 - 首选项 - Java - 代码样式 - 清理 ->新建...
在这里您可以更改代码的样式。然后,执行
Source - Clean Up
将确保它看起来是这样的。Window - Preferences - Java - Code Style - Formatter -> New... ->Indentation -> Align fields in column.
Now, pressing
ctrl-shift-f
will fix your code :)or
Window - Preferences - Java - Code Style - Clean Up -> New...
Here you can change how you would like your code to be. Then, doing
Source - Clean Up
will make sure it looks that way..没有格式化选项可以执行您的建议。我有两种可能性,但您都不会非常喜欢:
There is no formatting option to do what you suggest. I have two possibilities, neither of which you are going to like very much:
您可以为 Eclipse 编写一个非常复杂的格式化程序扩展。但你真的不应该。
Ctrl-shift F 会将您的代码格式化为美观的符合 Java 规范的格式。
You could write a really complicated formatter extension for eclipse. But you really shouldn't.
Ctrl-shift F will format your code in beautiful Java Spec compliant format.