I'm writing a plugin that will parse a bunch of files in a project. But for the moment I'm stuck searching through the Eclipse API for answers.
我正在编写一个插件来解析项目中的一堆文件。但就目前而言,我一直在寻找Eclipse API寻找答案。
The plugin works like this: Whenever I open a source file I let the plugin parse the source's corresponding build file (this could be further developed with caching the parse result). Getting the file is simple enough:
插件的工作方式如下:每当我打开源文件时,我都会让插件解析源代码的相应构建文件(这可以通过缓存解析结果进一步开发)。获取文件很简单:
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. */
}
}
The problem I have is I have to use hard coded strings for the paths where the source files and build files go. Anyone know how to retrieve the build path from Eclipse? (I'm working in CDT by the way). Also is there a simple way to determine what the source path is (e.g. one file is under the "src" directory) of a source file?
我遇到的问题是我必须使用硬编码字符串作为源文件和构建文件的路径。任何人都知道如何从Eclipse中检索构建路径? (顺便说一下,我在CDT工作)。还有一种简单的方法来确定源文件的源路径是什么(例如,一个文件位于“src”目录下)?
1 个解决方案
#1
1
You should take a look at ICProject, especially the getOutputEntries and getAllSourceRoots operations. This tutorial has some brief examples too. I work with JDT so thats pretty much what I can do. Hope it helps :)
您应该查看ICProject,尤其是getOutputEntries和getAllSourceRoots操作。本教程也有一些简短的例子。我和JDT一起工作,这几乎就是我能做的。希望能帮助到你 :)
#1
1
You should take a look at ICProject, especially the getOutputEntries and getAllSourceRoots operations. This tutorial has some brief examples too. I work with JDT so thats pretty much what I can do. Hope it helps :)
您应该查看ICProject,尤其是getOutputEntries和getAllSourceRoots操作。本教程也有一些简短的例子。我和JDT一起工作,这几乎就是我能做的。希望能帮助到你 :)