1 11 package org.eclipse.core.resources.mapping; 12 13 import java.util.ArrayList ; 14 import org.eclipse.core.internal.resources.MarkerManager; 15 import org.eclipse.core.internal.resources.Workspace; 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.CoreException; 18 19 35 public class ResourceTraversal { 36 37 private final int depth; 38 private final int flags; 39 private final IResource[] resources; 40 41 48 public ResourceTraversal(IResource[] resources, int depth, int flags) { 49 if (resources == null) 50 throw new NullPointerException (); 51 this.resources = resources; 52 this.depth = depth; 53 this.flags = flags; 54 } 55 56 65 public void accept(IResourceVisitor visitor) throws CoreException { 66 for (int i = 0, imax = resources.length; i < imax; i++) 67 try { 68 if (resources[i].exists()) 69 resources[i].accept(visitor, depth, flags); 70 } catch (CoreException e) { 71 if (e.getStatus().getCode() != IResourceStatus.RESOURCE_NOT_FOUND) 73 throw e; 74 } 75 } 76 77 86 public boolean contains(IResource resource) { 87 for (int i = 0; i < resources.length; i++) { 88 IResource member = resources[i]; 89 if (contains(member, resource)) { 90 return true; 91 } 92 } 93 return false; 94 } 95 96 private boolean contains(IResource resource, IResource child) { 97 if (resource.equals(child)) 98 return true; 99 if (depth == IResource.DEPTH_ZERO) 100 return false; 101 if (child.getParent().equals(resource)) 102 return true; 103 if (depth == IResource.DEPTH_INFINITE) 104 return resource.getFullPath().isPrefixOf(child.getFullPath()); 105 return false; 106 } 107 108 113 void doFindMarkers(ArrayList result, String type, boolean includeSubtypes) { 114 MarkerManager markerMan = ((Workspace) ResourcesPlugin.getWorkspace()).getMarkerManager(); 115 for (int i = 0; i < resources.length; i++) 116 markerMan.doFindMarkers(resources[i], result, type, includeSubtypes, depth); 117 } 118 119 131 public IMarker[] findMarkers(String type, boolean includeSubtypes) throws CoreException { 132 if (resources.length == 0) 133 return new IMarker[0]; 134 ArrayList result = new ArrayList (); 135 doFindMarkers(result, type, includeSubtypes); 136 return (IMarker[]) result.toArray(new IMarker[result.size()]); 137 } 138 139 146 public int getDepth() { 147 return depth; 148 } 149 150 161 public int getFlags() { 162 return flags; 163 } 164 165 178 public IResource[] getResources() { 179 return resources; 180 } 181 } 182 | Popular Tags |