Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Getting IResource from IDocument
Getting IResource from IDocument [message #255328] Thu, 24 June 2004 10:59 Go to next message
Eclipse UserFriend
Originally posted by: samanddimah.mail.com

How can the IResource for an IDocument be determined? I have implemnted an
instance of ITokenScanner and what to mark problems (via the createMarker
method on IResource) in the text as the user types rather than when they
save and the incremental build process runs.
Re: Getting IResource from IDocument [message #255370 is a reply to message #255328] Thu, 24 June 2004 12:56 Go to previous message
Eclipse UserFriend
Originally posted by: smesh.openrules.com

Sam wrote:
> How can the IResource for an IDocument be determined? I have implemnted an
> instance of ITokenScanner and what to mark problems (via the createMarker
> method on IResource) in the text as the user types rather than when they
> save and the incremental build process runs.

Hope, the following (mine:) code snippet will help.

> /**
> * Returns IResource associated with this adaptable.
> */
> public IResource getResourceAdapter(IAdaptable adaptable)
> {
> if (adaptable instanceof IJavaElement)
> {
> try
> {
> return ((IJavaElement) adaptable).getCorrespondingResource();
> }
> catch (Exception e)
> {
> handleException(e);
> return null;
> }
> }
>
> // IStorageEditorInput
> if (adaptable instanceof IStorageEditorInput)
> try
> {
> return getResourceAdapter(
> ((IStorageEditorInput) adaptable).getStorage());
> }
> catch (Exception e)
> {
> handleException(e);
> return null;
> }
>
> // IStorage
> if (adaptable instanceof IStorage)
> return findWorkspaceResource(((IStorage) adaptable).getFullPath());
>
> // IEditorPart
> if (adaptable instanceof IEditorPart)
> return getResourceAdapter(
> ((IEditorPart) adaptable).getEditorInput());
>
> // IFile for IAdaptable
> Object adapter = adaptable.getAdapter(IFile.class);
> // IResource for IAdaptable
> if (adapter == null)
> adapter = adaptable.getAdapter(IResource.class);
>
> if (!(adapter instanceof IResource))
> return null;
>
> IResource res = (IResource) adapter;
>
> return res;
> }
>
> /**
> * Returns resource associated with this something.
> * For example:
> * - IFile for editor
> * Example, most of IJavaElement's.
> */
> public IResource getResourceAdapter(Object something)
> {
> if (something instanceof IResource)
> return (IResource) something;
>
> if (something instanceof IAdaptable)
> return getResourceAdapter((IAdaptable) something);
>
> return null;
> }

--
Sam Mesh - http://openrules.com
Previous Topic:Are nested menus supported in Eclipse?
Next Topic:RC2: Problems at startup
Goto Forum:
  


Current Time: Tue May 27 15:38:29 EDT 2025

Powered by FUDForum. Page generated in 0.02880 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top