private static boolean hasReadOnlyResourcesAndSubResources(IJavaScriptElement javaElement)
      throws CoreException {
    switch (javaElement.getElementType()) {
      case IJavaScriptElement.CLASS_FILE:
        // if this assert fails, it means that a precondition is missing
        Assert.isTrue(((IClassFile) javaElement).getResource() instanceof IFile);
        // fall thru
      case IJavaScriptElement.JAVASCRIPT_UNIT:
        IResource resource = ReorgUtils.getResource(javaElement);
        return (resource != null && Resources.isReadOnly(resource));
      case IJavaScriptElement.PACKAGE_FRAGMENT:
        IResource packResource = ReorgUtils.getResource(javaElement);
        if (packResource == null) return false;
        IPackageFragment pack = (IPackageFragment) javaElement;
        if (Resources.isReadOnly(packResource)) return true;
        Object[] nonJava = pack.getNonJavaScriptResources();
        for (int i = 0; i < nonJava.length; i++) {
          Object object = nonJava[i];
          if (object instanceof IResource
              && hasReadOnlyResourcesAndSubResources((IResource) object)) return true;
        }
        return hasReadOnlyResourcesAndSubResources(pack.getChildren());
      case IJavaScriptElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot root = (IPackageFragmentRoot) javaElement;
        if (root.isArchive()) return false;
        IResource pfrResource = ReorgUtils.getResource(javaElement);
        if (pfrResource == null) return false;
        if (Resources.isReadOnly(pfrResource)) return true;
        Object[] nonJava1 = root.getNonJavaScriptResources();
        for (int i = 0; i < nonJava1.length; i++) {
          Object object = nonJava1[i];
          if (object instanceof IResource
              && hasReadOnlyResourcesAndSubResources((IResource) object)) return true;
        }
        return hasReadOnlyResourcesAndSubResources(root.getChildren());

      case IJavaScriptElement.FIELD:
      case IJavaScriptElement.IMPORT_CONTAINER:
      case IJavaScriptElement.IMPORT_DECLARATION:
      case IJavaScriptElement.INITIALIZER:
      case IJavaScriptElement.METHOD:
      case IJavaScriptElement.TYPE:
        return false;
      default:
        Assert.isTrue(false); // not handled here
        return false;
    }
  }
 private static boolean hasReadOnlyResourcesAndSubResources(IResource resource)
     throws CoreException {
   if (resource.isLinked()) // we don't want to count these because we never actually delete linked
     // resources
     return false;
   if (Resources.isReadOnly(resource)) return true;
   if (resource instanceof IContainer)
     return hasReadOnlyResourcesAndSubResources(((IContainer) resource).members());
   return false;
 }