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

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

问题描述

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

  / * 
* PSEUDOCODE
*读入用户字符串/段落
*
*三种情况可能
*案例1:foobar
*案例1事情
*案例2:fred hacker
* do case 2事情
*案例3:cowboyneal
*做案例3事情
*
*在所有情况下,做其他事情
* /

  / * 
* PSEUDOCODE读入用户字符串/段落
*
*三种情况可能情况1:foobar做case 1事情情况2:fred
* hacker做case 2事情情况3:cowboyneal做case 3事情
*
*在所有情况下,做一些其他事情
* /

我已经玩过Windows>首选项> Java>代码样式>格式化程序设置,但是找不到一个用于保持注释格式。我使用的是Eclipse 3.4.0。

解决方案

使用Java Formatter( Windows& ; Java> Code Style> Formatter ),您可以创建一个新的Formatter配置文件。



),您可以确保在 Javadoc注释设置中取消选中格式化HTML标签。 br>
也请检查常规设置部分中的永不加入行。 p>

然后您的评论应写成:

  / ** 
* PSEUDOCODE
*读入用户字符串/段落
*
*三种情况是可能的:
*< dl>
*< dt>情况1:foobar< / dt>
*< dd>做case 1事情< / dd>
*< dt>案例2:fred hacker< / dt>
*< dd>做case 2东西< / dd>
*< dt>案例3:cowboyneal< / dt>
*ⅆ做情况3事情< / dd>
*< / dl>
*在所有情况下,做一些其他事情
* /

我已经写了一个 Javadoc 注释,而不是一个简单的注释,因为我相信一个注释有很多文本可能更好地放在一个方法的前面。此外,Javadoc部分还有更多的格式化参数。

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


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
     */

into 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
     */

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.

解决方案

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

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
 */

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天全站免登陆