1 12 package org.eclipse.debug.core.sourcelookup.containers; 13 14 import java.util.ArrayList ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.DebugPlugin; 21 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 22 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 23 24 34 public class ProjectSourceContainer extends ContainerSourceContainer { 35 36 boolean fReferencedProjects=false; 37 41 public static final String TYPE_ID = DebugPlugin.getUniqueIdentifier() + ".containerType.project"; 43 49 public ProjectSourceContainer(IProject project, boolean referenced) { 50 super(project, true); 51 fReferencedProjects = referenced; 52 } 53 54 59 public boolean isSearchReferencedProjects() { 60 return fReferencedProjects; 61 } 62 63 68 public IProject getProject() { 69 return (IProject) getContainer(); 70 } 71 72 75 public ISourceContainerType getType() { 76 return getSourceContainerType(TYPE_ID); 77 } 78 79 82 public boolean isComposite() { 83 return true; 84 } 85 86 89 protected ISourceContainer[] createSourceContainers() throws CoreException { 90 if (getProject().isOpen()) { 91 if (isSearchReferencedProjects()) { 92 IProject project = getProject(); 93 IProject[] projects = getAllReferencedProjects(project); 94 ISourceContainer[] folders = super.createSourceContainers(); 95 List all = new ArrayList (folders.length + projects.length); 96 for (int i = 0; i < folders.length; i++) { 97 all.add(folders[i]); 98 } 99 for (int i = 0; i < projects.length; i++) { 100 if (project.exists() && project.isOpen()) { 101 ProjectSourceContainer container = new ProjectSourceContainer(projects[i], false); 102 container.init(getDirector()); 103 all.add(container); 104 } 105 } 106 return (ISourceContainer[]) all.toArray(new ISourceContainer[all.size()]); 107 } 108 return super.createSourceContainers(); 109 } 110 return new ISourceContainer[0]; 111 } 112 113 private IProject[] getAllReferencedProjects(IProject project) throws CoreException { 114 Set all = new HashSet (); 115 getAllReferencedProjects(all, project); 116 return (IProject[]) all.toArray(new IProject[all.size()]); 117 } 118 119 private void getAllReferencedProjects(Set all, IProject project) throws CoreException { 120 IProject[] refs = project.getReferencedProjects(); 121 for (int i = 0; i < refs.length; i++) { 122 if (!all.contains(refs[i]) && refs[i].exists() && refs[i].isOpen()) { 123 all.add(refs[i]); 124 getAllReferencedProjects(all, refs[i]); 125 } 126 } 127 } 128 } 129 | Popular Tags |