Re: getting to ProjectMember from SourceElement

Peter Wisnovsky <[email protected]> Wed, 30 Jul 2003 22:09:04 -0700
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Message-ID <[email protected]>
Svata Dedic writes:
 > 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.

Thanks, I'll try this! 

I do notice that in the Project.find docs it says that if you pass a
file object, "if FileObject lies on filesystem of some project then
this project is returned, otherwise it returns null"; moreover that
projectmember.find is equivelent to using this. I inferred from this
that since the file lives in a project that it would locate the
file. Are there different kinds of fileobjects in the system that
differ based on how they are extracted?

Thanks,

Peter