【问题标题】:Eclipse Plugin : How to convert "java. lang. string" into IEditorInput?Eclipse 插件:如何将“java.lang.string”转换为 IEditorInput?
【发布时间】:2021-12-25 02:05:12
【问题描述】:

Eclipse 插件

我希望编辑器打开源代码。我只有一个字符串(java.lang.String)。我该怎么做?

【问题讨论】:

  • 您需要使用IStorageEditorInput。字符串没有标准实现 - 但有一个示例 here
  • 我想让编辑器打开 java.lang.朗。字符串源代码文件,而不是自定义字符串
  • 就像点击控制台中的 StackTraceElement 链接

标签: eclipse plugins


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-02-05
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多