为什么Eclipse代码格式化程序在Javadoc @see标记中中断?

时间:2023-02-05 12:32:05

I'm using Eclipse 3.4 and have configured the Java code formatter with all of the options on the Comments tab enabled. The problem is that when I format a document comment that contains:

我正在使用Eclipse 3.4并配置了Java代码格式化程序,并启用了“注释”选项卡上的所有选项。问题是当我格式化包含以下内容的文档注释时:

* @see <a href="test.html">test</a>

the code formatter inserts a space in the closing HTML, breaking it:

代码格式化程序在结束HTML中插入一个空格,打破它:

* @see <a href="test.html">test< /a>

Why? How do I stop this happening?

为什么?我该如何阻止这种情况发生?

This is not fixed by disabling any of the options on the Comments tab, such as Format HTML tags. The only work-around I found is to disable Javadoc formatting completely by disabling both the Enable Javadoc comment formatting and Enable block comment formatting options, which means I then have to format comment blocks manually.

禁用“注释”选项卡上的任何选项(例如格式HTML标记)无法解决此问题。我发现的唯一解决方法是通过禁用启用Javadoc注释格式和启用块注释格式选项来完全禁用Javadoc格式,这意味着我必须手动格式化注释块。

3 个解决方案

#1


4  

I can only assume it's a bug in Eclipse. It only happens with @see tags, it happens also for all 3 builtin code formatter settings.

我只能假设它是Eclipse中的一个错误。它只发生在@see标签上,它也适用于所有3个内置代码格式化程序设置。

There are some interesting bugs reported already in the neighbourhood, but I couldn't find this specific one. See for example a search for @see in the Eclipse Bugzilla.

已经在附近报道了一些有趣的错误,但我找不到这个特定的错误。例如,请参阅Eclipse Bugzilla中的@see搜索。

#2


1  

Strict XML specifications require that the self closing tags should have a space before the closing slash like so:

严格的XML规范要求自闭标签在结束斜杠之前应该有一个空格,如下所示:

<gcServer enabled="true" /> <!-- note the space just after "true" -->

I can only assume, like Bart said, that there is a bug in Eclipse's reformatter that thinks the closing tag is actually a self-closing tag. Another idea: Can you verify that your a tags are balanced (i.e. no unclosed tags higher up in the document)?

我只能假设,就像Bart说的那样,Eclipse的重新格式化程序中存在一个错误,认为结束标记实际上是一个自动关闭的标记。另一个想法:你能验证你的标签是否平衡(即文件中没有未封闭的标签)?

#3


1  

This could be a bug in Eclipse 3.4. I'm using 3.3 (M20080221-1800), and do not observe this behavior.

这可能是Eclipse 3.4中的一个错误。我正在使用3.3(M20080221-1800),并且没有观察到这种行为。

#1


4  

I can only assume it's a bug in Eclipse. It only happens with @see tags, it happens also for all 3 builtin code formatter settings.

我只能假设它是Eclipse中的一个错误。它只发生在@see标签上,它也适用于所有3个内置代码格式化程序设置。

There are some interesting bugs reported already in the neighbourhood, but I couldn't find this specific one. See for example a search for @see in the Eclipse Bugzilla.

已经在附近报道了一些有趣的错误,但我找不到这个特定的错误。例如,请参阅Eclipse Bugzilla中的@see搜索。

#2


1  

Strict XML specifications require that the self closing tags should have a space before the closing slash like so:

严格的XML规范要求自闭标签在结束斜杠之前应该有一个空格,如下所示:

<gcServer enabled="true" /> <!-- note the space just after "true" -->

I can only assume, like Bart said, that there is a bug in Eclipse's reformatter that thinks the closing tag is actually a self-closing tag. Another idea: Can you verify that your a tags are balanced (i.e. no unclosed tags higher up in the document)?

我只能假设,就像Bart说的那样,Eclipse的重新格式化程序中存在一个错误,认为结束标记实际上是一个自动关闭的标记。另一个想法:你能验证你的标签是否平衡(即文件中没有未封闭的标签)?

#3


1  

This could be a bug in Eclipse 3.4. I'm using 3.3 (M20080221-1800), and do not observe this behavior.

这可能是Eclipse 3.4中的一个错误。我正在使用3.3(M20080221-1800),并且没有观察到这种行为。