Bug 125452 - [api] factory for an IResourceProxy
Summary: [api] factory for an IResourceProxy
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2006-01-27 06:09 EST by Martin Aeschlimann CLA
Modified: 2006-01-30 10:52 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2006-01-27 06:09:50 EST
20060127

Please offer an API to create a IResourceProxy from an IResource.

In the search plugin we use the IResourceProxy in a public API:
   TextSearchScope.contains(IResourceProxy proxy)
This is essential as we use a resource visitor and have to avoid resolving resources unless really needed. Hoever, the TextSearchScope also has its uses in other contexts where users only have an IFile and want to test it against the scope.
Adding a second API TextSearchScope.contains(IResource res) would mean code duplication in an implementation of a TextSearchScope.

A method IResource.getResourceProxy() would help to keep the code simple.
Comment 1 John Arthorne CLA 2006-01-27 11:30:12 EST
Sure, why not.
Comment 2 John Arthorne CLA 2006-01-27 11:45:25 EST
Released.  Note that when you create a proxy, you are obtaining a copy of the info about that resource.  The proxy will not get updated if the resource changes.

This could actually be useful to other clients as an optimization.  Every time you call an IResource method it has to do a lookup in the workspace tree. So, if you want several pieces of information, it's likely less expensive to create a proxy and then query its state instead. The client just has to realize that if the resource is modified concurrently, the proxy will become stale.
Comment 3 Martin Aeschlimann CLA 2006-01-27 12:02:39 EST
Great.
I found that the spec of IResourceProxy should be refined and the references to 'visit' should be generalized.

 * <p>
 * Note that a resource proxy is a transient object that is only valid for the
 * duration of a single visit method.  A proxy should not be referenced once the
 * single resource visit is complete. The equals and hashCode methods should not
 * be relied on.
 * </p>

I would change it the way to say that a resource proxy is a transient object and that clients should not hold a reference to it.

About your last comment in comment 2. The name of the class is IResourceProxy, so I wouldn't let it keep state, but really just be a proxy.
But as said as these elements are not to be kept in structures, and are therefore not long-lived, this doesn't really matter.
Comment 4 John Arthorne CLA 2006-01-30 10:52:33 EST
I have clarified the javadoc.  However, the behaviour of IResourceProxy during a visit is special so I still distinguish this in the doc.  During a visit, the same proxy object is reused, so it really cannot be referenced outside the visit method.  When IResource#createProxy is used, there is no context that we can define in which the proxy is valid.