Eclipse 插件:如何将 "java. lang. string" 转换为 IEditorInput?

Eclipse Plugin : How to convert "java. lang. string" into IEditorInput?

Eclipse 插件

我要小编打开一个源码。我只有一个字符串(java.lang.String)。我该怎么做?

如果您的意思是要打开 java.lang.String class 的 class 文件编辑器(如果可以找到,它将打开源代码)。你会做这样的事情:

IProject project = ... java project you are interested in

// Get the JavaModel project
IJavaProject javaProject = JavaCore.create(project);

// Find the String type using the classpath defined in the project
IType stringType = javaProject.findType("java.lang.String");

// Find the class file
IJavaElement classFile = stringType.getAncestor(IJavaElement.CLASS_FILE);

// Open the editor
JavaUI.openInEditor(classFile);