Re: setting package on new Java objects

Svata Dedic <[email protected]> 05 Aug 2003 07:49:32 +0200
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Message-ID <[email protected]>
On Tue, 2003-08-05 at 01:48, Peter Wisnovsky wrote:
> I have a wizard in which I create some Java files. It used to be that
> the package could be computed easily from the path to the root of the
> mountpoint. Now the path I get is relative to the root. So I end up
> with files with package declarations like
> 
> package /home/pswisnov/Projects/webmod/src/ws;
> 
> I'm trying to figure out if there is an encapsulated way to do
> this. There seems to be an implementation in JavaWizardData.setTarget
> which I can copy over, but is there or could there be an entry point
> provided by the Java module for computing the package name from a
> project member? 
> 
Assuming the ProjectMember is one that describes a java source file for
the project (== the ProjectMember is contained within some java source
descriptor), you could use:
	ProjectPath.find(theProjectMember, ProjectPath.PATH_SOURCE)
to get the source path effective for the file, then you can do:
	ClassPath.getResourceName(theProjectMember.getOriginal().getParent(),
'.', false)
to get the file's parent folder translated to a package name.

There's an abstraction of JavaPackage and JavaResource, which produce
resource/package names and manage folder contents merging/hiding inside
Java module, but I was not sure whether that could be an usable API at
the time of writing.

-Svata