01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.participants;
11:
12: import java.util.HashSet;
13: import java.util.Set;
14:
15: import org.eclipse.core.runtime.CoreException;
16:
17: import org.eclipse.core.resources.IProject;
18: import org.eclipse.core.resources.IResource;
19:
20: public class ResourceProcessors {
21:
22: public static String[] computeAffectedNatures(IResource resource)
23: throws CoreException {
24: IProject project = resource.getProject();
25: Set result = new HashSet();
26: Set visitedProjects = new HashSet();
27: computeNatures(result, visitedProjects, project);
28: return (String[]) result.toArray(new String[result.size()]);
29: }
30:
31: public static String[] computeAffectedNatures(IResource[] resources)
32: throws CoreException {
33: Set result = new HashSet();
34: Set visitedProjects = new HashSet();
35: for (int i = 0; i < resources.length; i++) {
36: computeNatures(result, visitedProjects, resources[i]
37: .getProject());
38: }
39: return (String[]) result.toArray(new String[result.size()]);
40: }
41:
42: private static void computeNatures(Set result, Set visitedProjects,
43: IProject focus) throws CoreException {
44: if (visitedProjects.contains(focus))
45: return;
46: String[] pns = focus.getDescription().getNatureIds();
47: for (int p = 0; p < pns.length; p++) {
48: result.add(pns[p]);
49: }
50: visitedProjects.add(focus);
51: IProject[] referencing = focus.getReferencingProjects();
52: for (int i = 0; i < referencing.length; i++) {
53: computeNatures(result, visitedProjects, referencing[i]);
54: }
55: }
56: }
|