gpt4 book ai didi

java - 如何访问 XText 中当前打开文件的位置

转载 作者:行者123 更新时间:2023-12-01 13:19:23 27 4
gpt4 key购买 nike

我应该读取当前打开的 DSL 文件来创建自动填充功能。为此,我应该以编程方式找到文件的位置,然后读取它。然而,为此目的似乎没有其他选择。如果我使用 Eclipse 插件方法,则会收到以下错误 java.lang.ClassCastException: org.eclipse.xtext.xbase.ui.editor.XbaseEditor 无法转换为 org.eclipse.core.resources.IFile请帮忙

最佳答案

确定任何编辑器正在编辑的文件的标准方法是:

IEditorPart editor = get the editor

IEditorInput editorInput = editor.getEditorInput();

if (editorInput instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput)editorInput).getFile();

// TODO handle file
}

关于java - 如何访问 XText 中当前打开文件的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22165574/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com