如何防止Eclipse包含注释部分

时间:2014-02-25 06:09:01

标签: eclipse formatting comments

我在save命令上调用的Eclipse格式化程序设置为包装注释行,因为这是我大多数时候所希望的。但是,我偶尔希望Eclipse不要包含一些注释。这是一个例子。

如果我写:

    /**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output:
 * <comments>
 *   <comment>This should be on one line</comment>
 *   <comment>And this on the next</comment>
 * </comments>
 * 
 */

Eclipse格式化程序会将其转换为:

/**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output: <comments> <comment>This should be on one line</comment>
 * <comment>And this on the next</comment> </comments>
 * 
 */

我不想要。我知道我可以阻止每一行用<li>包装如下,但是这很快就会变得很麻烦,使得注释更加混乱,并且仍然无法阻止Eclipse更改缩进:

    /**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output:<li>
 * <comments><li>
 * <comment>This should be on one line</comment><li>
 * <comment>And this on the next</comment><li>
 * </comments><li>
 * 
 */

我可以在“示例输出”之前放一些东西告诉Eclipse忽略格式化程序,以便它保留我只选择部分评论的缩进和换行吗?

2 个答案:

答案 0 :(得分:0)

增加代码样式格式化程序中注释的行宽应该可以解决您的问题。

答案 1 :(得分:0)

上面的Eclipse 3.6允许忽略或部分代码。转到首选项 - &gt;代码风格 - &gt;格式化。编辑现有格式化程序。转到关/开标签。您可以定义自己的标签,并在评论中使用它来忽略该格式的部分。