简体   繁体   English

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

[英]How to access the location of a currently open file in XText

I am supposed to read the currently open DSL File to create an Auto Populate Feature. 我应该阅读当前打开的DSL文件以创建自动填充功能。 For that I am supposed to find the location of the file programmatically and then read it. 为此,我应该以编程方式找到文件的位置,然后读取它。 However there seems to be no alternatives for this purpose. 但是,似乎没有其他选择可用于此目的。 If I use Eclipse Plugin Methods, I get the following error java.lang.ClassCastException: org.eclipse.xtext.xbase.ui.editor.XbaseEditor cannot be cast to org.eclipse.core.resources.IFile Please Help 如果我使用Eclipse插件方法, java.lang.ClassCastException: org.eclipse.xtext.xbase.ui.editor.XbaseEditor cannot be cast to org.eclipse.core.resources.IFile出现以下错误java.lang.ClassCastException: org.eclipse.xtext.xbase.ui.editor.XbaseEditor cannot be cast to org.eclipse.core.resources.IFile请帮助

The standard way to determine the file that any editor is editing is: 确定任何编辑器正在编辑的文件的标准方法是:

IEditorPart editor = get the editor

IEditorInput editorInput = editor.getEditorInput();

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

   // TODO handle file
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM