我正在编写一个插件,它将解析项目中的一堆文件。但目前我一直在通过 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”目录下)?

有帮助吗?

解决方案

你应该看看 集成电路项目, ,尤其是 getOutputEntries 和 getAllSourceRoots 操作。 本教程 也有一些简短的例子。我与 JDT 合作,所以这就是我能做的。希望能帮助到你 :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top