When writing Java code on Eclipse IDE, press Control + Space will pop up the content assist window.
For example, the content assist window for System.
will list all the available fields and methods for class System.
我需要通过代码访问内容辅助窗口的“数据模型”。
使用上面的例子,它是:给定类名System
,如何检索所有可用的字段和方法?
我在grepcode.com上花了一些时间研究这三个类的源代码:
org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext
org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer
org.eclipse.jdt.ui.text.java.CompletionProposalCollector
它看起来像一个ICompilationUnit
实例用于提供字段和方法名称。
然后我不明白如何生成ICompilationUnit
jre系统库或第三方库中的类的实例?或者如果我没有以正确的方式阅读代码,那么程序是如何找到字段和方法名称的? (我不需要担心偏移和 UI 的问题,只需担心“数据模型”部分)。
似乎唯一的选择是创建一个(临时)编译单元,这又需要正确设置 Java 项目。这基础设施JDT 有必要知道使用了哪个 JRE、使用了哪些编译器设置等。
See here http://www.programcreek.com/2011/05/eclipse-jdt-tutorial-java-model/如何设置 Java 项目,以及here https://stackoverflow.com/questions/11166862/eclipse-create-compilationunit-from-java-file如何获得编译单元。
编译单元看起来像
class Foo {
void bar() {
java.lang.System.
}
}
and codeComplete()
必须用一个偏移量来调用,该偏移量表示紧随其后的位置System.
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)