Java 插件中获得当前编辑文本的绝对路径

弄了好几天,终于弄出来了。为了实现根据import递归扫描文本,必须获得绝对路径。

IEditorPart editor = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput input = editor.getEditorInput(); 
    if (input instanceof IFileEditorInput) 
    { 
        IFile file = ((IFileEditorInput)input).getFile(); 
     String filepath = ((IFile)file).getLocation().makeAbsolute().toFile().getAbsolutePath();
                    System.out.println("BBBBBBBBBBBBBBBBB   "+filepath);
    }

放在对键盘的响应中,当敲击键盘时获得当前编辑文档的绝对路径。

原文地址:https://www.cnblogs.com/wangjiyuan/p/add.html