在自定义 Javadoc taglet 中展开内联标签
我编写了一个自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Taglet 概述说:
事实上,taglet API 有点太小了,因为它只支持
toString()
方法。您可以在此方法中检索参数
tag
的子标签(使用.inlineTags()
),但是您必须自己格式化它们,因为您没有从 taglet 访问标准 doclet 的正常机制。因此,如果您不想在自己的 taglet 中重新实现(或复制)标准 doclet 的部分内容,那么看起来您运气不好。 (但是,您同样可以直接扩展标准 doclet,而不是用 taglet 修补它。)
The Taglet overview says:
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.)
这里有三个可能的想法,但我并不真正喜欢其中一个:
不要定义自己的
Taglet
,而是使用javadoc
的-tag
选项> 命令支持@note
。当然,这不会让您定义自己的自定义格式。您可以使用
tag.holder().setRawCommentText(String)
。我的经验是,这可以让您添加标签,但不允许您重写标签。因此,您无法对tag.holder().getRawCommentText()
进行字符串替换,然后让标准 doclet 正确渲染内联标记,但您可能可以使用Taglet.toString (Tag[])
方法生成 html,包括原始形式的内联标签,然后附加到原始注释文本“@renderedNote
markedUp Tag.text() ”,其中@renderedNote
是另一个标签,使用-tag
定义。然后,您的Taglet.toString(Tag[])
应返回一个空字符串。然而,这不仅丑陋,我不知道这是否依赖于未记录的行为,所以我不知道这个想法有多稳健或未来的证明。您可以让您的
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:
Instead of defining your own
Taglet
, use the-tag
option to thejavadoc
command to support@note
. Of course, this won't let you define your own custom formatting.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 ontag.holder().getRawCommentText()
and then have the standard doclet render the inline tags properly, but you could probably have yourTaglet.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
. YourTaglet.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.You could have your
Taglet
also implementcom.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 areTagletOutput getTagletOutput(Tag tag, TagletWriter writer)
andTagletOutput getTagletOutput(Doc doc, TagletWriter writer)
. I think the latter can justthrow IllegalArgumentException()
. If you also keep theMap
provided when yourTaglet
was registered, then you may be able to render several of the inline tags that you encounter by looking up the tag name in thatMap
to get its implementingcom.sun.tools.doclets.internal.toolkit.taglets.Taglet
and delegating to itsgetTagletOutput
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 asSeeTag
you may be able to use the map from@see
instead, or you could cast theTagletWriter
toTagletWriterImpl
and then useTagletWriterImpl.seeTagOutput(Doc, SeeTag[])
. ForText
tags, you can generateTagletOutput
instances vianew TagletOutputImpl(String)
. Finally all theTagletOutput
instances that you get this way can be combined into a singleTagletOutput
to be returned usingTagletOutput.append(TagletOutput)
.