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 Object[] getPackageContents(IPackageFragment fragment) throws JavaScriptModelException {
    ISourceReference[] sourceRefs;
    if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
      sourceRefs = fragment.getJavaScriptUnits();
    } else {
      IClassFile[] classFiles = fragment.getClassFiles();
      List topLevelClassFile = new ArrayList();
      for (int i = 0; i < classFiles.length; i++) {
        IType type = classFiles[i].getType();
        if (type != null
            && type.getDeclaringType() == null
            && !type.isAnonymous()
            && !type.isLocal()) topLevelClassFile.add(classFiles[i]);
      }
      sourceRefs =
          (ISourceReference[])
              topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]);
    }

    Object[] result = new Object[0];
    for (int i = 0; i < sourceRefs.length; i++)
      result = concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i])));
    return concatenate(result, fragment.getNonJavaScriptResources());
  }