Javadoc 元数据的运行时保留?
有什么方法可以通过反射访问Javadoc信息,即可以在运行时保留注释的方式吗?
如果没有,Eclipse 如何访问 .jar 文件的 javadoc?
Is there any way to access Javadoc information via reflection, the way annotations can be retained at runtime?
If not, how does Eclipse access the javadoc for .jar files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
用于 Javadoc 的注释永远不会保留在已编译的类中(请参阅 http://例如 /java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf)。 Eclipse 能够将 Javadoc 与引用的 jar 文件关联起来,方法是从 jar 中提取 Javadoc(如果存在)、直接与 jar 文件关联(由您自己或像 m2eclipse 这样的插件设置),或者通过在 JRE javadoc 中查找它(直接在“Installed JREs”中设置)。
Comments used for Javadoc are never retained in compiled classes (see http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf for instance). Eclipse is able to associate Javadoc to the referenced jar files either by extracting it from the jar (if present), by direct association with the jar file (set by yourself or a plugin like m2eclipse), or by finding it inside the JRE javadoc (set directly in "Installed JREs").
JavaDoc 无法通过反射获得。 Eclipse 和其他 IDE 使用 JavaDoc 访问可用的库的 jar 文件。即,如果您使用 maven,带有 JavaDoc 的 jar 文件通常与带有字节代码的 jar 文件一起分发。
JavaDoc is not available via reflection. Eclipse and other IDE's access jar files with JavaDoc for libraries where this is available. I.e. if you use maven, jar files with JavaDoc is usually distributed along with jar files with the byte code.
理论上,可以有一个 javadoc doclet,它可以修改 javadoc 标签中的类,向记录的元素添加一些注释。
但我不知道有任何这样的 doclet(它还必须包含一些供运行时使用的注释类型)。
In theory, it would be possible to have a javadoc doclet which is modifying the classes from the javadoc tags, adding some annotations to the documented elements.
But I don't know of any such doclet (which would also have to include some annotation types for runtime use).
您可以使用此工具在运行时通过注释访问 Javadoc。它作为注释处理器运行并在编译时生成@Description注释。
https://github.com/Devexperts/dgen
You may use this tool to access Javadoc at runtime via annotations. It runs as annotation processor and generates @Description annotations at compile time.
https://github.com/Devexperts/dgen