簡體   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