Java 如何在XText中访问当前打开的文件的位置

Java 如何在XText中访问当前打开的文件的位置,java,eclipse,xtext,Java,Eclipse,Xtext,我应该读取当前打开的DSL文件来创建一个自动填充功能。为此,我应该以编程方式找到文件的位置,然后读取它。然而,在这方面似乎没有其他选择。如果我使用Eclipse插件方法,我会得到以下错误java.lang.ClassCastException:org.Eclipse.xtext.xbase.ui.editor.XbaseEditor无法转换为org.Eclipse.core.resources.IFile 请帮助确定任何编辑器正在编辑的文件的标准方法是: IEditorPart editor =

我应该读取当前打开的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
 }