1 11 package org.eclipse.core.internal.resources.mapping; 12 13 import java.util.*; 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.*; 16 17 20 public final class ProposedResourceDelta extends PlatformObject implements IResourceDelta { 21 22 protected static int KIND_MASK = 0xFF; 23 24 private HashMap children = new HashMap(8); 25 private IPath movedFromPath; 26 private IPath movedToPath; 27 private IResource resource; 28 private int status; 29 30 public ProposedResourceDelta(IResource resource) { 31 this.resource = resource; 32 } 33 34 37 public void accept(IResourceDeltaVisitor visitor) throws CoreException { 38 accept(visitor, 0); 39 } 40 41 44 public void accept(IResourceDeltaVisitor visitor, boolean includePhantoms) throws CoreException { 45 accept(visitor, includePhantoms ? IContainer.INCLUDE_PHANTOMS : 0); 46 } 47 48 51 public void accept(IResourceDeltaVisitor visitor, int memberFlags) throws CoreException { 52 if (!visitor.visit(this)) 53 return; 54 for (Iterator iter = children.values().iterator(); iter.hasNext();) { 55 ProposedResourceDelta childDelta = (ProposedResourceDelta) iter.next(); 56 childDelta.accept(visitor, memberFlags); 57 } 58 } 59 60 64 protected void add(ProposedResourceDelta delta) { 65 if (children.size() == 0 && status == 0) 66 setKind(IResourceDelta.CHANGED); 67 children.put(delta.getResource().getName(), delta); 68 } 69 70 74 protected void addFlags(int flags) { 75 this.status |= (flags & ~KIND_MASK); 77 } 78 79 82 public IResourceDelta findMember(IPath path) { 83 int segmentCount = path.segmentCount(); 84 if (segmentCount == 0) 85 return this; 86 87 ProposedResourceDelta current = this; 89 for (int i = 0; i < segmentCount; i++) { 90 current = (ProposedResourceDelta) current.children.get(path.segment(i)); 91 if (current == null) 92 return null; 93 } 94 return current; 95 } 96 97 100 public IResourceDelta[] getAffectedChildren() { 101 return getAffectedChildren(ADDED | REMOVED | CHANGED, IResource.NONE); 102 } 103 104 107 public IResourceDelta[] getAffectedChildren(int kindMask) { 108 return getAffectedChildren(kindMask, IResource.NONE); 109 } 110 111 114 public IResourceDelta[] getAffectedChildren(int kindMask, int memberFlags) { 115 List result = new ArrayList(); 116 for (Iterator iter = children.values().iterator(); iter.hasNext();) { 117 ProposedResourceDelta child = (ProposedResourceDelta) iter.next(); 118 if ((child.getKind() & kindMask) != 0) 119 result.add(child); 120 } 121 return (IResourceDelta[]) result.toArray(new IResourceDelta[result.size()]); 122 } 123 124 128 ProposedResourceDelta getChild(String name) { 129 return (ProposedResourceDelta) children.get(name); 130 } 131 132 135 public int getFlags() { 136 return status & ~KIND_MASK; 137 } 138 139 142 public IPath getFullPath() { 143 return getResource().getFullPath(); 144 } 145 146 149 public int getKind() { 150 return status & KIND_MASK; 151 } 152 153 156 public IMarkerDelta[] getMarkerDeltas() { 157 return new IMarkerDelta[0]; 158 } 159 160 163 public IPath getMovedFromPath() { 164 return movedFromPath; 165 } 166 167 170 public IPath getMovedToPath() { 171 return movedToPath; 172 } 173 174 177 public IPath getProjectRelativePath() { 178 return getResource().getProjectRelativePath(); 179 } 180 181 184 public IResource getResource() { 185 return resource; 186 } 187 188 public void setFlags(int flags) { 189 status = getKind() | (flags & ~KIND_MASK); 190 } 191 192 protected void setKind(int kind) { 193 status = getFlags() | (kind & KIND_MASK); 194 } 195 196 protected void setMovedFromPath(IPath path) { 197 movedFromPath = path; 198 } 199 200 protected void setMovedToPath(IPath path) { 201 movedToPath = path; 202 } 203 204 207 public String toString() { 208 return "ProposedDelta(" + resource + ')'; } 210 } 211 | Popular Tags |