1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import net.sourceforge.phpdt.core.IOpenable;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.core.util.LRUCache;
18 * An LRU cache of <code>JavaElements</code>.
20 public class ElementCache extends OverflowingLRUCache {
22 * Constructs a new element cache of the given size.
24 public ElementCache(int size) {
28 * Constructs a new element cache of the given size.
30 public ElementCache(int size, int overflow) {
31 super(size, overflow);
34 * Returns true if the element is successfully closed and
35 * removed from the cache, otherwise false.
37 * <p>NOTE: this triggers an external removal of this element
38 * by closing the element.
40 protected boolean close(LRUCacheEntry entry) {
41 IOpenable element = (IOpenable) entry._fKey;
43 if (element.hasUnsavedChanges()) {
46 // We must close an entire JarPackageFragmentRoot at once.
47 // if (element instanceof JarPackageFragment) {
48 // JarPackageFragment packageFragment= (JarPackageFragment) element;
49 // JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent();
56 } catch (JavaModelException npe) {
61 * Returns a new instance of the reciever.
63 protected LRUCache newInstance(int size, int overflow) {
64 return new ElementCache(size, overflow);