如何获取具有特定注释的所有方法的 javadoc,以及方法名称和包/类名称?
我正在寻找一种在运行时获取具有特定注释的所有方法的所有 javadoc 的方法。 我将使用此 javadoc 在定制的 UI 中显示有关这些方法的详细信息。
这些方法稍后用于测试,它们将以未知的顺序调用,由用户确定 - 我希望让用户无需浏览源代码即可看到 javadoc。
是的,我有资源并且可以利用它们来实现目标。
我想到的最好方法是维护一个带有描述的单独文件,该文件将在运行时读取,但这意味着我必须维护 javadoc 和外部文件,而且我不喜欢维护两个副本的想法非常相似的文字。
为任何答案干杯! 谢谢。
I'm looking for a way to fetch all the javadoc for all methods with a specific Annotation, at runtime.
I'm going to use this javadoc to display details about these methods in a custom made UI.
These methods are later used for testing, they will be invoked in an unknown order, determined by the user - I wish to let the user see the javadoc without having to browse the sources.
Yes, I have the sources and can use them to achieve the goal.
The best way I thought about doing this is maintaining a separate file with descriptions, which will be read on runtime, but that means I have to maintain both javadoc and the external file, and I don't like the idea of maintaining two copies of the pretty similar text.
Cheers for any answers!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这并不像听起来那么简单,因为 JavaDoc 不是类文件的一部分(
java.lang.reflect.Method
上没有getJavaDoc()
方法)。我会这样解决这个问题:
org.eclipse.jdt.core_*.jar
添加到您的类路径中。“使用批处理编译器" 也可能有帮助)。AstVisitor
This isn't as simple as it sounds because the JavaDoc isn't part of the class file (there is no
getJavaDoc()
method onjava.lang.reflect.Method
).I'd attack the problem like this:
org.eclipse.jdt.core_*.jar
to your classpath. "Using the batch compiler" might also help).AstVisitor
如果您打算在 UI 中使用它并且您的代码库相当大,那么您可能需要考虑对 javadoc 建立索引并在索引上创建搜索查询。 Solr、Lucene、Sphinx 是您可以利用的几种技术。
我怀疑直接使用 JavaDocs 阅读是否能够获得可接受的性能。
在这里查看使用 Lucene 是多么容易
http://www.lucenetutorial.com/lucene-in-5-minutes.html
If you are going to use it in a UI and your code base is considerably large then you might want to consider indexing your javadocs and create search queries on the indexes. Solr, Lucene, Sphinx are few of the technologies you can utilize.
I doubt you will be able to gain acceptable performance by using JavaDocs directly to read.
Check out how easy it is to work with Lucene here
http://www.lucenetutorial.com/lucene-in-5-minutes.html
这是可能的,但需要一些努力。
通常,创建 javadoc 是通过运行已达到 CLI 的实用程序
javadoc
来实现的。您可以使用注释处理器 API 在编译时调用它,并与编译的资源一起存储。然后你可以在运行时读取它。
请查看此项目,这是注释预处理器使用的精美示例。
It is possible but requires some efforts.
Generally creating javadoc is achieved by running utility
javadoc
that has reach CLI.You can invoke it at compile time by using Annotation processor API and store together with your compiled resources. Then you can read it at runtime.
Please take a look on this project as a beautiful example of annotation preprocessor usage.