繁体   English   中英

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

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

我应该阅读当前打开的DSL文件以创建自动填充功能。 为此,我应该以编程方式找到文件的位置,然后读取它。 但是,似乎没有其他选择可用于此目的。 如果我使用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请帮助

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

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