Re: getting to ProjectMember from SourceElement

Svata Dedic <[email protected]> Thu, 31 Jul 2003 06:22:36 +0200
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Message-ID <[email protected]>
Peter Wisnovsky wrote:
> I have a class constructed built off a source element. I find I need
> access to the project I'm in for various API calls. I used to access
> the public class from the source element, then do:
> 
>             Repository repository = Repository.getDefault();
>             String fileName = classElement.getName().getFullName().replace('.', '/') + ".java";
>             FileObject fileObject = repository.findResource(fileName);
>             if (fileObject == null)
>             {
>                 throw new FileStateInvalidException(fileName);
>             }
>                 
>             ProjectMember dataObject = ProjectMember.find(fileObject);
> 
If you really need to find the Project from a file, use findAll, *not* 
find. *Do read* documentation for ProjectMember.find(), Project.find() 
and Project.getProjectMember(). According to Project.find(), this call 
*can not* work, since Project.find() and ProjectMember.find() are 
designed to do a completely other thing.
There's even a warning that find should NOT be used in just your use 
case. in Project.find() javadoc (linked into ProjectMember.find() javadoc).

-Svata