2011-06-16 61 views
4

我想用一個打印當前項目名稱的命令做一個小插件。該代碼片段是以下:Eclipse包中缺少類,幫助

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); 

    IEditorPart editorPart = window.getActivePage().getActiveEditor(); 
    if (editorPart != null){ 
     IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ; 
     IFile file = input.getFile(); 
     IProject activeProject = file.getProject(); 
     String activeProjectName = activeProject.getName(); 
     //... use activeProjectName 
    } 

問題:IFileEditorInput無法找到(錯誤味精:不能解析爲一個類型)。我有導入org.eclipse.ui。*;在文件的頂部,但它不起作用。似乎IFileEditorInput丟失,但我怎麼能找到它?

非常感謝!

回答

9

您需要添加對org.eclipse.ui.ide插件的依賴關係。 IFileEditorInput生活在org.eclipse.ui,但不是插件的同名,這是混淆。您還可以通過使用程序包依賴關係而不是明確依賴某些插件來避免此類混淆。

+0

完全正確。 – xiaolong 2011-06-16 22:12:15