A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / ElementCache.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IOpenable;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.core.util.LRUCache;
16
17 /**
18  * An LRU cache of <code>JavaElements</code>.
19  */
20 public class ElementCache extends OverflowingLRUCache {
21         /**
22          * Constructs a new element cache of the given size.
23          */
24         public ElementCache(int size) {
25                 super(size);
26         }
27
28         /**
29          * Constructs a new element cache of the given size.
30          */
31         public ElementCache(int size, int overflow) {
32                 super(size, overflow);
33         }
34
35         /**
36          * Returns true if the element is successfully closed and removed from the
37          * cache, otherwise false.
38          * 
39          * <p>
40          * NOTE: this triggers an external removal of this element by closing the
41          * element.
42          */
43         protected boolean close(LRUCacheEntry entry) {
44                 IOpenable element = (IOpenable) entry._fKey;
45                 try {
46                         if (element.hasUnsavedChanges()) {
47                                 return false;
48                         } else {
49                                 // We must close an entire JarPackageFragmentRoot at once.
50                                 // if (element instanceof JarPackageFragment) {
51                                 // JarPackageFragment packageFragment= (JarPackageFragment)
52                                 // element;
53                                 // JarPackageFragmentRoot root = (JarPackageFragmentRoot)
54                                 // packageFragment.getParent();
55                                 // root.close();
56                                 // } else {
57                                 element.close();
58                                 // }
59                                 return true;
60                         }
61                 } catch (JavaModelException npe) {
62                         return false;
63                 }
64         }
65
66         /**
67          * Returns a new instance of the reciever.
68          */
69         protected LRUCache newInstance(int size, int overflow) {
70                 return new ElementCache(size, overflow);
71         }
72 }