Home > Software design >  Eclipse Plugin : How to convert "java. lang. string" into IEditorInput?
Eclipse Plugin : How to convert "java. lang. string" into IEditorInput?

Time:11-15

Eclipse Plugin

I want the editor to open a source code. I only have one string(java.lang.String). How do I do that?

CodePudding user response:

If you mean you want to open the class file editor for the java.lang.String class (which will open the source if it can be found). You would do something like:

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);
  • Related