protected Object internalGetParent(Object element) { // since we insert logical package containers we have to fix // up the parent for package fragment roots so that they refer // to the container and containers refere to the project // if (element instanceof ISourceFolderRoot) { ISourceFolderRoot root = (ISourceFolderRoot) element; IRubyProject project = root.getRubyProject(); try { ILoadpathEntry[] entries = project.getRawLoadpath(); for (int i = 0; i < entries.length; i++) { ILoadpathEntry entry = entries[i]; if (entry.getEntryKind() == ILoadpathEntry.CPE_CONTAINER) { if (LoadPathContainer.contains(project, entry, root)) return new LoadPathContainer(project, entry); } } } catch (RubyModelException e) { // fall through } } if (element instanceof LoadPathContainer) { return ((LoadPathContainer) element).getRubyProject(); } return super.internalGetParent(element); }
private Object[] rootsAndContainers(IRubyProject project, Object[] roots) throws RubyModelException { List result = new ArrayList(roots.length); Set containers = new HashSet(roots.length); Set containedRoots = new HashSet(roots.length); ILoadpathEntry[] entries = project.getRawLoadpath(); for (int i = 0; i < entries.length; i++) { ILoadpathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == ILoadpathEntry.CPE_CONTAINER) { ISourceFolderRoot[] roots1 = project.findSourceFolderRoots(entry); containedRoots.addAll(Arrays.asList(roots1)); containers.add(entry); } } for (int i = 0; i < roots.length; i++) { if (roots[i] instanceof ISourceFolderRoot) { if (!containedRoots.contains(roots[i])) { result.add(roots[i]); } } else { result.add(roots[i]); } } for (Iterator each = containers.iterator(); each.hasNext(); ) { ILoadpathEntry element = (ILoadpathEntry) each.next(); result.add(new LoadPathContainer(project, element)); } return result.toArray(); }