get subpackages from IPackageFragment [message #157311] |
Wed, 05 May 2004 07:16  |
Eclipse User |
|
|
|
Originally posted by: jochen.kressin.artnolgoy.com
Hi,
how is it possible to get all subpackages from an IPackageFragment? As far as I
can see the method getChildren() only returns ICompilationUnits and IClassFiles
and I cannot find something like getSubpackes() (despite of the existance of the
method hasSubpackes). I am using Eclipse 3.0, Milestone 8.
Thanks,
Jochen
|
|
|
Re: get subpackages from IPackageFragment [message #171816 is a reply to message #157311] |
Wed, 04 August 2004 12:13   |
Eclipse User |
|
|
|
Originally posted by: daniel.megert.gmx.net
Jochen Kressin wrote:
> Hi,
>
> how is it possible to get all subpackages from an IPackageFragment?
You cannot since Java has no concept of sub-packages. You can get the
package fragment root via getParent() and then its children using
getChildren().
Dani
> As far as I can see the method getChildren() only returns
> ICompilationUnits and IClassFiles and I cannot find something like
> getSubpackes() (despite of the existance of the method hasSubpackes).
> I am using Eclipse 3.0, Milestone 8.
>
> Thanks,
>
> Jochen
|
|
|
Re: get subpackages from IPackageFragment [message #189517 is a reply to message #171816] |
Mon, 13 December 2004 09:59  |
Eclipse User |
|
|
|
/**
*
* @return List[PackageFragment]
*/
private static List getSubPackages(IPackageFragment p) throws Exception
{
List result = new ArrayList();
IJavaElement[] packages= ((IPackageFragmentRoot)p.getParent()).getChildren();
String[] names =((PackageFragment)p).names;
int namesLength = names.length;
newPackage: for (int i= 0, length = packages.length; i < length; i++)
{
String[] otherNames = ((PackageFragment) packages[i]).names;
if (otherNames.length <= namesLength)
continue;
for (int j = 0; j < namesLength; j++)
{
if (!names[j].equals(otherNames[j]))
continue newPackage;
}
result.add(packages[i]);
System.out.println("Subpackage found:"+packages[i].getElementName());
}
return result;
}
Greetings
Andreas
Note: The most of the code is 'ripped' from PackageFragment.hasSubpackages();
|
|
|
Powered by
FUDForum. Page generated in 0.03317 seconds