Eclipse 插件开发:如何获取当前所选项目的路径?
-
09-06-2019 - |
题
我正在编写一个插件,它将解析项目中的一堆文件。但目前我一直在通过 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”目录下)?
不隶属于 StackOverflow