/** Adds all of the openables defined within this package fragment root to the list. */ private void injectAllOpenablesForPackageFragmentRoot( IPackageFragmentRoot root, ArrayList openables) { try { IJavaScriptElement[] packFrags = root.getChildren(); for (int k = 0; k < packFrags.length; k++) { IPackageFragment packFrag = (IPackageFragment) packFrags[k]; injectAllOpenablesForPackageFragment(packFrag, openables); } } catch (JavaScriptModelException e) { return; } }
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; } }
protected Object[] getPackageFragmentRoots(IJavaScriptProject project) throws JavaScriptModelException { if (!project.getProject().isOpen()) return NO_CHILDREN; IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); List list = new ArrayList(roots.length); // filter out package fragments that correspond to projects and // replace them with the package fragments directly for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; if (!root.isExternal()) { Object[] children = root.getChildren(); for (int k = 0; k < children.length; k++) list.add(children[k]); } else if (hasChildren(root)) { list.add(root); } } return concatenate(list.toArray(), project.getNonJavaScriptResources()); }