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

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

问题描述

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

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

到这个:

  / * 
* PSEUDOCODE读入用户的字符串/段
*
*三种情况可能情况1:foobar做案例1事情情况2:fred
*黑客做案例2事情案例3:cowboyneal做案例3事物
*
*在所有情况下,做一些其他事情
* /

我已经玩过Windows> Preferences> Java> Code Style> Formatter设置,但找不到一个f或保留注释格式。我使用Eclipse 3.4.0。

解决方案

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



在注释选项卡(在eclipse3.5 ),您可以在 Javadoc注释设置中取消选中格式化HTML标签。 br>
另请参阅常规设置部分中的从不连接线。 p>

然后你的评论应写成:

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

注意:我已经发表了一个 Javadoc 注释,而不是一个简单的评论,因为我相信一个很多文本的评论可能会更好地放在一个方法的前面。另外,Javadoc部分有更多的格式化参数可以玩。

如果它在一个方法(true J​​avadoc)前面, HTML标签< dl> < dt>   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天全站免登陆