如何以编程方式从完整的类名中找到 eclipse 中的 java 文件?

在 Eclipse 插件中,我想在编辑器中打开一个文件.我知道完整的包和类名,如何从中确定java文件的路径?

Inside an eclipse plugin, I'd like to open a file in editor. I know the full package and class name, how can I determine the path of the java file from this?

推荐答案

看看IJavaProject.findType(name)方法.一旦有了 IType,就可以使用 getPath() 或 getResource() 方法来定位文件.此方法搜索整个项目以及该项目中可见的所有内容.要搜索整个工作区,请遍历工作区中的所有 Java 项目,依次调用每个项目的 findType() 方法.

Take a look at IJavaProject.findType( name ) method. Once you have an IType, you can use getPath() or getResource() methods to locate the file. This method searches across a project and everything visible from that project. To search the whole workspace, iterate through all the Java projects in the workspace, calling the findType() method on each in turn.

相关文章