我正在使用Eclipse格式化程序,我想要以下代码格式化。注意JavaDoc和=
是如何对齐的。
我想要的是什么:
/**
* Description.
*
* @param alpha this is what alpha does
* @param beta this is what beta does
* @param gamma this is what gamma does
* @param delta this is what delta does
*/
public Foo(Bar alpha, Bar beta, Bar gamma, Bar delta) {
this.alpha = alpha;
this.beta = beta;
this.gamma = gamma;
this.delta = delta;
}
什么是eclipse格式:
/**
*
* @param alpha this is what alpha does
* @param beta this is what beta does
* @param gamma this is what gamma does
* @param delta this is what delta does
*/
public Foo(Bar alpha, Bar beta, Bar gamma, Bar delta) {
this.alpha = alpha;
this.beta = beta;
this.gamma = gamma;
this.delta = delta;
}
有人知道这是否可行?
如果无法自动执行此操作,是否可以让格式化程序忽略这些行上的空格?
答案 0 :(得分:1)
看起来太具体了,没有内置的解决方案。可能有一个插件可以帮助解决这个问题。
如果无法自动执行此操作,是否可以让格式化程序忽略这些行上的空格?
是的,使用@formatter
标记。
Windows > Preferences
。Java > Code Style > Formatter > Edit
On/Off Tags
标签,然后选中Enable
复选框。将它们应用于您的代码:
//@formatter:off
/**
* Description.
*
* @param alpha this is what alpha does
* @param beta this is what beta does
* @param gamma this is what gamma does
* @param delta this is what delta does
*/
//@formatter:on
public Foo(Bar alpha, Bar beta, Bar gamma, Bar delta) {
this.alpha = alpha;
this.beta = beta;
this.gamma = gamma;
this.delta = delta;
}
或者,如果要禁用所有Javadoc格式:
Comments
代码并取消选中Enable Javadoc comment formatting
复选框。以下不是您想要的,因为它添加了新行,但可能足够接近您,因为它将参数说明彼此对齐:
/**
* Description.
*
* @param alpha
* this is what alpha does
* @param beta
* this is what beta does
* @param gamma
* this is what gamma does
* @param delta
* this is what delta does
*/
这是通过以下方式实现的:
Comments
代码,然后选中Indent Javadoc tags
,(可选)Indent description after @param
和New line after @param tags
复选框。答案 1 :(得分:0)
您可以使用适用于最常见IDE的Jindent插件: Eclipse,Netbeans,JDeveloper,IntelliJ IDEA,JBuilder
这将保留代码的格式
/**
* Description.
*
* @param alpha this is what alpha does
* @param beta this is what beta does
* @param gamma this is what gamma does
* @param delta this is what delta does
*/
public Foo(Bar alpha, Bar beta, Bar gamma, Bar delta) {
this.alpha = alpha;
this.beta = beta;
this.gamma = gamma;
this.delta = delta;
}
//~ Formatted by Jindent --- http://www.jindent.com
与Eclipse的默认格式化命令 Ctrl + Shift + F 不同,您需要使用
Ctrl + Shift + J ,使用Jindent
格式化您的代码。
它只在代码末尾添加注释,您必须手动删除。