【问题标题】:Eclipse Plugin Dev: How do I get the paths for the currently selected project?Eclipse Plugin Dev:如何获取当前选定项目的路径?
【发布时间】:2010-09-07 10:50:37
【问题描述】:

我正在编写一个插件来解析项目中的一堆文件。但目前我一直在通过 Eclipse API 寻找答案。

插件的工作原理是这样的:每当我打开一个源文件时,我都会让插件解析源对应的构建文件(这可以通过缓存解析结果来进一步开发)。获取文件很简单:

public void showSelection(IWorkbenchPart sourcePart) {
    // Gets the currently selected file from the editor
    IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor()
        .getEditorInput().getAdapter(IFile.class);
    if (file != null) {
        String path = file.getProjectRelativePath();
        /** Snipped out: Rip out the source path part
         * and replace with build path
         * Then parse it. */
    }
}

我的问题是我必须使用硬编码字符串作为源文件和构建文件所在的路径。任何人都知道如何从 Eclipse 中检索构建路径? (顺便说一句,我在 CDT 工作)。还有一种简单的方法可以确定源文件的源路径是什么(例如,一个文件在“src”目录下)?

【问题讨论】:

    标签: java eclipse eclipse-api


    【解决方案1】:

    你应该看看ICProject,尤其是getOutputEntries 和getAllSourceRoots 操作。 This tutorial 也有一些简短的例子。我与 JDT 一起工作,所以这几乎是我能做的。希望对你有帮助:)

    【讨论】:

    • 教程链接好像坏了:(
    • 教程链接失效
    猜你喜欢
    • 2011-10-17
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    相关资源
    最近更新 更多