getting an IFile from the java editor [message #151720] |
Fri, 31 October 2003 03:03  |
Eclipse User |
|
|
|
Originally posted by: dave_s42.hotmail.com
My situation is this: I need to parse the file currently open in the java
editor, for use elsewhere in my plugin. I have gotten to the point where
if I can get the IFile object representing the .java file I am editing, I
think everything will work. However, I have been unable to find out how
to get this IFile (or something equivilant). Does anyone have suggestions
about how I should go about this?
Thanks,
Dave
|
|
|
|
Re: getting an IFile from the java editor [message #152055 is a reply to message #151728] |
Sat, 01 November 2003 16:27   |
Eclipse User |
|
|
|
Originally posted by: dave_s42.hotmail.com
Tom Eicher wrote:
> Dave wrote:
> > My situation is this: I need to parse the file currently open in the java
> > editor, for use elsewhere in my plugin. I have gotten to the point where
> > if I can get the IFile object representing the .java file I am editing, I
> > think everything will work. However, I have been unable to find out how
> > to get this IFile (or something equivilant). Does anyone have suggestions
> > about how I should go about this?
> Assuming you have access to your IEditorParet ed.
> if (ed.getEditorInput() instanceof IFileEditorInput) {
> IFile file= ((IFileEditorInput) ed.getEditorInput()).getFile();
> }
> Note that you can also get access to the document being edited
> (including any unsaved changes in the document), you can do the
> following if your editor is an ITextEditor:
> IDocument doc= ed.getDocumentProvider().getDocument(ed.getEditorInput())
> -tom
OK, I get that much. However, I'm still having trouble getting hold of
the IEditorPart. The two possibilites I've found are:
BasicTextEditorActionContributor.getActiveEditorPart()
and
IWorkbenchPage.getActiveEditor()
The trouble is, I'm still not sure how to get a hold of the
BasicTextEditorActionContributor or IWorkbenchPage objects to do these
operations on.
I think part of my problem is that I'm still not really sure about how to
get at and use the Workspace, and all the related parts. I've looked
through the API and it doesn't seem to be much help. Any suggestions
about how I should proceed, or where to look for more information?
Thanks,
Dave
|
|
|
|
Re: getting an IFile from the java editor [message #152581 is a reply to message #151720] |
Mon, 03 November 2003 15:29  |
Eclipse User |
|
|
|
Originally posted by: eclipse.guide.removeMe.andMeToo.earthlink.net
Perhaps this is the wrong question but... why would you want to do all this
parsing yourself? The JDT provides a real handy parser and an underlying
model. My article, "Extend Eclipse's Java Development Tools"
( http://www-106.ibm.com/developerworks/opensource/library/os- ecjdt/) gives
you a flavor for what's possible (more detail in Chapter 26 of our book).
More directly to your question, you can get the editor's input
(IEditorInput) and from there its underlying IFile, source, compilation
unit, whatever.
I suggest you consider going the JDT route because the end result will
integrate much better. To give you just an example of what might be an
issue otherwise: Consider if the editor content is modified but not yet
saved to disk. If you go the IFile route, you'll be parsing a backlevel
copy of the code. The JDT handles all the in-memory and disk
synchronization. It's a lot to learn in one sitting but worth your time.
-- Dan
---------------------------------------
co-author "The Java Developer's Guide to Eclipse"
http://www-106.ibm.com/developerworks/opensource/library/os- ecjdt/
"Dave" <dave_s42@hotmail.com> wrote in message
news:bnt4vq$chj$1@eclipse.org...
> My situation is this: I need to parse the file currently open in the java
> editor, for use elsewhere in my plugin. I have gotten to the point where
> if I can get the IFile object representing the .java file I am editing, I
> think everything will work. However, I have been unable to find out how
> to get this IFile (or something equivilant). Does anyone have suggestions
> about how I should go about this?
>
> Thanks,
>
> Dave
>
|
|
|
Powered by
FUDForum. Page generated in 0.02824 seconds