使Eclipse的Java代码格式化程序忽略块注释 [英] Making Eclipse's Java code formatter ignore block comments

查看:101
本文介绍了使Eclipse的Java代码格式化程序忽略块注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使Eclipse的内置Java代码格式化程序忽略注释?每当我运行它时,它就会变成这样:

Is there a way to make Eclipse's built-in Java code formatter ignore comments? Whenever I run it, it turns this:

    /*
     * PSEUDOCODE
     * Read in user's string/paragraph
     * 
     * Three cases are possible
     * Case 1: foobar
     *         do case 1 things
     * Case 2: fred hacker
     *         do case 2 things
     * Case 3: cowboyneal
     *         do case 3 things
     *         
     * In all cases, do some other thing
     */

到此:

    /*
     * PSEUDOCODE Read in user's string/paragraph
     * 
     * Three cases are possible Case 1: foobar do case 1 things Case 2: fred
     * hacker do case 2 things Case 3: cowboyneal do case 3 things
     * 
     * In all cases, do some other thing
     */

我已经玩过Windows>偏好设置> Java>代码样式>格式化程序设置,但找不到适合kee的设置ping注释格式。我正在使用Eclipse 3.4.0。

I have already played around with the Windows > Preferences > Java > Code Style > Formatter settings but can't find one for keeping comment formatting. I'm using Eclipse 3.4.0.

推荐答案

Update 2010,如由OP 在此答案中指向的特殊字符串 // @formatter:off 在Eclipse 3.6中就足够了。

Update 2010, as pointed by the OP and in this answer, the special string // @formatter:off in Eclipse 3.6 is enough.

在提出问题时不可用

原始答案:2009年6月, Eclipse 3.4 / 3.5

Original answer: June 2009, Eclipse 3.4/3.5

使用Java格式化程序( Windows>首选项> Java>代码样式> Formatter ),您可以创建一个新的Formatter配置文件。

With the Java Formatter (Windows > Preferences > Java > Code Style > Formatter), you can create a new Formatter profile.

在评论标签(在eclipse3.5中)中,请确保,在 Javadoc注释设置中,取消选中 格式化HTML标签s

还要检查 常规设置中的 从不加入行 / code>部分。

In the Comments tab (in eclipse3.5), you can make sure, in the "Javadoc comment settings", to uncheck "Format HTML tags".
Check also the "Never join lines" in the "General settings" section.

然后,您的注释应写为:

Then your comment should be written as:

/**
 * PSEUDOCODE
 * Read in user's string/paragraph
 * 
 * Three cases are possible:
 * <dl>
 *   <dt>Case 1: foobar</dt>
 *     <dd>        do case 1 things</dd>
 *   <dt>Case 2: fred hacker</dt>
 *     <dd>        do case 2 things</dd>
 *   <dt>Case 3: cowboyneal</dt>
 *     <dd>        do case 3 things</dd>
 * </dl>        
 * In all cases, do some other thing
 */

注意:我已经发表了 Javadoc 注释,而不是简单的注释,因为我认为其中包含大量文本的注释可能会更好地放在方法的前面。另外,Javadoc部分还具有更多可用于设置格式的参数。

如果在方法(真正的Javadoc)前面,则 HTML标签< dl> < dt> < dd> 将有助于在Javadoc视图中正确显示它。

Note: I have made a Javadoc comment, and not a simple comment, as I believe a comment with that much text in it may be better placed in front of a method. Plus, Javadoc sections have more formatting parameters to play with.
If it is in front of a method (true Javadoc), the HTML tags <dl>, <dt> and <dd> will help to present it properly within the Javadoc view.

这篇关于使Eclipse的Java代码格式化程序忽略块注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆