我有(Java)评论,例如:
/*
* The quick brown fox jumped over the lazy dog.
*
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
*/
Eclipse自动格式化程序正确设置注释行宽度,但使其成为:
/*
* The quick brown fox jumped over the lazy dog.
*
*
* Notes: - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog. The quick brown fox jumped over the lazy dog. - The second quick brown fox jumped over the
* lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
*/
我如何使代码格式化程序保留项目符号列表,同时还处理注释?
备注:
答案 0 :(得分:39)
This answer表示您在开场/*
后添加连字符,即:
/*-
* The quick brown fox jumped over the lazy dog.
*
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
*/
这也适合我。
答案 1 :(得分:13)
您的问题的答案可能与此处的答案相同:How to turn off the Eclipse code formatter for certain sections of Java code?
从Eclipse 3.6开始,您可以使用
// @formatter:off
...
// @formatter:on
注释以禁用代码格式化。
更新:
或者,您也可以更改首选项中的注释设置:在Java /代码样式/格式化程序中编辑格式化程序设置,并在“注释”页面中查看以下设置:
顺便说一句,这种手动列表不会转换为生成代码中的列表。出于这个原因,使用html列表可能是有意义的。
答案 2 :(得分:3)
您可以更改Eclipse格式化注释的方式,并对块注释进行特殊处理。
到达窗口 - >喜好。 Java>代码风格>格式化。单击“新建”以创建新模板。然后在“注释”选项卡下禁用块注释格式。
然而,这将永远不会对块注释执行任何格式化。
答案 3 :(得分:2)
在Java中有两种不同的注释:
<br>
或<p>
)
用于评论。在JavaDoc中,您的示例可以像下面这样编写(并且格式如图所示):
/**
* The quick brown fox jumped over the lazy dog.
*
* <p>
* Notes:
* <ul>
* <li>The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown
* fox jumped over the lazy dog.</li>
* <li>The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick
* brown fox jumped over the lazy dog.</li>
* </ul>
* </p>
*/
答案 4 :(得分:2)
拿起Bananeweizen所说的内容,你也可以用<pre></pre>
标签包装相关的评论栏,保留每个标签和空格:
/*
* The quick brown fox jumped over the lazy dog.
*
*
*<pre>Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.</pre>
*/
答案 5 :(得分:1)
我知道问题很老,但我也看不到有人给出满意的答案。
这解决了我的问题。
转到Preference->Java->Code Style->Formatter
。在这里转到您要使用的任何Formatter样式的Edit。在“编辑”对话框中,您会找到一个复选框启用块注释格式。取消选中此项。像我一样更改配置文件名称。申请并确定。大功告成
希望这会有所帮助。
答案 6 :(得分:0)
怎么样:
/**
* The quick brown fox jumped over the lazy dog.
*
* <p>Notes:
* <li>The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</li>
* <li>The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</li>
*/
然后关闭&#34;格式化HTML标签&#34;在Windows中 - &gt;偏好 - &gt; Java - &gt;代码风格 - &gt;格式化程序 - &gt;编辑... - &gt;评论
这仍然会使线宽线断裂。
修改强>
我使用了以下块注释:
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
*/
我正在使用Eclipse Neon.3 for Java EE,我的Formatter cor注释被设置为150的宽度和#34;从不加入行&#34;选择。 格式化这个块注释给了我以下结果,我认为这是你可能想要的(虽然我知道你不想&#34;永远不会加入行&#34;)。
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The
* quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* The quick brown fox jumped over the lazy dog.
*/
只有一个小问题。当我向第一个项目符号列表添加更多文本然后再次格式化时,我得到以下结果。
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The
* SOME MORE TEXT TO WRAP
* quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* The quick brown fox jumped over the lazy dog.
*/
那是因为我告诉格式化师&#34;不要加入行&#34;。当我取消选择&#34;从不加入线条&#34;我显然得到了与你相同的结果。