Bug 31174 - [resources] IWorkspaceRoot API clarification (if none?)
Summary: [resources] IWorkspaceRoot API clarification (if none?)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 2.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.1 RC1   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2003-02-06 17:21 EST by Jared Burns CLA
Modified: 2003-02-11 16:59 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 Jared Burns CLA 2003-02-06 17:21:58 EST
The API for IWorkspaceRoot#getFileForLocation(IPath) is unclear about the
nature of the returned IFile. Specifically, it is hard to tell from the API
if the returned file is guaranteed to exist and when null can be returned.

The first sentence ends with "or null if none". It would be helpful to
clarify exactly what "if none" means. Does it mean "if no file exists at the
given path"? This interpretation doesn't seem correct in light of the third
sentence, but the reader isn't given any clues about what else might cause a
null value to be returned. What does a null return value mean?

/**
 * Returns a handle to the file which is mapped to the given path 
 * in the local file system, or <code>null</code> if none.
 * The path must be absolute; its segments need not be valid names.
 * The resulting file need not exist in the workspace.
 * <p>
 * Warning: This method ignores linked resources and their children.  Since
 * linked resources may overlap other resources, a unique mapping from a
 * file system location to a single resource is not guaranteed.  To find all 
 * resources for a given location, including linked resources, use the method
 * <code>findFilesForLocation</code>.
 * </p>
 *
 * @param location a path in the local file system
 * @return the corresponding file in the workspace,
 *    or <code>null</code> if none
 */
public IFile getFileForLocation(IPath location);
Comment 1 John Arthorne CLA 2003-02-11 14:09:54 EST
Would it be sufficient clarification to add the following sentence?

 * This method returns null when the given file system location is not under
 * the location of any existing project in the workspace.
Comment 2 Jared Burns CLA 2003-02-11 14:43:53 EST
The main point of confusion here (for me, at least) is the difference between
the method returning null and the method returning a handle to a file that
doesn't exist.

Based on your addition, I can guess that the first sentence means:
"Returns a handle to the file which is mapped to the given path in the local
file system, or <code>null</code> if the given path does not map to a project
within the workspace."

So if you have a workspace with projects Foo and Bar, a path that starts
with Foo or Bar will always return a file (though it might not exist), but
a path starting with Baz would return null?
Comment 3 John Arthorne CLA 2003-02-11 15:56:00 EST
That's correct.  If your workspace contains two projects at c:\ws\Foo and
c:\ws\Bar, then getFileForLocation will have the following behaviour:

c:\ws\Fred -> null
c:\ws\Fred\abc.txt -> null
d:\elsewhere -> null
c:\ws\Foo -> null
c:\ws\Foo\abc.txt -> IFile with path /Foo/abc.txt

Comment 4 John Arthorne CLA 2003-02-11 16:59:08 EST
Released clarified API javadoc