Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » get subpackages from IPackageFragment
get subpackages from IPackageFragment [message #157311] Wed, 05 May 2004 11:16 Go to next message
Eclipse UserFriend
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 16:13 Go to previous messageGo to next message
Eclipse UserFriend
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 14:59 Go to previous message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
/**
*
* @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();
Previous Topic:WTK22 JAD problem
Next Topic:Creating a project programmatically
Goto Forum:
  


Current Time: Fri Dec 27 01:53:13 GMT 2024

Powered by FUDForum. Page generated in 0.03203 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top