1 11 package org.eclipse.core.internal.resources; 12 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.runtime.IPath; 17 18 21 public class MarkerDelta implements IMarkerDelta, IMarkerSetElement { 22 protected int kind; 23 protected IResource resource; 24 protected MarkerInfo info; 25 26 29 public MarkerDelta(int kind, IResource resource, MarkerInfo info) { 30 this.kind = kind; 31 this.resource = resource; 32 this.info = info; 33 } 34 35 38 public Object getAttribute(String attributeName) { 39 return info.getAttribute(attributeName); 40 } 41 42 45 public int getAttribute(String attributeName, int defaultValue) { 46 Object value = info.getAttribute(attributeName); 47 if (value instanceof Integer ) 48 return ((Integer ) value).intValue(); 49 return defaultValue; 50 } 51 52 55 public String getAttribute(String attributeName, String defaultValue) { 56 Object value = info.getAttribute(attributeName); 57 if (value instanceof String ) 58 return (String ) value; 59 return defaultValue; 60 } 61 62 65 public boolean getAttribute(String attributeName, boolean defaultValue) { 66 Object value = info.getAttribute(attributeName); 67 if (value instanceof Boolean ) 68 return ((Boolean ) value).booleanValue(); 69 return defaultValue; 70 } 71 72 75 public Map getAttributes() { 76 return info.getAttributes(); 77 } 78 79 82 public Object [] getAttributes(String [] attributeNames) { 83 return info.getAttributes(attributeNames); 84 } 85 86 89 public long getId() { 90 return info.getId(); 91 } 92 93 96 public int getKind() { 97 return kind; 98 } 99 100 103 public IMarker getMarker() { 104 return new Marker(resource, getId()); 105 } 106 107 110 public IResource getResource() { 111 return resource; 112 } 113 114 117 public String getType() { 118 return info.getType(); 119 } 120 121 124 public boolean isSubtypeOf(String superType) { 125 return ((Workspace) getResource().getWorkspace()).getMarkerManager().isSubtype(getType(), superType); 126 } 127 128 132 public static Map merge(Map oldChanges, Map newChanges) { 133 if (oldChanges == null) 134 return newChanges; 136 if (newChanges == null) 137 return oldChanges; 138 for (Iterator it = newChanges.keySet().iterator(); it.hasNext();) { 139 IPath key = (IPath) it.next(); 140 MarkerSet oldSet = (MarkerSet) oldChanges.get(key); 141 MarkerSet newSet = (MarkerSet) newChanges.get(key); 142 if (oldSet == null) 143 oldChanges.put(key, newSet); 144 else 145 merge(oldSet, newSet.elements()); 146 } 147 return oldChanges; 148 } 149 150 164 protected static MarkerSet merge(MarkerSet oldChanges, IMarkerSetElement[] newChanges) { 165 if (oldChanges == null) { 166 MarkerSet result = new MarkerSet(newChanges.length); 167 for (int i = 0; i < newChanges.length; i++) 168 result.add(newChanges[i]); 169 return result; 170 } 171 if (newChanges == null) 172 return oldChanges; 173 174 for (int i = 0; i < newChanges.length; i++) { 175 MarkerDelta newDelta = (MarkerDelta) newChanges[i]; 176 MarkerDelta oldDelta = (MarkerDelta) oldChanges.get(newDelta.getId()); 177 if (oldDelta == null) { 178 oldChanges.add(newDelta); 179 continue; 180 } 181 switch (oldDelta.getKind()) { 182 case IResourceDelta.ADDED : 183 switch (newDelta.getKind()) { 184 case IResourceDelta.ADDED : 185 break; 187 case IResourceDelta.REMOVED : 188 oldChanges.remove(oldDelta); 191 break; 192 case IResourceDelta.CHANGED : 193 break; 195 } 196 break; 197 case IResourceDelta.REMOVED : 198 switch (newDelta.getKind()) { 199 case IResourceDelta.ADDED : 200 break; 202 case IResourceDelta.REMOVED : 203 break; 205 case IResourceDelta.CHANGED : 206 break; 208 } 209 break; 210 case IResourceDelta.CHANGED : 211 switch (newDelta.getKind()) { 212 case IResourceDelta.ADDED : 213 break; 215 case IResourceDelta.REMOVED : 216 oldDelta.setKind(IResourceDelta.REMOVED); 219 break; 220 case IResourceDelta.CHANGED : 221 break; 223 } 224 break; 225 } 226 } 227 return oldChanges; 228 } 229 230 private void setKind(int kind) { 231 this.kind = kind; 232 } 233 } 234 | Popular Tags |