1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.core.JavaModelException; 15 import org.eclipse.jdt.internal.core.util.LRUCache; 16 17 20 public class ElementCache extends OverflowingLRUCache { 21 22 IJavaElement spaceLimitParent = null; 23 24 27 public ElementCache(int size) { 28 super(size); 29 } 30 33 public ElementCache(int size, int overflow) { 34 super(size, overflow); 35 } 36 43 protected boolean close(LRUCacheEntry entry) { 44 Openable element = (Openable) entry._fKey; 45 try { 46 if (!element.canBeRemovedFromCache()) { 47 return false; 48 } else { 49 if (element instanceof JarPackageFragment) { 51 JarPackageFragment packageFragment= (JarPackageFragment) element; 52 JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent(); 53 root.close(); 54 } else { 55 element.close(); 56 } 57 return true; 58 } 59 } catch (JavaModelException npe) { 60 return false; 61 } 62 } 63 64 68 protected void ensureSpaceLimit(int childrenSize, IJavaElement parent) { 69 int spaceNeeded = 1 + (int)((1 + fLoadFactor) * (childrenSize + fOverflow)); 71 if (fSpaceLimit < spaceNeeded) { 72 shrink(); setSpaceLimit(spaceNeeded); 75 this.spaceLimitParent = parent; 76 } 77 } 78 79 82 protected LRUCache newInstance(int size, int overflow) { 83 return new ElementCache(size, overflow); 84 } 85 86 90 protected void resetSpaceLimit(int defaultLimit, IJavaElement parent) { 91 if (parent.equals(this.spaceLimitParent)) { 92 setSpaceLimit(defaultLimit); 93 this.spaceLimitParent = null; 94 } 95 } 96 97 } 98 | Popular Tags |