简体   繁体   English

如何在com.sun.javadoc.Taglet中获取{@docroot}的值?

[英]How to get value of {@docroot} in a com.sun.javadoc.Taglet?

I'm writing a custom taglet for inclusion of a mathML file in a javadoc html file. 我正在编写一个自定义标签,以便在javadoc html文件中包含mathML文件。 I would like to store all my *.mml files in the same folder, possibly in the 我想将所有* .mml文件存储在同一文件夹中,可能在

{@docroot}/doc-files

folder. 夹。 My question is : how can I know the value of the @docRoot string within a Taglet object (more specifically, within the toString(com.sun.javadoc.Tag tag) method ? Many thanks! 我的问题是:如何知道Taglet对象中的@docRoot字符串的值(更具体地说,是toString(com.sun.javadoc.Tag tag)方法的值?

I also needed to display MathML in my javadoc. 我还需要在我的javadoc中显示MathML。 I wrote a blog post about how I solved it here: http://chadretz.wordpress.com/2010/12/19/mathml-inside-javadoc-using-mathjax-and-a-custom-taglet/ 我在这里写了一篇有关如何解决它的博客文章: http : //chadretz.wordpress.com/2010/12/19/mathml-inside-javadoc-using-mathjax-and-a-custom-taglet/

More specifically to your problem though, if you look at the Taglet source code I posted there (collapsed by default), you can see where I get the top level ClassDoc of the Tag.holder() to obtain the directory depth I am at so I can traverse up. 但是,更具体地讲,如果您查看我在此处发布的Taglet源代码(默认情况下已折叠),则可以看到我从哪里获得Tag.holder()的顶级ClassDoc来获取我所在的目录深度我可以走过去。 This helps if you need the relative HTML root. 如果您需要相对的HTML根目录,这会有所帮助。 If you need to know the location of your MML's while the Taglet is running, I suggest you put them on the classpath and access them as resources. 如果您在运行Taglet时需要了解MML的位置,建议您将其放在类路径中,并作为资源进行访问。

Starting with the getPackageDoc function from @ChadRetz's blog , I've created a utility class that contains a function that does what you wish: Given a com.sun.javadoc.Tag , it returns the relative url from its enclosing file (the file containing that tag), to the JavaDoc root directory--this is the equivalent of {@docRoot} . @ChadRetz的博客中getPackageDoc函数开始,我创建了一个实用程序类,其中包含一个满足您期望的功能:给定com.sun.javadoc.Tag ,它从其随附文件(包含标签)到JavaDoc根目录-这等效于{@docRoot}

The class is called ComSunJavaDocUtil , and the function name is getRelativeUrlToDocRoot . 该类称为ComSunJavaDocUtil ,函数名称为getRelativeUrlToDocRoot

An example taglet's toString() function: 一个示例标记的toString()函数:

public String toString(Tag tag) {
   return  "Relative url to DOC ROOT for this tag's enclosing file is \"" + 
      ComSunJavaDocUtil.getRelativeUrlToDocRoot(tag) + "\"";
}

This utility class is part of Codelet . 该实用程序类是Codelet的一部分。 Installation instructions are here . 安装说明在这里 If this utility class is all you're going to use, then the only jars you need on your classpath are codelet and xbnjava ...and, of course, com.sun.javadoc . 如果您将只使用该实用程序类,则类路径上唯一需要的jar是codeletxbnjava ...,当然还有com.sun.javadoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM