views:

1366

answers:

1

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.

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?

+2  A: 

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 :)

Marcio Aguiar
tutorial link seems to be broken :(
Adrian Mouat