如何创建自定义 javadoc 标签?

发布于 2024-08-29 18:13:41 字数 446 浏览 3 评论 0原文

如何创建自定义 javadoc 标签,例如 @pre / @post?我找到了一些解释它的链接,但我没有运气。这些是一些链接:

http://www. developer.com/java/other/article.php/3085991/Javadoc-Programming.html

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html

How do I create custom javadoc tags such as @pre / @post? I found some links that explain it but I haven't had luck with them. These are some of the links:

http://www.developer.com/java/other/article.php/3085991/Javadoc-Programming.html

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

焚却相思 2024-09-05 18:13:41

java代码

/**
 * @custom.mytag hey ho...
 */

java文档选项

-tag custom.mytag:a:"This is my Tag:"

输出

这是我的标签:

<块引用>

嘿嘿...

java code

/**
 * @custom.mytag hey ho...
 */

java doc option

-tag custom.mytag:a:"This is my Tag:"

output

This is my Tag:

hey ho...

心头的小情儿 2024-09-05 18:13:41

不应使用 HTML 创建自定义标签,因为 javadoc 可能会更改其实现或呈现数据的方式,也许他们会开始使用 Markdown 将来,Javadoc 导出器也不会捕获丢失的信息,并且您可能有空的“标签”。

首先使用您想要的任何标签:

/**
 * Comments and a {@link #methodLink} for this method.
 * 
 * @tt.wrapper {@link OtherClass}
 *
 */
public String extractName() {
    // method contents
}

请注意,自定义标签的格式为 @[prefix].[tagName],这是因为 doclet(或另一个 Eclipse 插件)可能会释放它自己的标签使用相同的名称,您的标签只会覆盖标准标签,因此我们添加一个前缀以降低发生这种情况的可能性。

来自 doclet 的评论。

可以覆盖未来标准标签的自定义标签:@wrapper 要避免潜在的覆盖,请在自定义标签名称中至少使用一个句点字符 (.)。


现在您必须告诉 Javadoc 导出器这个自定义标记 @tt.wrapper
转到项目>;在 Eclipse 中生成 Javadoc..(在我的例子中为 Indigo)。

配置该对话框前两个屏幕的设置后(使用“下一步”更改屏幕),您应该看到以下屏幕:

Third Eclipse Doclet Javadoc Export 的配置屏幕

您应该注意到“Extra Javadoc options..”文本框具有您必须添加的值
供 Javadoc 导出器创建与您的标记等效的 HTML。

在我们的例子中,选项是这样的(如果您想要多个标签,请将它们放在新行中):

-tag tt.wrapper:a:"API Wrapper:"

现在,当您导出 Javadoc 时(我还建议保存 ANT 脚本,这样您就不必每次都通过此对话框)您的自定义标签将显示为粗体,并带有说明和下面的值。

PS 我还没有找到一种方法来添加为自定义标签添加自动完成的功能,但这在 Indigo 中似乎是不可能的,也许会在未来的版本中出现(不确定 Juno 是否有)。

Custom tags should not be created using HTML because javadoc might change it's implementation or how it presents data, maybe they'll start using Markdown in the future, also the Javadoc exporter will not catch missing information and you might have empty "tags".

First use whatever tag you want:

/**
 * Comments and a {@link #methodLink} for this method.
 * 
 * @tt.wrapper {@link OtherClass}
 *
 */
public String extractName() {
    // method contents
}

Notice that the custom tag has the format @[prefix].[tagName], this is due to the fact that doclet (or another Eclipse plugin) might release it's own tag with the same name, and your tag would just override the standard tag, so we add a prefix to make it less likely of that happening.

Comment from doclet.

Custom tags that could override future standard tags: @wrapper To avoid potential overrides, use at least one period character (.) in custom tag names.


Now you have to tell the Javadoc exporter about this custom tag, @tt.wrapper.
Go to Project > Generate Javadoc.. in Eclipse (Indigo in my case).

After configuring the settings for the first two screens of this dialog (using "Next" to change screens) you should see this screen:

Third configuration screen for Eclipse Doclet Javadoc Export

You should notice that the "Extra Javadoc options.." text box has the value you must add
for the Javadoc exporter to create the HTML equivalent of your tag.

In our case the option is this (if you want multiple tags, put them on a new line):

-tag tt.wrapper:a:"API Wrapper:"

Now when you export your Javadoc (I also recommend saving an ANT script so you don't have to go through this dialog every time) you will have your custom tag in bold with the description, and the values underneath.

P.S. I have yet to find a way to add the ability to add auto-completion for the custom tags, but it seems impossible in Indigo, maybe it'll be in future releases (not sure if Juno has it).

花开柳相依 2024-09-05 18:13:41

如果您想要多个,请执行类似于 javadoc -tag pre -tag post -tag invariant 的操作,其中要求命令行参数。不要使用 html 的东西

If you want multiple, do something like javadoc -tag pre -tag post -tag invariant where it asks for command line arguments. Don't use the html stuff

GRAY°灰色天空 2024-09-05 18:13:41

好吧,我所做的不是最好的解决方案,但可读:

  /** <p><b>Pre:</b></p>  <Ul>True</Ul>
    * <p><b>Post:</b></p> <Ul>The x is pushed onto the top of the stack,
    *                       and the rest of the stack remains unchanged.</Ul>
    *
    * @param x              Indicates the current node
    */
   public void push(int x){
      ...
   }

在找到正确的答案之前,希望它有所帮助!

Well what i did is not the best solution but is readable:

  /** <p><b>Pre:</b></p>  <Ul>True</Ul>
    * <p><b>Post:</b></p> <Ul>The x is pushed onto the top of the stack,
    *                       and the rest of the stack remains unchanged.</Ul>
    *
    * @param x              Indicates the current node
    */
   public void push(int x){
      ...
   }

Till a proper answer is found, hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文