在 Eclipse JDT 中,如何最有效地在工作区中找到与完全限定名称相对应的类型根?
JavaCore 类包含一个 create 方法,该方法允许我在给定体现文件位置的句柄标识符的情况下获取 ITypeRoot(类文件或编译单元的表示形式)。
但是,我试图找到与特定全名相对应的类型根(如果有的话)。
我能想到的唯一实现是扫描系统中的所有类型,获取每个类型的类型根(甚至不知道如何做到这一点),然后比较 FQN。
任何帮助,将不胜感激。
The JavaCore class includes a create method that allows me to get the ITypeRoot (representation of class file or compilation unit) given a handle identifier that embodies the location of the file.
However, I am trying to find the typeroot (if there is one) that corresponds to a specific fullname.
The only implementation that I can think of is to scan all the types in the system, get the type root on each of them (not even sure how to do that), and then compare FQNs.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 JavaCore 单例中,尝试:
一旦有了层次结构,您就可以非常轻松地以 IType 形式遍历类文件层次结构。
From the JavaCore singleton, try:
Once you have the hierarchy, you can traverse class file hierarchies as ITypes pretty easily.
我假设您有一个
IJavaProject
参考。 如果没有,那么您将必须遍历工作区中的所有项目,因为 IType 会根据您所在的项目而有所不同,即使它们具有相同的限定名称。您可以执行以下操作:
注意:
findType
可能返回 null,因此需要进行检查findType
方法的此变体假定类型是顶级类型,并且不是内部或非公开类型。 如果您需要检查这些,则必须使用以下变体:IType findType(String fullQualifiedName, IProgressMonitor ProgressMonitor)
I am assuming that you have an
IJavaProject
reference. If not, then you will have to traverse all projects in the workspace since ITypes are different depending on which project you are in even if they have the same qualified name.You could do something like this:
Caveats:
findType
may return null, so need to have a check for thatfindType
method assumes the type is top-level and not an inner or non-public type. If you need to check for these, then you must use this variant:IType findType(String fullyQualifiedName, IProgressMonitor progressMonitor)