* (K_SOURCE or K_BINARY), and deletes the corresponding folder if it is then
* empty.
*/
private void deletePackageFragment(IPackageFragment frag)
throws JavaModelException {
IResource res = frag.getResource();
if (res != null) {
// collect the children to remove
IJavaElement[] childrenOfInterest = frag.getChildren();
if (childrenOfInterest.length > 0) {
IResource[] resources = new IResource[childrenOfInterest.length];
// remove the children
for (int i = 0; i < childrenOfInterest.length; i++) {
resources[i] = childrenOfInterest[i].getCorrespondingResource();
}
deleteResources(resources, force);
}
// Discard non-java resources
Object[] nonJavaResources = frag.getNonJavaResources();
int actualResourceCount = 0;
for (int i = 0, max = nonJavaResources.length; i < max; i++){
if (nonJavaResources[i] instanceof IResource) actualResourceCount++;
}
IResource[] actualNonJavaResources = new IResource[actualResourceCount];
for (int i = 0, max = nonJavaResources.length, index = 0; i < max; i++){
if (nonJavaResources[i] instanceof IResource) actualNonJavaResources[index++] = (IResource)nonJavaResources[i];
}
deleteResources(actualNonJavaResources, force);
// delete remaining files in this package (.class file in the case where Proj=src=bin)
IResource[] remainingFiles;
try {
remainingFiles = ((IContainer) res).members();
} catch (CoreException ce) {
throw new JavaModelException(ce);
}
boolean isEmpty = true;
for (int i = 0, length = remainingFiles.length; i < length; i++) {
IResource file = remainingFiles[i];
if (file instanceof IFile && org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(file.getName())) {
this.deleteResource(file, IResource.FORCE | IResource.KEEP_HISTORY);
} else {
isEmpty = false;
}
}
if (isEmpty && !frag.isDefaultPackage()/*don't delete default package's folder: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38450*/) {
// delete recursively empty folders
IResource fragResource = frag.getResource();
if (fragResource != null) {
deleteEmptyPackageFragment(frag, false, fragResource.getParent());
}
}
}
}