KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > model > JavaModelMerger


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.model;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
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 /**
33  * Java-aware refactoring model merger.
34  *
35  * @since 3.2
36  */

37 public final class JavaModelMerger extends AbstractResourceMappingMerger {
38
39     /**
40      * Creates a new java model merger.
41      *
42      * @param provider
43      * the model provider
44      */

45     public JavaModelMerger(final ModelProvider provider) {
46         super(provider);
47     }
48
49     /**
50      * {@inheritDoc}
51      */

52     protected IProject[] getDependencies(final IProject[] projects) {
53         Assert.isNotNull(projects);
54         final Set JavaDoc set= new HashSet JavaDoc();
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     /**
63      * Returns the dependent projects of the specified project.
64      *
65      * @param set
66      * the project set
67      * @param project
68      * the project to get its dependent projects
69      */

70     private void getDependentProjects(final Set JavaDoc 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 JavaDoc name= project.getName();
77                 final IJavaProject[] projects= model.getJavaProjects();
78                 for (int index= 0; index < projects.length; index++) {
79                     final String JavaDoc[] 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