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) {
29 * Constructs a new element cache of the given size.
31 public ElementCache(int size, int overflow) {
32 super(size, overflow);
36 * Returns true if the element is successfully closed and removed from the
37 * cache, otherwise false.
40 * NOTE: this triggers an external removal of this element by closing the
43 protected boolean close(LRUCacheEntry entry) {
44 IOpenable element = (IOpenable) entry._fKey;
46 if (element.hasUnsavedChanges()) {
49 // We must close an entire JarPackageFragmentRoot at once.
50 // if (element instanceof JarPackageFragment) {
51 // JarPackageFragment packageFragment= (JarPackageFragment)
53 // JarPackageFragmentRoot root = (JarPackageFragmentRoot)
54 // packageFragment.getParent();
61 } catch (JavaModelException npe) {
67 * Returns a new instance of the reciever.
69 protected LRUCache newInstance(int size, int overflow) {
70 return new ElementCache(size, overflow);