Sorry for a probable FAQ kind of question, but I just can't find the answer.
很抱歉我有个常见问题,但我就是找不到答案。
As far as I remember Eclipse, a blank line in a Javadoc comment is displayed (in in-source Javadoc popups) as a line break (with extra vertical spacing).
就我所知,在Eclipse中,Javadoc注释中的空行显示为换行符(具有额外的垂直间距)。
In Netbeans, however, this is not the case.
然而,在Netbeans中,情况并非如此。
Can I configure Javadoc to interpret a blank line as a line break?
我可以配置Javadoc将空行解释为换行吗?
Additional question: Can I override default Netbeans behavior (related to this) for in-source Javadoc popups?
附加问题:我可以为源Javadoc弹出窗口覆盖默认的Netbeans行为(与此相关)吗?
What I'm talking about is:
我说的是
Source
/**
* Paragraph One
*
* Paragraph Two
*/
void someMethod() { }
Eclipse interpretation
Paragraph One
Paragraph Two
Netbeans interpretation
Paragraph One Paragraph Two
7 个解决方案
#1
58
It has nothing to do with Netbeans. I suspect you are looking at the source code in one case and the output of Javadoc in the other case. Newlines are not significant in HTML ergo the output will not show them. If you want a newline use a <p>
or a <br>
.
它与Netbeans没有关系。我怀疑您正在查看一种情况下的源代码和另一种情况下Javadoc的输出。换行在HTML中并不重要,因此输出将不会显示它们。如果希望换行,请使用
或
。
#2
24
I'm not sure if this helps for OP's case, however I put <pre></pre>
around my document so netbean does not mess up my formatting. So it will look like
我不确定这对OP是否有帮助,但是我在文档周围加上了
,这样netbean就不会打乱我的格式。看起来是这样的/**
* <pre>
* Paragraph One
*
* Paragraph Two
* </pre>
*/
This is closest I get to showing new lines in text format. I'm using NetBeans 7.1.2. This way using code format
option will not reformat the document. Showing doc in hints is still formatted.
这是最接近于显示文本格式的新行。我使用NetBeans 7.1.2。这样使用代码格式选项将不会重新格式化文档。在提示中显示doc仍然是格式化的。
Update: in Netbeans 8.x there is an option in code formatting to disable formatting comments.
更新:在Netbeans 8。在代码格式化中有一个选项可以禁用格式化注释。
#3
7
There is already an option in NetBeans
- tested on version 8.2 - that allows you to preserve new lines in your comments, and/or add a <p>
tag to your Javadoc
if needed
NetBeans中已经有一个选项——在8.2版本中进行了测试——允许您在注释中保留新行,如果需要,还可以向Javadoc添加
标记
- Just from the
Tools
menu, choseOptions
- 从“工具”菜单中选择“选项”。
- Go to
Editor
tab, thenFormatting
tab - 转到Editor选项卡,然后格式化选项卡。
- In the 'Language' menu chose
Java
, and in 'Category' menu choseComments
- “语言”菜单选择Java,“类别”菜单选择评论
- Check the
Preserve New Lines
checkbox in theGeneral
section if you want to preserve new lines in your comments. This will preserve new lines without adding<p>
tag -
如果您想在评论中保留新行,请在常规部分检查保存新行复选框。这将保留新的行,而不添加
标记
- Check
Generate "<p>" on Blank Lines
checkbox in theJavadoc
section if you also want to add<p>
tag. -
如果您还想添加
标记,请在Javadoc部分的空行复选框中选择“
”。
#4
4
I agree with you, HTML doesn't belong in source-code. Sadly, I didn't find much help Googling around for this. It's actually quite easy to implement.
我同意你的观点,HTML不属于源代码。遗憾的是,我在谷歌上搜索这条消息时没有发现什么帮助。它实际上很容易实现。
Here's the custom Doclet that you can compile and use:
这里是您可以编译和使用的自定义Doclet:
import com.sun.javadoc.*;
import com.sun.tools.doclets.standard.*;
/**
* Formats text-only comments with HTML.
*/
@SuppressWarnings("restriction")
public final class TextDoclet {
private static final Pattern NEWLINE_REGEX = Pattern.compile("\\n");
private static final String BR = "<br/>\n";
public static boolean start(RootDoc rootDoc) {
for ( ClassDoc classdoc : rootDoc.classes())
classdoc.setRawCommentText(formatText(classdoc.getRawCommentText()));
return Standard.start(rootDoc);
}
private static String formatText(String text) {
return NEWLINE_REGEX.matcher(text).replaceAll(BR);
}
}
An example of how to invoke it using javadoc:
如何使用javadoc调用它的示例:
javadoc -docletpath ~/project/text-doclet/target/text-doclet-1.0.0-SNAPSHOT.jar -doclet com.myorg.textdoclet.TextDoclet -sourcepath ~/project/myapp/src/main/java -subpackages com.myorg.myapp
#5
2
JavaDoc displays the way the CSS styles have been defined. You could edit the CSS styles associated with paragraph tags to do this:
JavaDoc显示了CSS样式的定义方式。您可以编辑与段落标签相关的CSS样式来完成以下操作:
p {
line-height: 25px;
}
#6
1
This is a pseudo-solution
(which sadly affects only generated javadoc, but does not affect Netbeans' in-source javadoc display).
这是一个伪解决方案(可惜只影响生成的javadoc,但不影响Netbeans的源内javadoc显示)。
Specify a stylesheet which contain the following:
指定一个包含以下内容的样式表:
div.block {
white-space: pre;
}
#7
0
I have no idea what Eclipse is doing here, but if you want this behavior in general (not only an IDE), you may have to create a new Doclet (which may be based on the default HTML doclet) instead, there inserting a <p>
at every empty line or such.
我不知道Eclipse在这里做什么,但是如果您想要这个行为(不仅仅是IDE),您可能需要创建一个新的Doclet(可能基于默认的HTML Doclet),而是在每个空行插入一个
。
#1
58
It has nothing to do with Netbeans. I suspect you are looking at the source code in one case and the output of Javadoc in the other case. Newlines are not significant in HTML ergo the output will not show them. If you want a newline use a <p>
or a <br>
.
它与Netbeans没有关系。我怀疑您正在查看一种情况下的源代码和另一种情况下Javadoc的输出。换行在HTML中并不重要,因此输出将不会显示它们。如果希望换行,请使用
或
。
#2
24
I'm not sure if this helps for OP's case, however I put <pre></pre>
around my document so netbean does not mess up my formatting. So it will look like
我不确定这对OP是否有帮助,但是我在文档周围加上了
,这样netbean就不会打乱我的格式。看起来是这样的/**
* <pre>
* Paragraph One
*
* Paragraph Two
* </pre>
*/
This is closest I get to showing new lines in text format. I'm using NetBeans 7.1.2. This way using code format
option will not reformat the document. Showing doc in hints is still formatted.
这是最接近于显示文本格式的新行。我使用NetBeans 7.1.2。这样使用代码格式选项将不会重新格式化文档。在提示中显示doc仍然是格式化的。
Update: in Netbeans 8.x there is an option in code formatting to disable formatting comments.
更新:在Netbeans 8。在代码格式化中有一个选项可以禁用格式化注释。
#3
7
There is already an option in NetBeans
- tested on version 8.2 - that allows you to preserve new lines in your comments, and/or add a <p>
tag to your Javadoc
if needed
NetBeans中已经有一个选项——在8.2版本中进行了测试——允许您在注释中保留新行,如果需要,还可以向Javadoc添加
标记
- Just from the
Tools
menu, choseOptions
- 从“工具”菜单中选择“选项”。
- Go to
Editor
tab, thenFormatting
tab - 转到Editor选项卡,然后格式化选项卡。
- In the 'Language' menu chose
Java
, and in 'Category' menu choseComments
- “语言”菜单选择Java,“类别”菜单选择评论
- Check the
Preserve New Lines
checkbox in theGeneral
section if you want to preserve new lines in your comments. This will preserve new lines without adding<p>
tag -
如果您想在评论中保留新行,请在常规部分检查保存新行复选框。这将保留新的行,而不添加
标记
- Check
Generate "<p>" on Blank Lines
checkbox in theJavadoc
section if you also want to add<p>
tag. -
如果您还想添加
标记,请在Javadoc部分的空行复选框中选择“
”。
#4
4
I agree with you, HTML doesn't belong in source-code. Sadly, I didn't find much help Googling around for this. It's actually quite easy to implement.
我同意你的观点,HTML不属于源代码。遗憾的是,我在谷歌上搜索这条消息时没有发现什么帮助。它实际上很容易实现。
Here's the custom Doclet that you can compile and use:
这里是您可以编译和使用的自定义Doclet:
import com.sun.javadoc.*;
import com.sun.tools.doclets.standard.*;
/**
* Formats text-only comments with HTML.
*/
@SuppressWarnings("restriction")
public final class TextDoclet {
private static final Pattern NEWLINE_REGEX = Pattern.compile("\\n");
private static final String BR = "<br/>\n";
public static boolean start(RootDoc rootDoc) {
for ( ClassDoc classdoc : rootDoc.classes())
classdoc.setRawCommentText(formatText(classdoc.getRawCommentText()));
return Standard.start(rootDoc);
}
private static String formatText(String text) {
return NEWLINE_REGEX.matcher(text).replaceAll(BR);
}
}
An example of how to invoke it using javadoc:
如何使用javadoc调用它的示例:
javadoc -docletpath ~/project/text-doclet/target/text-doclet-1.0.0-SNAPSHOT.jar -doclet com.myorg.textdoclet.TextDoclet -sourcepath ~/project/myapp/src/main/java -subpackages com.myorg.myapp
#5
2
JavaDoc displays the way the CSS styles have been defined. You could edit the CSS styles associated with paragraph tags to do this:
JavaDoc显示了CSS样式的定义方式。您可以编辑与段落标签相关的CSS样式来完成以下操作:
p {
line-height: 25px;
}
#6
1
This is a pseudo-solution
(which sadly affects only generated javadoc, but does not affect Netbeans' in-source javadoc display).
这是一个伪解决方案(可惜只影响生成的javadoc,但不影响Netbeans的源内javadoc显示)。
Specify a stylesheet which contain the following:
指定一个包含以下内容的样式表:
div.block {
white-space: pre;
}
#7
0
I have no idea what Eclipse is doing here, but if you want this behavior in general (not only an IDE), you may have to create a new Doclet (which may be based on the default HTML doclet) instead, there inserting a <p>
at every empty line or such.
我不知道Eclipse在这里做什么,但是如果您想要这个行为(不仅仅是IDE),您可能需要创建一个新的Doclet(可能基于默认的HTML Doclet),而是在每个空行插入一个
。