[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.jdt] Re: Getting all packages from a IJavaProject

Hi Guy
I am not the definitive JDT expert !
The code above contains my solution, hope it helps you


/**
* Get all the compilation unit corresponding to Java resources in
* the current Java project. * That means classes and interfaces (.java)
* @return
*/
public Vector<ICompilationUnit> getUnitsOfInterest() {
IPackageFragmentRoot[] ipfr;
Vector<ICompilationUnit> icu = new Vector<ICompilationUnit>();
try {
// acces the package root for Java resources
ipfr = javaProject.getAllPackageFragmentRoots();
for (int i = 0; i < ipfr.length; i++) {
// select internal resources
if (!ipfr[i].isExternal()) {
// get the inner packages
IJavaElement [] ije = ipfr[i].getChildren();
for (int j = 0; j < ije.length; j++) {
// cast needed here IPackageFragment pf = (IPackageFragment) ije[j];
// if there are Java resources inside
if (pf.containsJavaResources()) {
// search for compilation unit
ICompilationUnit [] tmp = pf.getCompilationUnits();
for (int k = 0; k < tmp.length; k++) {
ICompilationUnit cu = tmp[k];
icu.add(cu);
}
}
}
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
return icu;
}