以编程方式访问有关 Java 库的信息
我想为 Java 编写玩具 IDE,所以我问了一个关于一件特定事情的问题,我希望这可以帮助我开始。
我在 swing 之上实现了编辑器,里面有一些文本。例如:
import java.util.List;
现在我需要一种方法将“java.util.List”字符串发送到一个方法,该方法返回我可能需要的所有信息,包括 JavaDoc 文档。
那么是否有任何工具可以使用库设置类路径,它可以解析我发送的每个字符串并尝试查找是否有任何带有文档的类/接口要返回?
I would like to write toy IDE for Java, so I ask a question about one particular thing that as I hope can help me get started.
I have editor implemented on top of swing and i have some text in there. There is for example:
import java.util.List;
Now I need a way to send "java.util.List" string to a method that returns me all the information I may need including JavaDoc document.
So is there any tool that can set up classpath with libraries, that would parse every string I send and try to find if there is any Class/Interface with documentation to return?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,不。没有这样的独立工具或库。您需要自己实施它。 (不要指望编写 Java IDE 很简单……甚至是一个“玩具”IDE。)
AFAIK, no. There is no such free-standing tool or library. You will need to implement it yourself. (Don't expect that writing a Java IDE is simple ... even a "toy" one.)
库将有类文件,而不会有javadocs..所以不清楚你想做什么。
有许多字节码工程工具可以从类文件中分析和提取信息。例如 asm 或 bcel。 Javassist 允许处理源代码和字节代码,因此可能是接近你所需要的。
Libraries will have class files, which will not have javadocs.. So it is not clear what you want to do.
There are many byte code engineering tools to analyse and extract information from class files. For example asm or bcel. Javassist allows to process both source and byte code, so may be close to what you need.
您可以使用 html 解析器 使用类的完整路径从网络获取 javadoc 和其他信息(包括包名称以构造每个类的正确 URL)。这当然取决于您使用的 java 版本。
您还可以使用 java 中的 javadoc 工具从 java 源文件(可以从 Web 下载)生成所需的文档。该工具的源代码也可以帮助您。请参阅 http://java.sun.com/j2se/javadoc/faq/#developingwithjavadoc
最后,如果您需要基于程序中运行时类型的信息,您可能需要检查反射能力。
You could use html parser to get the javadoc and other info from the web using the full path to the class (including package names to construct the correct URL per class). This will of course depend on the version of java you are using.
You can also use the
javadoc
tool from within java to generate the desired documentation from java source files (which can be downloaded from the web). The source code of the tool could also help you out. See http://java.sun.com/j2se/javadoc/faq/#developingwithjavadocLastly, if you need information based on runtime types in your program, you might want to check reflection capabilities.
首先你需要知道如何打印导入的java库? 。然后下载 java API 文档 此处。找到导入的库后,打开 inputStream 以读取适当的 HTML 文件。
当心!此技术仅在从 jdk 导入时才有效。
First you need to know How to print imported java libraries?. Then download java API documentation here. Once you find out imported libraries, open an inputStream in order to read appropriate HTML file.
Beware! This technic will only work when importing from jdk.