Re: setting package on new Java objects

Cliff Draper <[email protected]> Wed, 20 Aug 2003 10:15:28 -0700 (PDT)
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Message-ID <[email protected]>
From: Tomas Zezula <[email protected]>
Date: Wed, 20 Aug 2003 09:06:39 +0200
> Hi Cliff,
> if the packageObject is a FileObject or its getPackageNameExt method
> delegates on the FileObject.getPackageNameExt () the problem is in it.
> The FO.getPackageNameExt method is deprecated and can not be used in the
> NB 4.0. It supposes that the root of a FileSystem is a root of a Java
> ClassPath entry. You have to use the ClassPath to obtain the correct
> package name.

Yes, packageObject is a FileObject.  Okay, so it looks like the
following is the correct way:

        FileObject packageObject = ...
        ProjectMember javaObject = ...
        ClassPath cp = ProjectPath.find(javaObject, ProjectPath.PATH_SOURCE);
        sourceElement.setPackage(Identifier.create(cp.getResourceName(packageObject)));

thanks,
Cliff Draper    Sun Microsystems, Forte Tools
My opinions may or may not reflect those of my employer.
---------------------------- food for thought ---------------------------
Smart bombs have bad days too.