【发布时间】: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