在自定义 Javadoc taglet 中展开内联标签

发布于 2024-10-02 06:59:24 字数 621 浏览 2 评论 0原文

我编写了一个自定义 Javadoc taglet,它添加了一个新的 note 标签:

 ...
 public boolean isInlineTag() { return false; }

  public String toString(Tag tag) {
      return "<pre class='note'>" + tag.text() + "</pre>";
   }

到目前为止它可以工作,但内联标签没有扩展。以下是注释示例:

/**
 * @note Test note with {@link Someclass} // @link tag is NOT expanded
 * @param name - here the {@link Someclass} works // works for standard 'param' tag
 */

{@link} 内联标记未展开。但是,它对于内置 param javadoc 标记来说效果很好。

有没有办法在自定义 Javadoc taglet 中扩展嵌套内联标签?

谢谢!

I wrote a custom Javadoc taglet that adds a new note tag:

 ...
 public boolean isInlineTag() { return false; }

  public String toString(Tag tag) {
      return "<pre class='note'>" + tag.text() + "</pre>";
   }

It works so far, but inline tags are not expanded. Here is an example comment:

/**
 * @note Test note with {@link Someclass} // @link tag is NOT expanded
 * @param name - here the {@link Someclass} works // works for standard 'param' tag
 */

The {@link} inline tag is not expanded. However, it works just fine for the built-in param javadoc tag.

Is there a way to expand nested inline tags in a custom Javadoc taglet?

Thanks!

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

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

发布评论

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

评论(2

孤独岁月 2024-10-09 06:59:24

Taglet 概述说:

Taglet 可以写成块标签(例如@todo)或内联标签(例如{@underline})。块 taglet 目前不支持其文本中的内联标记。

事实上,taglet API 有点太小了,因为它只支持 toString() 方法。

您可以在此方法中检索参数 tag 的子标签(使用 .inlineTags()),但是您必须自己格式化它们,因为您没有从 taglet 访问标准 doclet 的正常机制。

因此,如果您不想在自己的 taglet 中重新实现(或复制)标准 doclet 的部分内容,那么看起来您运气不好。 (但是,您同样可以直接扩展标准 doclet,而不是用 taglet 修补它。)

The Taglet overview says:

Taglets can be written as either block tags, such as @todo, or inline tags, such as {@underline}. Block taglets do not currently support inline tags in their text.

In fact, the taglet API is a bit too minimal, as it supports only the toString() method.

You could inside this method retrieve the subtags of the parameter tag (with .inlineTags()), but then you would have to format them yourself, since you don't have access to the normal machinery of the standard doclet from your taglet.

So, looks like you are out of luck here, if you don't want to reimplement (or copy) parts of the standard doclet in your own taglet. (But then, you could the same directly extend the standard doclet instead of patching it with taglets.)

铁憨憨 2024-10-09 06:59:24

这里有三个可能的想法,但我并不真正喜欢其中一个:

  1. 不要定义自己的 Taglet,而是使用 javadoc-tag 选项> 命令支持@note。当然,这不会让您定义自己的自定义格式。

  2. 您可以使用tag.holder().setRawCommentText(String)。我的经验是,这可以让您添加标签,但不允许您重写标签。因此,您无法对 tag.holder().getRawCommentText() 进行字符串替换,然后让标准 doclet 正确渲染内联标记,但您可能可以使用 Taglet.toString (Tag[]) 方法生成 html,包括原始形式的内联标签,然后附加到原始注释文本“@renderedNote markedUp Tag.text() ”,其中 @renderedNote 是另一个标签,使用 -tag 定义。然后,您的 Taglet.toString(Tag[]) 应返回一个空字符串。然而,这不仅丑陋,我不知道这是否依赖于未记录的行为,所以我不知道这个想法有多稳健或未来的证明。

  3. 您可以让您的 Taglet 也实现 com.sun.tools.doclets.internal.toolkit.taglets.Taglet。这似乎就是标准 taglet 的定义方式。您必须实现的两个方法是 TagletOutput getTagletOutput(Tag tag, TagletWriter writer)TagletOutput getTagletOutput(Doc doc, TagletWriter writer)。我认为后者可以抛出 IllegalArgumentException()。如果您还保留注册 Taglet 时提供的 Map,那么您可以通过在其中查找标记名称来呈现您遇到的多个内联标记。 Map 获取其实现 com.sun.tools.doclets.internal.toolkit.taglets.Taglet 并委托给其 getTagletOutput 方法。但是,例如,@link 标签似乎未在该地图中注册;对于这些,有可能(但我没有检查过),因为 @link 标签据称是作为 SeeTag 提供的,您也许可以使用 @ 中的地图see 相反,或者您可以将 TagletWriter 转换为 TagletWriterImpl,然后使用 TagletWriterImpl.seeTagOutput(Doc, SeeTag[])。对于 Text 标签,您可以通过 new TagletOutputImpl(String) 生成 TagletOutput 实例。最后,通过这种方式获得的所有 TagletOutput 实例都可以组合成一个 TagletOutput,并使用 TagletOutput.append(TagletOutput) 返回。< /p>

Here's three possible ideas, none of which I really like:

  1. Instead of defining your own Taglet, use the -tag option to the javadoc command to support @note. Of course, this won't let you define your own custom formatting.

  2. You could use tag.holder().setRawCommentText(String). My experience playing with this is that this lets you add tags, but doesn't let you rewrite a tag. So you can't do a string replacement on tag.holder().getRawCommentText() and then have the standard doclet render the inline tags properly, but you could probably have your Taglet.toString(Tag[]) method generate the html, including the raw form of the inline tags, and then append to the raw comment text "@renderedNote markedUp Tag.text()" where @renderedNote is another tag, defined using -tag. Your Taglet.toString(Tag[]) should then return an empty string. However, not only is this ugly, I don't know if this relies on undocumented behavior and so I don't know how robust or future proof this idea is.

  3. You could have your Taglet also implement com.sun.tools.doclets.internal.toolkit.taglets.Taglet. This seems to be how the standard taglets are defined. The two methods you then have to implement are TagletOutput getTagletOutput(Tag tag, TagletWriter writer) and TagletOutput getTagletOutput(Doc doc, TagletWriter writer). I think the latter can just throw IllegalArgumentException(). If you also keep the Map provided when your Taglet was registered, then you may be able to render several of the inline tags that you encounter by looking up the tag name in that Map to get its implementing com.sun.tools.doclets.internal.toolkit.taglets.Taglet and delegating to its getTagletOutput method. However, it looks like, for example, @link tags are not registered in that map; for those, it's possible (but I haven't checked) that because @link tags are supposedly provided as SeeTag you may be able to use the map from @see instead, or you could cast the TagletWriter to TagletWriterImpl and then use TagletWriterImpl.seeTagOutput(Doc, SeeTag[]). For Text tags, you can generate TagletOutput instances via new TagletOutputImpl(String). Finally all the TagletOutput instances that you get this way can be combined into a single TagletOutput to be returned using TagletOutput.append(TagletOutput).

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