简体   繁体   English

我们可以制作 JavaDoc 工具来解析方法内的注释吗?

[英]can we make JavaDoc tool to parse comments inside methods?

I tried googling this question a lot but could not find the answer to exact question.我尝试在谷歌上搜索这个问题很多,但找不到确切问题的答案。 I also read this question: Does the javadoc tool recognize comments inside methods?我还阅读了这个问题: javadoc 工具是否识别方法中的注释?

So my question is kind-of a follow-up to this.所以我的问题是对此的跟进。 I know that default JavaDoc tool would simple ignore any javadoc comments inside methods, but can we somehow make it read those comments too and may be try handling them on our customer doclets/ taglets?我知道默认的 JavaDoc 工具会简单地忽略方法中的任何 javadoc 注释,但是我们能否以某种方式让它也读取这些注释,并且可以尝试在我们的客户 doclets/taglets 上处理它们? I tried writing my own doclet and taglet as well but since JavaDoc would completely ignore the comments inside methods, I could not succeed.我也尝试编写自己的 doclet 和 taglet,但由于 JavaDoc 会完全忽略方法中的注释,因此我无法成功。

For example, suppose I have the following code:例如,假设我有以下代码:

public void methodX() {
        /**
         * @MyTag This is a sample javadoc comment with custom tag
         */
    }

Is there a way to make JavaDoc not ignore the comment inside methodX?有没有办法让 JavaDoc 不忽略 methodX 中的注释? I could handle the response in a custom doclet if javadoc could parse and provide the comment text.如果 javadoc 可以解析并提供注释文本,我可以在自定义 doclet 中处理响应。

Reason to try this: I guess it would be helpful to know why I'm looking for such a requirement.尝试这样做的原因:我想知道我为什么要寻找这样的要求会很有帮助。 Basically we have a lot of configuration driven coding where these configurations are stored in DB (So that we could simply change the configuration at runtime without having to go through the BRD process again).基本上我们有很多配置驱动的编码,这些配置存储在 DB 中(这样我们可以在运行时简单地更改配置,而不必再次通过 BRD 过程)。 So we are planning to document those configurations at a central place.所以我们计划在一个中心位置记录这些配置。 And instead of keeping the code and document separate, we also think it would be wise to keep the documentation closer to code itself so that any code updations could also possibly update the documentation.与其将代码和文档分开,我们还认为让文档更接近代码本身是明智的,这样任何代码更新也可能更新文档。 Publishing to central place can be taken care of via doclets/ taglets but only if JavaDoc could read those comments inside methods.发布到中心位置可以通过 doclets/taglets 来处理,但前提是 JavaDoc 可以读取方法中的这些注释。

So is there a possibility of making JavaDoc tool read through comments inside methods as well?那么是否有可能让 JavaDoc 工具也通过方法内的注释来读取? Or else we would have to try and write our own comments parser similar to JavaDoc for this.否则,我们将不得不为此尝试编写类似于 JavaDoc 的我们自己的注释解析器。

So I did a little digging around and seeing that no-one has answered the question, it seems people are (maybe) not sure about the possibility.所以我做了一些挖掘,发现没有人回答这个问题,似乎人们(也许)不确定这种可能性。

Based on what I found, it doesn't seem feasible to have the JavaDoc tool parse the comments inside methods.根据我的发现,让 JavaDoc 工具解析方法中的注释似乎不可行。 The reason being, JavaDoc doesn't even get those comment texts to parse .原因是, JavaDoc 甚至没有得到那些注释文本来解析. Now, what I mean here is, JavaDoc relies on the JDK compiler (the API of-course) to have the Java code converted into tokens and trees and then gets all the comments from there.现在,我在这里的意思是, JavaDoc 依赖 JDK 编译器(当然是 API)将 Java 代码转换为令牌和树,然后从那里获取所有注释。 So unless you are okay modifying the JDK compiler itself to make it "Do Not Ignore" the comments inside methods, you can't make JavaDoc to read comments inside method.因此,除非您可以修改 JDK 编译器本身以使其“不要忽略”方法内的注释,否则您无法让 JavaDoc 读取方法内的注释。

Oh!哦! And for the part of solving our problem, we're, for now, restricting to define JavaDocs with custom Tags for the constants we used and have the comments processed via a Custom Taglet to handle the new Tags.对于解决我们问题的部分,我们现在限制为我们使用的常量定义带有自定义标签的 JavaDocs,并通过自定义 Taglet处理注释以处理新标签。

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

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