How to programmatically find a java file in eclipse from full classname?

后端 未结 3 1543
温柔的废话
温柔的废话 2020-12-19 18:22

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?

3条回答
  •  一个人的身影
    2020-12-19 19:01

    You also need to know the source folder.

    IProject prj = ResourcePlugin.getWorkspace().getRoot().getProject("project-name");
    IFile theFile = prj.getFile(sourceFolder + packageName.replace('.','/') + className + ".java");
    

    Generally you specify the file for an editor with an IFile. You can also ask an IFile for variants of the file's path.

提交回复
热议问题