KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > participants > ResourceProcessors


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.corext.refactoring.participants;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IResource;
20
21 public class ResourceProcessors {
22     
23     public static String JavaDoc[] computeAffectedNatures(IResource resource) throws CoreException {
24         IProject project= resource.getProject();
25         Set JavaDoc result= new HashSet JavaDoc();
26         Set JavaDoc visitedProjects= new HashSet JavaDoc();
27         computeNatures(result, visitedProjects, project);
28         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
29     }
30     
31     public static String JavaDoc[] computeAffectedNatures(IResource[] resources) throws CoreException {
32         Set JavaDoc result= new HashSet JavaDoc();
33         Set JavaDoc visitedProjects= new HashSet JavaDoc();
34         for (int i= 0; i < resources.length; i++) {
35             computeNatures(result, visitedProjects, resources[i].getProject());
36         }
37         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
38     }
39     
40     private static void computeNatures(Set JavaDoc result, Set JavaDoc visitedProjects, IProject focus) throws CoreException {
41         if (visitedProjects.contains(focus))
42             return;
43         String JavaDoc[] pns= focus.getDescription().getNatureIds();
44         for (int p = 0; p < pns.length; p++) {
45             result.add(pns[p]);
46         }
47         visitedProjects.add(focus);
48         IProject[] referencing= focus.getReferencingProjects();
49         for (int i= 0; i < referencing.length; i++) {
50             computeNatures(result, visitedProjects, referencing[i]);
51         }
52     }
53 }
54
Popular Tags