1 11 package org.eclipse.jdt.internal.ui.model; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.resources.mapping.ModelProvider; 21 22 import org.eclipse.ltk.ui.refactoring.model.AbstractResourceMappingMerger; 23 24 import org.eclipse.jdt.core.IJavaModel; 25 import org.eclipse.jdt.core.IJavaProject; 26 import org.eclipse.jdt.core.JavaCore; 27 import org.eclipse.jdt.core.JavaModelException; 28 29 30 import org.eclipse.jdt.internal.ui.JavaPlugin; 31 32 37 public final class JavaModelMerger extends AbstractResourceMappingMerger { 38 39 45 public JavaModelMerger(final ModelProvider provider) { 46 super(provider); 47 } 48 49 52 protected IProject[] getDependencies(final IProject[] projects) { 53 Assert.isNotNull(projects); 54 final Set set= new HashSet (); 55 for (int index= 0; index < projects.length; index++) 56 getDependentProjects(set, projects[index]); 57 final IProject[] result= new IProject[set.size()]; 58 set.toArray(result); 59 return result; 60 } 61 62 70 private void getDependentProjects(final Set set, final IProject project) { 71 Assert.isNotNull(set); 72 Assert.isNotNull(project); 73 final IJavaModel model= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); 74 if (model != null) { 75 try { 76 final String name= project.getName(); 77 final IJavaProject[] projects= model.getJavaProjects(); 78 for (int index= 0; index < projects.length; index++) { 79 final String [] names= projects[index].getRequiredProjectNames(); 80 for (int offset= 0; offset < names.length; offset++) { 81 if (name.equals(names[offset])) 82 set.add(projects[index].getProject()); 83 } 84 } 85 } catch (JavaModelException exception) { 86 JavaPlugin.log(exception); 87 } 88 } 89 } 90 } 91 | Popular Tags |