Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at Contributors: IBM Corporation - initial API and implementation /
package org.eclipse.jdt.internal.core;
An LRU cache of JavaElements.
public class ElementCache extends OverflowingLRUCache {
Constructs a new element cache of the given size.
public ElementCache(int size) {
Constructs a new element cache of the given size.
public ElementCache(int sizeint overflow) {
Returns true if the element is successfully closed and removed from the cache, otherwise false.

NOTE: this triggers an external removal of this element by closing the element.

protected boolean close(LRUCacheEntry entry) {
	Openable element = (Openableentry.key;
	try {
		if (!element.canBeRemovedFromCache()) {
			return false;
else {
			return true;
catch (JavaModelException npe) {
		return false;
 * Ensures that there is enough room for adding the children of the given info.
 * If the space limit must be increased, record the parent that needed this space limit.
protected void ensureSpaceLimit(Object infoIJavaElement parent) {
	// ensure the children can be put without closing other elements
	int childrenSize = ((JavaElementInfoinfo).getChildren().length;
	int spaceNeeded = 1 + (int)((1 + this.) * (childrenSize + this.));
	if (this. < spaceNeeded) {
		// parent is being opened with more children than the space limit
		shrink(); // remove overflow
		this. = parent;
 * Returns a new instance of the receiver.
protected LRUCache newInstance(int sizeint newOverflow) {
	return new ElementCache(sizenewOverflow);
 * If the given parent was the one that increased the space limit, reset
 * the space limit to the given default value.
protected void resetSpaceLimit(int defaultLimitIJavaElement parent) {
	if (parent.equals(this.)) {
		this. = null;
New to GrepCode? Check out our FAQ X