1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.*; 14 import java.util.Map ; 15 import org.eclipse.core.internal.localstore.FileStoreRoot; 16 import org.eclipse.core.internal.utils.*; 17 import org.eclipse.core.internal.watson.IElementTreeData; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.QualifiedName; 20 21 24 public class ResourceInfo implements IElementTreeData, ICoreConstants, IStringPoolParticipant { 25 protected static final int LOWER = 0xFFFF; 26 protected static final int UPPER = 0xFFFF0000; 27 28 32 protected volatile int charsetAndContentId = 0; 33 34 37 protected FileStoreRoot fileStoreRoot; 38 39 40 protected int flags = 0; 41 42 43 protected volatile long localInfo = I_NULL_SYNC_INFO; 45 46 50 protected volatile int markerAndSyncStamp; 51 52 53 protected MarkerSet markers = null; 54 55 56 protected long modStamp = 0; 57 58 59 protected volatile long nodeId = 0; 61 62 69 protected ObjectMap sessionProperties = null; 70 71 78 protected ObjectMap syncInfo = null; 79 80 83 protected static int getBits(int flags, int mask, int start) { 84 return (flags & mask) >> start; 85 } 86 87 91 public static int getType(int flags) { 92 return getBits(flags, M_TYPE, M_TYPE_START); 93 } 94 95 98 public static boolean isSet(int flags, int mask) { 99 return (flags & mask) == mask; 100 } 101 102 105 public void clear(int mask) { 106 flags &= ~mask; 107 } 108 109 public void clearModificationStamp() { 110 modStamp = IResource.NULL_STAMP; 111 } 112 113 public synchronized void clearSessionProperties() { 114 sessionProperties = null; 115 } 116 117 public Object clone() { 118 try { 119 return super.clone(); 120 } catch (CloneNotSupportedException e) { 121 return null; } 123 } 124 125 public int getCharsetGenerationCount() { 126 return charsetAndContentId >> 16; 127 } 128 129 public int getContentId() { 130 return charsetAndContentId & LOWER; 131 } 132 133 public FileStoreRoot getFileStoreRoot() { 134 return fileStoreRoot; 135 } 136 137 140 public int getFlags() { 141 return flags; 142 } 143 144 147 public long getLocalSyncInfo() { 148 return localInfo; 149 } 150 151 155 public int getMarkerGenerationCount() { 156 return markerAndSyncStamp >> 16; 157 } 158 159 163 public MarkerSet getMarkers() { 164 return getMarkers(true); 165 } 166 167 171 public MarkerSet getMarkers(boolean makeCopy) { 172 if (markers == null) 173 return null; 174 return makeCopy ? (MarkerSet) markers.clone() : markers; 175 } 176 177 public long getModificationStamp() { 178 return modStamp; 179 } 180 181 public long getNodeId() { 182 return nodeId; 183 } 184 185 188 public Object getPropertyStore() { 189 return null; 190 } 191 192 195 public Object getSessionProperty(QualifiedName name) { 196 Map temp = sessionProperties; 198 if (temp == null) 199 return null; 200 return temp.get(name); 201 } 202 203 208 public synchronized ObjectMap getSyncInfo(boolean makeCopy) { 209 if (syncInfo == null) 210 return null; 211 return makeCopy ? (ObjectMap) syncInfo.clone() : syncInfo; 212 } 213 214 public synchronized byte[] getSyncInfo(QualifiedName id, boolean makeCopy) { 215 byte[] b; 217 if (syncInfo == null) 218 return null; 219 b = (byte[]) syncInfo.get(id); 220 return b == null ? null : (makeCopy ? (byte[]) b.clone() : b); 221 } 222 223 227 public int getSyncInfoGenerationCount() { 228 return markerAndSyncStamp & LOWER; 229 } 230 231 235 public int getType() { 236 return getType(flags); 237 } 238 239 243 public void incrementCharsetGenerationCount() { 244 charsetAndContentId = ((charsetAndContentId + LOWER + 1) & UPPER) + (charsetAndContentId & LOWER); 246 } 247 248 251 public void incrementContentId() { 252 charsetAndContentId = (charsetAndContentId & UPPER) + ((charsetAndContentId + 1) & LOWER); 254 } 255 256 260 public void incrementMarkerGenerationCount() { 261 markerAndSyncStamp = ((markerAndSyncStamp + LOWER + 1) & UPPER) + (markerAndSyncStamp & LOWER); 263 } 264 265 270 public void incrementModificationStamp() { 271 modStamp++; 272 } 273 274 278 public void incrementSyncInfoGenerationCount() { 279 markerAndSyncStamp = (markerAndSyncStamp & UPPER) + ((markerAndSyncStamp + 1) & LOWER); 281 } 282 283 286 public boolean isSet(int mask) { 287 return (flags & mask) == mask; 288 } 289 290 public void readFrom(int newFlags, DataInput input) throws IOException { 291 this.flags = newFlags; 295 localInfo = input.readLong(); 296 nodeId = input.readLong(); 297 charsetAndContentId = input.readInt() & LOWER; 298 modStamp = input.readLong(); 299 } 300 301 304 public void set(int mask) { 305 flags |= mask; 306 } 307 308 311 protected void setBits(int mask, int start, int value) { 312 int baseMask = mask >> start; 313 int newValue = (value & baseMask) << start; 314 int temp = flags; 316 temp &= ~mask; 317 temp |= newValue; 318 flags = temp; 319 } 320 321 public void setFileStoreRoot(FileStoreRoot fileStoreRoot) { 322 this.fileStoreRoot = fileStoreRoot; 323 } 324 325 328 protected void setFlags(int value) { 329 flags = value; 330 } 331 332 335 public void setLocalSyncInfo(long info) { 336 localInfo = info; 337 } 338 339 343 public void setMarkers(MarkerSet value) { 344 markers = value; 345 } 346 347 350 public void setModificationStamp(long value) { 351 this.modStamp = value; 352 } 353 354 357 public void setNodeId(long id) { 358 nodeId = id; 359 } 360 361 364 public void setPropertyStore(Object value) { 365 } 367 368 372 public synchronized void setSessionProperty(QualifiedName name, Object value) { 373 if (value == null) { 375 if (sessionProperties == null) 376 return; 377 ObjectMap temp = (ObjectMap) sessionProperties.clone(); 378 temp.remove(name); 379 if (temp.isEmpty()) 380 sessionProperties = null; 381 else 382 sessionProperties = temp; 383 } else { 384 ObjectMap temp = sessionProperties; 385 if (temp == null) 386 temp = new ObjectMap(5); 387 else 388 temp = (ObjectMap) sessionProperties.clone(); 389 temp.put(name, value); 390 sessionProperties = temp; 391 } 392 } 393 394 399 protected void setSyncInfo(ObjectMap syncInfo) { 400 this.syncInfo = syncInfo; 401 } 402 403 public synchronized void setSyncInfo(QualifiedName id, byte[] value) { 404 if (value == null) { 405 if (syncInfo == null) 407 return; 408 syncInfo.remove(id); 409 if (syncInfo.isEmpty()) 410 syncInfo = null; 411 } else { 412 if (syncInfo == null) 414 syncInfo = new ObjectMap(5); 415 syncInfo.put(id, value.clone()); 416 } 417 } 418 419 423 public void setType(int value) { 424 setBits(M_TYPE, M_TYPE_START, value); 425 } 426 427 430 public void shareStrings(StringPool set) { 431 ObjectMap map = syncInfo; 432 if (map != null) 433 map.shareStrings(set); 434 map = sessionProperties; 435 if (map != null) 436 map.shareStrings(set); 437 MarkerSet markerSet = markers; 438 if (markerSet != null) 439 markerSet.shareStrings(set); 440 } 441 442 public void writeTo(DataOutput output) throws IOException { 443 output.writeLong(localInfo); 447 output.writeLong(nodeId); 448 output.writeInt(getContentId()); 449 output.writeLong(modStamp); 450 } 451 } 452 | Popular Tags |