Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a reference to the current project in an Eclipse plugin?

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.

like image 470
Martin Doms Avatar asked Dec 08 '25 15:12

Martin Doms


1 Answers

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();

like image 50
Zoltán Ujhelyi Avatar answered Dec 10 '25 05:12

Zoltán Ujhelyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!