3

I'm creating an editor for Eclipse. Right now the editor fires up with the user creates a new file with the appropriate extension. My question is, how can I get a reference to the project in which the file resides? For example, say I have a workspace with 2 projects, P1 and P2. I right click P2 and create a new file, can I get a reference to P2 from this somehow?

Ultimately I need to reference the AST or Java Model of the project but even a String identifying the project would work.

oberlies
  • 11,503
  • 4
  • 63
  • 110
Martin Doms
  • 8,598
  • 11
  • 43
  • 60
  • does http://stackoverflow.com/questions/1206095/how-to-get-the-project-name-in-eclipse help? – VonC Apr 15 '10 at 04:22

1 Answers1

5

I think, the answer is simply IFile.getProject() would work...

If you work with a FileEditorInput in the init() method, you could use the following code to obtain the searched project resource:

FileEditorInput fileInput = (FileEditorInput) input; fileInput.getFile().getProject();

Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37