1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

2004-09-10 Alain Magloire

Remove annoying warnings and prevent the PathEntryManger
	from firing on working Copies.

	* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
This commit is contained in:
Alain Magloire 2004-09-10 15:48:15 +00:00
parent bae54f4e47
commit 3f14afc110
43 changed files with 1042 additions and 1037 deletions

View file

@ -1,3 +1,10 @@
2004-09-10 Alain Magloire
Remove annoying warnings and prevent the PathEntryManger
from firing on working Copies.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
2004-09-07 Alain Magloire
Part of the uncoming work to supply formatting in CDT

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.internal.core.model.APathEntry;
import org.eclipse.cdt.internal.core.model.BatchOperation;
import org.eclipse.cdt.internal.core.model.CModel;
import org.eclipse.cdt.internal.core.model.CModelManager;
@ -368,7 +369,7 @@ public class CoreModel {
*
*/
public static IOutputEntry newOutputEntry(IPath outputPath) {
return newOutputEntry(outputPath, OutputEntry.NO_EXCLUSION_PATTERNS);
return newOutputEntry(outputPath, APathEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -410,7 +411,7 @@ public class CoreModel {
*
*/
public static ISourceEntry newSourceEntry(IPath sourcePath) {
return newSourceEntry(sourcePath, SourceEntry.NO_EXCLUSION_PATTERNS);
return newSourceEntry(sourcePath, APathEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -467,7 +468,7 @@ public class CoreModel {
* @return IIncludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath basePath, IPath includePath, boolean isSystemInclude) {
return newIncludeEntry(resourcePath, basePath, includePath, isSystemInclude, IncludeEntry.NO_EXCLUSION_PATTERNS);
return newIncludeEntry(resourcePath, basePath, includePath, isSystemInclude, APathEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -540,7 +541,7 @@ public class CoreModel {
* @return
*/
public static IMacroEntry newMacroEntry(IPath resourcePath, String macroName, String macroValue) {
return newMacroEntry(resourcePath, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS);
return newMacroEntry(resourcePath, macroName, macroValue, APathEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -589,7 +590,7 @@ public class CoreModel {
* @return
*/
public static IMacroEntry newMacroRefEntry(IPath resourcePath, IPath baseRef, String macroName) {
return new MacroEntry(resourcePath, baseRef, macroName, null, MacroEntry.NO_EXCLUSION_PATTERNS, false);
return new MacroEntry(resourcePath, baseRef, macroName, null, APathEntry.NO_EXCLUSION_PATTERNS, false);
}
/**

View file

@ -23,7 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class ArchiveContainer extends Openable implements IArchiveContainer {
public ArchiveContainer (CProject cProject) {
super (cProject, null, CCorePlugin.getResourceString("CoreModel.ArchiveContainer.Archives"), CElement.C_VCONTAINER); //$NON-NLS-1$
super (cProject, null, CCorePlugin.getResourceString("CoreModel.ArchiveContainer.Archives"), ICElement.C_VCONTAINER); //$NON-NLS-1$
}
public IArchive[] getArchives() throws CModelException {

View file

@ -35,15 +35,14 @@ public class BatchOperation extends CModelOperation {
} catch (CoreException ce) {
if (ce instanceof CModelException) {
throw (CModelException)ce;
} else {
if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
Throwable e= ce.getStatus().getException();
if (e instanceof CModelException) {
throw (CModelException) e;
}
}
throw new CModelException(ce);
}
if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
Throwable e= ce.getStatus().getException();
if (e instanceof CModelException) {
throw (CModelException) e;
}
}
throw new CModelException(ce);
}
}

View file

@ -24,7 +24,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class BinaryContainer extends Openable implements IBinaryContainer {
public BinaryContainer (CProject cProject) {
super (cProject, null, CCorePlugin.getResourceString("CoreModel.BinaryContainer.Binaries"), CElement.C_VCONTAINER); //$NON-NLS-1$
super (cProject, null, CCorePlugin.getResourceString("CoreModel.BinaryContainer.Binaries"), ICElement.C_VCONTAINER); //$NON-NLS-1$
}
public IBinary[] getBinaries() throws CModelException {

View file

@ -214,9 +214,8 @@ public class Buffer implements IBuffer {
public boolean isReadOnly() {
if (this.file == null) {
return (this.flags & F_IS_READ_ONLY) != 0;
} else {
return this.file.isReadOnly();
}
return this.file.isReadOnly();
}
/**

View file

@ -56,10 +56,9 @@ public class BufferManager implements IBufferFactory {
IBuffer buffer= (IBuffer) entry._fValue;
if (buffer.hasUnsavedChanges()) {
return false;
} else {
buffer.close();
return true;
}
buffer.close();
return true;
}
/**
* Returns a new instance of the reciever.

View file

@ -83,11 +83,10 @@ public class CContainerInfo extends OpenableInfo {
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) &&
root.isOnSourceEntry(member)) {
continue;
} else {
if (root.isOnSourceEntry(member)) {
if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
continue;
}
}
if (root.isOnSourceEntry(member)) {
if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
continue;
}
}
break;

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@ -290,12 +291,12 @@ public abstract class CElement extends PlatformObject implements ICElement {
}
public String toDebugString() {
return getElementName() + " " + getTypeString(getElementType()); //$NON-NLS-1$
return getElementName() + " " + getTypeString(); //$NON-NLS-1$
}
// util
public static String getTypeString(int type) {
switch (type) {
public String getTypeString() {
switch (getElementType()) {
case C_MODEL:
return "CMODEL"; //$NON-NLS-1$
case C_PROJECT:
@ -303,6 +304,9 @@ public abstract class CElement extends PlatformObject implements ICElement {
case C_CCONTAINER:
return "CCONTAINER"; //$NON-NLS-1$
case C_UNIT:
if (this instanceof IWorkingCopy) {
return "WORKING_UNIT"; //$NON-NLS-1$
}
return "TRANSLATION_UNIT"; //$NON-NLS-1$
case C_FUNCTION:
return "C_FUNCTION"; //$NON-NLS-1$

View file

@ -270,15 +270,15 @@ private void insertPositions(ICElement[] elements, boolean isNew) {
* none of the internal calls need to use the locally cached contents
* of the old translation unit.
*/
private boolean isIdentical(CElement e1, CElement e2) {
if (e1 == null ^ e2 == null)
return false;
if (e1 == null)
return true;
return e1.isIdentical(e2);
}
//private boolean isIdentical(CElement e1, CElement e2) {
// if (e1 == null ^ e2 == null)
// return false;
//
// if (e1 == null)
// return true;
//
// return e1.isIdentical(e2);
//}
/**
* Answers true if the elements position has not changed.
* Takes into account additions so that elements following
@ -296,9 +296,8 @@ private boolean isPositionedCorrectly(ICElement element) {
if (oldPrevious == null) {
return newPrevious == null;
} else {
return oldPrevious.equals(newPrevious);
}
}
return oldPrevious.equals(newPrevious);
}
private void putElementInfo(ICElement element, CElementInfo info) {
this.infos.put(element, info);

View file

@ -64,7 +64,7 @@ import org.eclipse.core.runtime.Platform;
public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IResolverChangeListener {
public static boolean VERBOSE = false;
public static boolean VERBOSE = true;
/**
* Unique handle onto the CModel

View file

@ -336,16 +336,15 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo
} catch (CoreException ce) {
if (ce instanceof CModelException) {
throw (CModelException)ce;
} else {
// translate the core exception to a c model exception
if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
Throwable e = ce.getStatus().getException();
if (e instanceof CModelException) {
throw (CModelException) e;
}
}
throw new CModelException(ce);
}
// translate the core exception to a c model exception
if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
Throwable e = ce.getStatus().getException();
if (e instanceof CModelException) {
throw (CModelException) e;
}
}
throw new CModelException(ce);
}
}
@ -379,9 +378,8 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo
public ICModel getCModel() {
if (fElementsToProcess == null || fElementsToProcess.length == 0) {
return getParentElement().getCModel();
} else {
return fElementsToProcess[0].getCModel();
}
return fElementsToProcess[0].getCModel();
}
/**

View file

@ -62,9 +62,8 @@ public class CommitWorkingCopyOperation extends CModelOperation {
IWorkspace workspace = resource.getWorkspace();
if (resource.exists()) {
return workspace.getRuleFactory().modifyRule(resource);
} else {
return workspace.getRuleFactory().createRule(resource);
}
return workspace.getRuleFactory().createRule(resource);
}
/**

View file

@ -11,12 +11,13 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IContainerEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.runtime.IPath;
public class ContainerEntry extends PathEntry implements IContainerEntry {
public ContainerEntry(IPath path, boolean isExported) {
super(IContainerEntry.CDT_CONTAINER, path, isExported);
super(IPathEntry.CDT_CONTAINER, path, isExported);
}
public boolean equals(Object obj) {

View file

@ -194,9 +194,9 @@ public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListe
if (projSegment != null && projSegment.equals(project.getName())) { // this
// project
return CoreModel.newSourceEntry(path, exclusionPatterns);
} else { // another project
return CoreModel.newProjectEntry(path, isExported);
}
// another project
return CoreModel.newProjectEntry(path, isExported);
}
case IPathEntry.CDT_OUTPUT :
return CoreModel.newOutputEntry(path, exclusionPatterns);

View file

@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants;
/**
* This operation deletes a collection of resources and all of their children.
@ -44,6 +45,6 @@ public class DeleteResourceElementsOperation extends MultiOperation {
*/
protected void verify(ICElement element) throws CModelException {
if (element == null || !element.exists())
error(CModelStatus.ELEMENT_DOES_NOT_EXIST, element);
error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
}
}

View file

@ -47,17 +47,9 @@ public class ElementCache extends OverflowingLRUCache {
try {
if (element.hasUnsavedChanges()) {
return false;
} /*else {
// We must close an entire JarPackageFragmentRoot at once.
if (element instanceof JarPackageFragment) {
JarPackageFragment packageFragment= (JarPackageFragment) element;
JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent();
root.close();
}*/ else {
element.close();
}
return true;
// }
}
element.close();
return true;
} catch (CModelException npe) {
return false;
}

View file

@ -18,7 +18,7 @@ import org.eclipse.cdt.core.model.IEnumeration;
public class Enumeration extends SourceManipulation implements IEnumeration{
public Enumeration(ICElement parent, String name) {
super(parent, name, CElement.C_ENUMERATION);
super(parent, name, ICElement.C_ENUMERATION);
}
protected CElementInfo createElementInfo () {

View file

@ -18,7 +18,7 @@ public class Enumerator extends SourceManipulation implements IEnumerator{
String constantExpression = ""; //$NON-NLS-1$
public Enumerator(ICElement parent, String name) {
super(parent, name, CElement.C_ENUMERATOR);
super(parent, name, ICElement.C_ENUMERATOR);
}
protected CElementInfo createElementInfo () {

View file

@ -19,7 +19,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
public class Field extends VariableDeclaration implements IField {
public Field(ICElement parent, String name) {
super(parent, name, CElement.C_FIELD);
super(parent, name, ICElement.C_FIELD);
}
public boolean isMutable() throws CModelException{

View file

@ -11,6 +11,6 @@ import org.eclipse.cdt.core.model.IFunction;
public class Function extends FunctionDeclaration implements IFunction {
public Function(ICElement parent, String name) {
super(parent, name, CElement.C_FUNCTION);
super(parent, name, ICElement.C_FUNCTION);
}
}

View file

@ -18,7 +18,7 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
protected String returnType;
public FunctionDeclaration(ICElement parent, String name) {
super(parent, name, CElement.C_FUNCTION_DECLARATION);
super(parent, name, ICElement.C_FUNCTION_DECLARATION);
fParameterTypes= fgEmptyList;
}
@ -28,10 +28,10 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
}
public String getReturnType(){
if (returnType != null)
if (returnType != null) {
return returnType;
else
return ""; //$NON-NLS-1$
}
return ""; //$NON-NLS-1$
}
public void setReturnType(String type){

View file

@ -21,7 +21,7 @@ public class FunctionTemplate extends FunctionDeclaration implements ITemplate{
protected String[] templateParameterTypes;
public FunctionTemplate(ICElement parent, String name) {
super(parent, name, CElement.C_TEMPLATE_FUNCTION);
super(parent, name, ICElement.C_TEMPLATE_FUNCTION);
templateParameterTypes= fgEmptyList;
}

View file

@ -14,7 +14,7 @@ public class Include extends SourceManipulation implements IInclude {
private String fullPath;
public Include(ICElement parent, String name, boolean isStandard) {
super(parent, name, CElement.C_INCLUDE);
super(parent, name, ICElement.C_INCLUDE);
standard = isStandard;
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
@ -22,7 +23,7 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude,
IPath[] exclusionPatterns, boolean isExported) {
super(IIncludeEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, isExported);
super(IPathEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, isExported);
this.includePath = (includePath == null) ? Path.EMPTY : includePath;
this.isSystemInclude = isSystemInclude;
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
@ -35,7 +36,7 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
*/
public LibraryEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath libraryPath, IPath sourceAttachmentPath,
IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) {
super(ILibraryEntry.CDT_LIBRARY, basePath, baseRef, resourcePath, APathEntry.NO_EXCLUSION_PATTERNS, isExported);
super(IPathEntry.CDT_LIBRARY, basePath, baseRef, resourcePath, APathEntry.NO_EXCLUSION_PATTERNS, isExported);
this.libraryPath = (libraryPath == null) ? Path.EMPTY : libraryPath;
this.sourceAttachmentPath = sourceAttachmentPath;
this.sourceAttachmentRootPath = sourceAttachmentRootPath;
@ -144,9 +145,9 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
}
p = loc.append(lib);
return p;
} else {
p = lib;
}
p = lib;
if (!p.isAbsolute()) {
IPath resPath = getPath();
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(resPath);

View file

@ -11,7 +11,7 @@ import org.eclipse.cdt.core.model.IMacro;
public class Macro extends SourceManipulation implements IMacro {
public Macro(ICElement parent, String name) {
super(parent, name, CElement.C_MACRO);
super(parent, name, ICElement.C_MACRO);
}
public String getIdentifierList() {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.runtime.IPath;
public class MacroEntry extends APathEntry implements IMacroEntry {
@ -19,7 +20,7 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
String macroValue;
public MacroEntry (IPath path, IPath baseRef, String macroName, String macroValue, IPath[] exclusionPatterns, boolean isExported) {
super(IMacroEntry.CDT_MACRO, null, baseRef, path, exclusionPatterns, isExported);
super(IPathEntry.CDT_MACRO, null, baseRef, path, exclusionPatterns, isExported);
if ( macroName == null) {
throw new IllegalArgumentException("Macro name cannot be null"); //$NON-NLS-1$
}

View file

@ -11,6 +11,6 @@ import org.eclipse.cdt.core.model.IMethod;
public class Method extends MethodDeclaration implements IMethod{
public Method(ICElement parent, String name){
super(parent, name, CElement.C_METHOD);
super(parent, name, ICElement.C_METHOD);
}
}

View file

@ -23,7 +23,7 @@ public class MethodDeclaration extends FunctionDeclaration implements IMethodDec
boolean isDestructor = false;
public MethodDeclaration(ICElement parent, String name){
super(parent, name, CElement.C_METHOD_DECLARATION);
super(parent, name, ICElement.C_METHOD_DECLARATION);
}
public MethodDeclaration(ICElement parent, String name, int type){

View file

@ -21,7 +21,7 @@ public class MethodTemplate extends MethodDeclaration implements ITemplate{
protected String[] templateParameterTypes;
public MethodTemplate(ICElement parent, String name) {
super(parent, name, CElement.C_TEMPLATE_METHOD);
super(parent, name, ICElement.C_TEMPLATE_METHOD);
templateParameterTypes= fgEmptyList;
}

View file

@ -117,10 +117,10 @@ public abstract class MultiOperation extends CModelOperation {
* if there are no renamings specified.
*/
protected String getNewNameFor(ICElement element) {
if (fRenamings != null)
if (fRenamings != null) {
return (String) fRenamings.get(element);
else
return null;
}
return null;
}
/**

View file

@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - Initial API and implementation
***********************************************************************/
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.INamespace;
@ -19,7 +18,7 @@ public class Namespace extends SourceManipulation implements INamespace{
String typeName = ""; //$NON-NLS-1$
public Namespace(ICElement parent, String name) {
super(parent, name, CElement.C_NAMESPACE);
super(parent, name, ICElement.C_NAMESPACE);
}
/*

View file

@ -41,6 +41,7 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.model.IProjectEntry;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.PathEntryContainerInitializer;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
@ -1209,13 +1210,19 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return true;
}
// project change, traverse children.
} else if (kind == ICElementDelta.ADDED || kind == ICElementDelta.REMOVED) {
}
if (element instanceof IWorkingCopy) {
return false;
}
if (kind == ICElementDelta.ADDED || kind == ICElementDelta.REMOVED) {
return true; // add/remove we validate all paths
}
ICElementDelta[] affectedChildren = delta.getAffectedChildren();
for (int i = 0; i < affectedChildren.length; i++) {
if (processDelta(affectedChildren[i]) == true) {
return true;
if (type == ICElement.C_MODEL || type == ICElement.C_CCONTAINER || type == ICElement.C_PROJECT) {
ICElementDelta[] affectedChildren = delta.getAffectedChildren();
for (int i = 0; i < affectedChildren.length; i++) {
if (processDelta(affectedChildren[i]) == true) {
return true;
}
}
}
return false;

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IProjectEntry;
import org.eclipse.core.runtime.IPath;
@ -17,7 +18,7 @@ import org.eclipse.core.runtime.IPath;
public class ProjectEntry extends PathEntry implements IProjectEntry {
public ProjectEntry(IPath path, boolean isExported) {
super(IProjectEntry.CDT_PROJECT, path, isExported);
super(IPathEntry.CDT_PROJECT, path, isExported);
}
public boolean equals(Object obj) {

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.core.runtime.IPath;
@ -21,7 +22,7 @@ public class SourceEntry extends APathEntry implements ISourceEntry {
* @param exclusionPatterns
*/
public SourceEntry(IPath sourcePath, IPath[] exclusionPatterns) {
super(ISourceEntry.CDT_SOURCE, null, null, sourcePath, exclusionPatterns, false);
super(IPathEntry.CDT_SOURCE, null, null, sourcePath, exclusionPatterns, false);
}
public boolean equals (Object obj) {

View file

@ -18,7 +18,7 @@ public class TypeDef extends SourceManipulation implements ITypeDef{
String typeName= ""; //$NON-NLS-1$
public TypeDef(ICElement parent, String name) {
super(parent, name, CElement.C_TYPEDEF);
super(parent, name, ICElement.C_TYPEDEF);
}
/**
* Returns the typeName.

View file

@ -19,7 +19,7 @@ public class Using extends SourceManipulation implements IUsing {
boolean directive;
public Using(ICElement parent, String name, boolean isDirective) {
super(parent, name, CElement.C_USING);
super(parent, name, ICElement.C_USING);
directive = isDirective;
}

View file

@ -11,7 +11,7 @@ import org.eclipse.cdt.core.model.IVariable;
public class Variable extends VariableDeclaration implements IVariable {
public Variable(ICElement parent, String name) {
super(parent, name, CElement.C_VARIABLE);
super(parent, name, ICElement.C_VARIABLE);
}
public Variable(ICElement parent, String name, int kind) {

View file

@ -12,7 +12,7 @@ import org.eclipse.cdt.core.model.IVariableDeclaration;
public class VariableDeclaration extends SourceManipulation implements IVariableDeclaration {
public VariableDeclaration(ICElement parent, String name) {
super(parent, name, CElement.C_VARIABLE_DECLARATION);
super(parent, name, ICElement.C_VARIABLE_DECLARATION);
}
public VariableDeclaration(ICElement parent, String name, int type) {

View file

@ -19,7 +19,7 @@ public class VariableTemplate extends Variable implements ITemplate {
protected String[] templateParameterTypes;
public VariableTemplate(ICElement parent, String name) {
super(parent, name, CElement.C_TEMPLATE_VARIABLE);
super(parent, name, ICElement.C_TEMPLATE_VARIABLE);
templateParameterTypes= fgEmptyList;
}

View file

@ -1,429 +1,427 @@
package org.eclipse.cdt.internal.core.util;
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - Initial API and implementation
***********************************************************************/
import java.util.Enumeration;
import java.util.Iterator;
import org.eclipse.cdt.internal.core.util.LRUCache;
/**
* The <code>OverflowingLRUCache</code> is an LRUCache which attempts
* to maintain a size equal or less than its <code>fSpaceLimit</code>
* by removing the least recently used elements.
*
* <p>The cache will remove elements which successfully close and all
* elements which are explicitly removed.
*
* <p>If the cache cannot remove enough old elements to add new elements
* it will grow beyond <code>fSpaceLimit</code>. Later, it will attempt to
* shink back to the maximum space limit.
*
* The method <code>close</code> should attempt to close the element. If
* the element is successfully closed it will return true and the element will
* be removed from the cache. Otherwise the element will remain in the cache.
*
* <p>The cache implicitly attempts shrinks on calls to <code>put</code>and
* <code>setSpaceLimit</code>. Explicitly calling the <code>shrink</code> method
* will also cause the cache to attempt to shrink.
*
* <p>The cache calculates the used space of all elements which implement
* <code>ILRUCacheable</code>. All other elements are assumed to be of size one.
*
* <p>Use the <code>#peek(Object)</code> and <code>#disableTimestamps()</code> method to
* circumvent the timestamp feature of the cache. This feature is intended to be used
* only when the <code>#close(LRUCacheEntry)</code> method causes changes to the cache.
* For example, if a parent closes its children when </code>#close(LRUCacheEntry)</code> is called,
* it should be careful not to change the LRU linked list. It can be sure it is not causing
* problems by calling <code>#peek(Object)</code> instead of <code>#get(Object)</code> method.
*
* @see LRUCache
*
* This class is similar to the JDT OverflowingLRUCache class.
*/
public abstract class OverflowingLRUCache extends LRUCache {
/**
* Indicates if the cache has been over filled and by how much.
*/
protected int fOverflow = 0;
/**
* Indicates whether or not timestamps should be updated
*/
protected boolean fTimestampsOn = true;
/**
* Indicates how much space should be reclaimed when the cache overflows.
* Inital load factor of one third.
*/
protected double fLoadFactor = 0.333;
/**
* Creates a OverflowingLRUCache.
* @param size Size limit of cache.
*/
public OverflowingLRUCache(int size) {
this(size, 0);
}
/**
* Creates a OverflowingLRUCache.
* @param size Size limit of cache.
* @param overflow Size of the overflow.
*/
public OverflowingLRUCache(int size, int overflow) {
super(size);
fOverflow = overflow;
}
/**
* Returns a new cache containing the same contents.
*
* @return New copy of this object.
*/
public Object clone() {
OverflowingLRUCache newCache = (OverflowingLRUCache)newInstance(fSpaceLimit, fOverflow);
LRUCacheEntry qEntry;
/* Preserve order of entries by copying from oldest to newest */
qEntry = this.fEntryQueueTail;
while (qEntry != null) {
newCache.privateAdd (qEntry._fKey, qEntry._fValue, qEntry._fSpace);
qEntry = qEntry._fPrevious;
}
return newCache;
}
/**
* Returns true if the element is successfully closed and
* removed from the cache, otherwise false.
*
* <p>NOTE: this triggers an external remove from the cache
* by closing the obejct.
*
*/
protected abstract boolean close(LRUCacheEntry entry);
/**
* Returns an enumerator of the values in the cache with the most
* recently used first.
*/
public Enumeration elements() {
if (fEntryQueue == null)
return new LRUCacheEnumerator(null);
LRUCacheEnumerator.LRUEnumeratorElement head =
new LRUCacheEnumerator.LRUEnumeratorElement(fEntryQueue._fValue);
LRUCacheEntry currentEntry = fEntryQueue._fNext;
LRUCacheEnumerator.LRUEnumeratorElement currentElement = head;
while(currentEntry != null) {
currentElement.fNext = new LRUCacheEnumerator.LRUEnumeratorElement(currentEntry._fValue);
currentElement = currentElement.fNext;
currentEntry = currentEntry._fNext;
}
return new LRUCacheEnumerator(head);
}
public double fillingRatio() {
return (fCurrentSpace + fOverflow) * 100.0 / fSpaceLimit;
}
/**
* For internal testing only.
* This method exposed only for testing purposes!
*
* @return Hashtable of entries
*/
public java.util.Hashtable getEntryTable() {
return fEntryTable;
}
/**
* Returns the load factor for the cache. The load factor determines how
* much space is reclaimed when the cache exceeds its space limit.
* @return double
*/
public double getLoadFactor() {
return fLoadFactor;
}
/**
* @return The space by which the cache has overflown.
*/
public int getOverflow() {
return fOverflow;
}
/**
* Ensures there is the specified amount of free space in the receiver,
* by removing old entries if necessary. Returns true if the requested space was
* made available, false otherwise. May not be able to free enough space
* since some elements cannot be removed until they are saved.
*
* @param space Amount of space to free up
*/
protected boolean makeSpace(int space) {
int limit = fSpaceLimit;
if (fOverflow == 0) {
/* if space is already available */
if (fCurrentSpace + space <= limit) {
return true;
}
}
/* Free up space by removing oldest entries */
int spaceNeeded = (int)((1 - fLoadFactor) * fSpaceLimit);
spaceNeeded = (spaceNeeded > space) ? spaceNeeded : space;
LRUCacheEntry entry = fEntryQueueTail;
while (fCurrentSpace + spaceNeeded > limit && entry != null) {
this.privateRemoveEntry(entry, false, false);
entry = entry._fPrevious;
}
/* check again, since we may have aquired enough space */
if (fCurrentSpace + space <= limit) {
fOverflow = 0;
return true;
}
/* update fOverflow */
fOverflow = fCurrentSpace + space - limit;
return false;
}
/**
* Returns a new instance of the reciever.
*/
protected abstract LRUCache newInstance(int size, int overflow);
/**
* Answers the value in the cache at the given key.
* If the value is not in the cache, returns null
*
* This function does not modify timestamps.
*/
public Object peek(Object key) {
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key);
if (entry == null) {
return null;
}
return entry._fValue;
}
/**
* For testing purposes only
*/
public void printStats() {
int forwardListLength = 0;
LRUCacheEntry entry = fEntryQueue;
while(entry != null) {
forwardListLength++;
entry = entry._fNext;
}
System.out.println("Forward length: " + forwardListLength); //$NON-NLS-1$
int backwardListLength = 0;
entry = fEntryQueueTail;
while(entry != null) {
backwardListLength++;
entry = entry._fPrevious;
}
System.out.println("Backward length: " + backwardListLength); //$NON-NLS-1$
Enumeration keys = fEntryTable.keys();
class Temp {
public Class fClass;
public int fCount;
public Temp(Class aClass) {
fClass = aClass;
fCount = 1;
}
public String toString() {
return "Class: " + fClass + " has " + fCount + " entries."; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
}
}
java.util.HashMap h = new java.util.HashMap();
while(keys.hasMoreElements()) {
entry = (LRUCacheEntry)fEntryTable.get(keys.nextElement());
Class key = entry._fValue.getClass();
Temp t = (Temp)h.get(key);
if (t == null) {
h.put(key, new Temp(key));
} else {
t.fCount++;
}
}
for (Iterator iter = h.keySet().iterator(); iter.hasNext();){
System.out.println(h.get(iter.next()));
}
}
/**
* Removes the entry from the entry queue.
* Calls <code>privateRemoveEntry</code> with the external functionality enabled.
*
* @param shuffle indicates whether we are just shuffling the queue
* (i.e., the entry table is left alone).
*/
protected void privateRemoveEntry (LRUCacheEntry entry, boolean shuffle) {
privateRemoveEntry(entry, shuffle, true);
}
/**
* Removes the entry from the entry queue. If <i>external</i> is true, the entry is removed
* without checking if it can be removed. It is assumed that the client has already closed
* the element it is trying to remove (or will close it promptly).
*
* If <i>external</i> is false, and the entry could not be closed, it is not removed and the
* pointers are not changed.
*
* @param shuffle indicates whether we are just shuffling the queue
* (i.e., the entry table is left alone).
*/
protected void privateRemoveEntry(LRUCacheEntry entry, boolean shuffle, boolean external) {
if (!shuffle) {
if (external) {
fEntryTable.remove(entry._fKey);
fCurrentSpace -= entry._fSpace;
privateNotifyDeletionFromCache(entry);
} else {
if (!close(entry)) return;
// buffer close will recursively call #privateRemoveEntry with external==true
// thus entry will already be removed if reaching this point.
if (fEntryTable.get(entry._fKey) == null){
return;
} else {
// basic removal
fEntryTable.remove(entry._fKey);
fCurrentSpace -= entry._fSpace;
privateNotifyDeletionFromCache(entry);
}
}
}
LRUCacheEntry previous = entry._fPrevious;
LRUCacheEntry next = entry._fNext;
/* if this was the first entry */
if (previous == null) {
fEntryQueue = next;
} else {
previous._fNext = next;
}
/* if this was the last entry */
if (next == null) {
fEntryQueueTail = previous;
} else {
next._fPrevious = previous;
}
}
/**
* Sets the value in the cache at the given key. Returns the value.
*
* @param key Key of object to add.
* @param value Value of object to add.
* @return added value.
*/
public Object put(Object key, Object value) {
/* attempt to rid ourselves of the overflow, if there is any */
if (fOverflow > 0)
shrink();
/* Check whether there's an entry in the cache */
int newSpace = spaceFor (key, value);
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get (key);
if (entry != null) {
/**
* Replace the entry in the cache if it would not overflow
* the cache. Otherwise flush the entry and re-add it so as
* to keep cache within budget
*/
int oldSpace = entry._fSpace;
int newTotal = fCurrentSpace - oldSpace + newSpace;
if (newTotal <= fSpaceLimit) {
updateTimestamp (entry);
entry._fValue = value;
entry._fSpace = newSpace;
fCurrentSpace = newTotal;
fOverflow = 0;
return value;
} else {
privateRemoveEntry (entry, false, false);
}
}
// attempt to make new space
makeSpace(newSpace);
// add without worring about space, it will
// be handled later in a makeSpace call
privateAdd (key, value, newSpace);
return value;
}
/**
* Removes and returns the value in the cache for the given key.
* If the key is not in the cache, returns null.
*
* @param key Key of object to remove from cache.
* @return Value removed from cache.
*/
public Object remove(Object key) {
return removeKey(key);
}
/**
* Sets the load factor for the cache. The load factor determines how
* much space is reclaimed when the cache exceeds its space limit.
* @param newLoadFactor double
* @throws IllegalArgumentException when the new load factor is not in (0.0, 1.0]
*/
public void setLoadFactor(double newLoadFactor) throws IllegalArgumentException {
if(newLoadFactor <= 1.0 && newLoadFactor > 0.0)
fLoadFactor = newLoadFactor;
else
throw new IllegalArgumentException("cache.invalidLoadFactor"); //$NON-NLS-1$
}
/**
* Sets the maximum amount of space that the cache can store
*
* @param limit Number of units of cache space
*/
public void setSpaceLimit(int limit) {
if (limit < fSpaceLimit) {
makeSpace(fSpaceLimit - limit);
}
fSpaceLimit = limit;
}
/**
* Attempts to shrink the cache if it has overflown.
* Returns true if the cache shrinks to less than or equal to <code>fSpaceLimit</code>.
*/
public boolean shrink() {
if (fOverflow > 0)
return makeSpace(0);
return true;
}
/**
* Returns a String that represents the value of this object. This method
* is for debugging purposes only.
*/
public String toString() {
return
"OverflowingLRUCache " + this.fillingRatio() + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$
this.toStringContents();
}
/**
* Updates the timestamp for the given entry, ensuring that the queue is
* kept in correct order. The entry must exist.
*
* <p>This method will do nothing if timestamps have been disabled.
*/
protected void updateTimestamp(LRUCacheEntry entry) {
if (fTimestampsOn) {
entry._fTimestamp = fTimestampCounter++;
if (fEntryQueue != entry) {
this.privateRemoveEntry(entry, true);
this.privateAddEntry(entry, true);
}
}
}
}
package org.eclipse.cdt.internal.core.util;
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - Initial API and implementation
***********************************************************************/
import java.util.Enumeration;
import java.util.Iterator;
import org.eclipse.cdt.internal.core.util.LRUCache;
/**
* The <code>OverflowingLRUCache</code> is an LRUCache which attempts
* to maintain a size equal or less than its <code>fSpaceLimit</code>
* by removing the least recently used elements.
*
* <p>The cache will remove elements which successfully close and all
* elements which are explicitly removed.
*
* <p>If the cache cannot remove enough old elements to add new elements
* it will grow beyond <code>fSpaceLimit</code>. Later, it will attempt to
* shink back to the maximum space limit.
*
* The method <code>close</code> should attempt to close the element. If
* the element is successfully closed it will return true and the element will
* be removed from the cache. Otherwise the element will remain in the cache.
*
* <p>The cache implicitly attempts shrinks on calls to <code>put</code>and
* <code>setSpaceLimit</code>. Explicitly calling the <code>shrink</code> method
* will also cause the cache to attempt to shrink.
*
* <p>The cache calculates the used space of all elements which implement
* <code>ILRUCacheable</code>. All other elements are assumed to be of size one.
*
* <p>Use the <code>#peek(Object)</code> and <code>#disableTimestamps()</code> method to
* circumvent the timestamp feature of the cache. This feature is intended to be used
* only when the <code>#close(LRUCacheEntry)</code> method causes changes to the cache.
* For example, if a parent closes its children when </code>#close(LRUCacheEntry)</code> is called,
* it should be careful not to change the LRU linked list. It can be sure it is not causing
* problems by calling <code>#peek(Object)</code> instead of <code>#get(Object)</code> method.
*
* @see LRUCache
*
* This class is similar to the JDT OverflowingLRUCache class.
*/
public abstract class OverflowingLRUCache extends LRUCache {
/**
* Indicates if the cache has been over filled and by how much.
*/
protected int fOverflow = 0;
/**
* Indicates whether or not timestamps should be updated
*/
protected boolean fTimestampsOn = true;
/**
* Indicates how much space should be reclaimed when the cache overflows.
* Inital load factor of one third.
*/
protected double fLoadFactor = 0.333;
/**
* Creates a OverflowingLRUCache.
* @param size Size limit of cache.
*/
public OverflowingLRUCache(int size) {
this(size, 0);
}
/**
* Creates a OverflowingLRUCache.
* @param size Size limit of cache.
* @param overflow Size of the overflow.
*/
public OverflowingLRUCache(int size, int overflow) {
super(size);
fOverflow = overflow;
}
/**
* Returns a new cache containing the same contents.
*
* @return New copy of this object.
*/
public Object clone() {
OverflowingLRUCache newCache = (OverflowingLRUCache)newInstance(fSpaceLimit, fOverflow);
LRUCacheEntry qEntry;
/* Preserve order of entries by copying from oldest to newest */
qEntry = this.fEntryQueueTail;
while (qEntry != null) {
newCache.privateAdd (qEntry._fKey, qEntry._fValue, qEntry._fSpace);
qEntry = qEntry._fPrevious;
}
return newCache;
}
/**
* Returns true if the element is successfully closed and
* removed from the cache, otherwise false.
*
* <p>NOTE: this triggers an external remove from the cache
* by closing the obejct.
*
*/
protected abstract boolean close(LRUCacheEntry entry);
/**
* Returns an enumerator of the values in the cache with the most
* recently used first.
*/
public Enumeration elements() {
if (fEntryQueue == null)
return new LRUCacheEnumerator(null);
LRUCacheEnumerator.LRUEnumeratorElement head =
new LRUCacheEnumerator.LRUEnumeratorElement(fEntryQueue._fValue);
LRUCacheEntry currentEntry = fEntryQueue._fNext;
LRUCacheEnumerator.LRUEnumeratorElement currentElement = head;
while(currentEntry != null) {
currentElement.fNext = new LRUCacheEnumerator.LRUEnumeratorElement(currentEntry._fValue);
currentElement = currentElement.fNext;
currentEntry = currentEntry._fNext;
}
return new LRUCacheEnumerator(head);
}
public double fillingRatio() {
return (fCurrentSpace + fOverflow) * 100.0 / fSpaceLimit;
}
/**
* For internal testing only.
* This method exposed only for testing purposes!
*
* @return Hashtable of entries
*/
public java.util.Hashtable getEntryTable() {
return fEntryTable;
}
/**
* Returns the load factor for the cache. The load factor determines how
* much space is reclaimed when the cache exceeds its space limit.
* @return double
*/
public double getLoadFactor() {
return fLoadFactor;
}
/**
* @return The space by which the cache has overflown.
*/
public int getOverflow() {
return fOverflow;
}
/**
* Ensures there is the specified amount of free space in the receiver,
* by removing old entries if necessary. Returns true if the requested space was
* made available, false otherwise. May not be able to free enough space
* since some elements cannot be removed until they are saved.
*
* @param space Amount of space to free up
*/
protected boolean makeSpace(int space) {
int limit = fSpaceLimit;
if (fOverflow == 0) {
/* if space is already available */
if (fCurrentSpace + space <= limit) {
return true;
}
}
/* Free up space by removing oldest entries */
int spaceNeeded = (int)((1 - fLoadFactor) * fSpaceLimit);
spaceNeeded = (spaceNeeded > space) ? spaceNeeded : space;
LRUCacheEntry entry = fEntryQueueTail;
while (fCurrentSpace + spaceNeeded > limit && entry != null) {
this.privateRemoveEntry(entry, false, false);
entry = entry._fPrevious;
}
/* check again, since we may have aquired enough space */
if (fCurrentSpace + space <= limit) {
fOverflow = 0;
return true;
}
/* update fOverflow */
fOverflow = fCurrentSpace + space - limit;
return false;
}
/**
* Returns a new instance of the reciever.
*/
protected abstract LRUCache newInstance(int size, int overflow);
/**
* Answers the value in the cache at the given key.
* If the value is not in the cache, returns null
*
* This function does not modify timestamps.
*/
public Object peek(Object key) {
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key);
if (entry == null) {
return null;
}
return entry._fValue;
}
/**
* For testing purposes only
*/
public void printStats() {
int forwardListLength = 0;
LRUCacheEntry entry = fEntryQueue;
while(entry != null) {
forwardListLength++;
entry = entry._fNext;
}
System.out.println("Forward length: " + forwardListLength); //$NON-NLS-1$
int backwardListLength = 0;
entry = fEntryQueueTail;
while(entry != null) {
backwardListLength++;
entry = entry._fPrevious;
}
System.out.println("Backward length: " + backwardListLength); //$NON-NLS-1$
Enumeration keys = fEntryTable.keys();
class Temp {
public Class fClass;
public int fCount;
public Temp(Class aClass) {
fClass = aClass;
fCount = 1;
}
public String toString() {
return "Class: " + fClass + " has " + fCount + " entries."; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
}
}
java.util.HashMap h = new java.util.HashMap();
while(keys.hasMoreElements()) {
entry = (LRUCacheEntry)fEntryTable.get(keys.nextElement());
Class key = entry._fValue.getClass();
Temp t = (Temp)h.get(key);
if (t == null) {
h.put(key, new Temp(key));
} else {
t.fCount++;
}
}
for (Iterator iter = h.keySet().iterator(); iter.hasNext();){
System.out.println(h.get(iter.next()));
}
}
/**
* Removes the entry from the entry queue.
* Calls <code>privateRemoveEntry</code> with the external functionality enabled.
*
* @param shuffle indicates whether we are just shuffling the queue
* (i.e., the entry table is left alone).
*/
protected void privateRemoveEntry (LRUCacheEntry entry, boolean shuffle) {
privateRemoveEntry(entry, shuffle, true);
}
/**
* Removes the entry from the entry queue. If <i>external</i> is true, the entry is removed
* without checking if it can be removed. It is assumed that the client has already closed
* the element it is trying to remove (or will close it promptly).
*
* If <i>external</i> is false, and the entry could not be closed, it is not removed and the
* pointers are not changed.
*
* @param shuffle indicates whether we are just shuffling the queue
* (i.e., the entry table is left alone).
*/
protected void privateRemoveEntry(LRUCacheEntry entry, boolean shuffle, boolean external) {
if (!shuffle) {
if (external) {
fEntryTable.remove(entry._fKey);
fCurrentSpace -= entry._fSpace;
privateNotifyDeletionFromCache(entry);
} else {
if (!close(entry)) return;
// buffer close will recursively call #privateRemoveEntry with external==true
// thus entry will already be removed if reaching this point.
if (fEntryTable.get(entry._fKey) == null){
return;
}
// basic removal
fEntryTable.remove(entry._fKey);
fCurrentSpace -= entry._fSpace;
privateNotifyDeletionFromCache(entry);
}
}
LRUCacheEntry previous = entry._fPrevious;
LRUCacheEntry next = entry._fNext;
/* if this was the first entry */
if (previous == null) {
fEntryQueue = next;
} else {
previous._fNext = next;
}
/* if this was the last entry */
if (next == null) {
fEntryQueueTail = previous;
} else {
next._fPrevious = previous;
}
}
/**
* Sets the value in the cache at the given key. Returns the value.
*
* @param key Key of object to add.
* @param value Value of object to add.
* @return added value.
*/
public Object put(Object key, Object value) {
/* attempt to rid ourselves of the overflow, if there is any */
if (fOverflow > 0)
shrink();
/* Check whether there's an entry in the cache */
int newSpace = spaceFor (key, value);
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get (key);
if (entry != null) {
/**
* Replace the entry in the cache if it would not overflow
* the cache. Otherwise flush the entry and re-add it so as
* to keep cache within budget
*/
int oldSpace = entry._fSpace;
int newTotal = fCurrentSpace - oldSpace + newSpace;
if (newTotal <= fSpaceLimit) {
updateTimestamp (entry);
entry._fValue = value;
entry._fSpace = newSpace;
fCurrentSpace = newTotal;
fOverflow = 0;
return value;
}
privateRemoveEntry (entry, false, false);
}
// attempt to make new space
makeSpace(newSpace);
// add without worring about space, it will
// be handled later in a makeSpace call
privateAdd (key, value, newSpace);
return value;
}
/**
* Removes and returns the value in the cache for the given key.
* If the key is not in the cache, returns null.
*
* @param key Key of object to remove from cache.
* @return Value removed from cache.
*/
public Object remove(Object key) {
return removeKey(key);
}
/**
* Sets the load factor for the cache. The load factor determines how
* much space is reclaimed when the cache exceeds its space limit.
* @param newLoadFactor double
* @throws IllegalArgumentException when the new load factor is not in (0.0, 1.0]
*/
public void setLoadFactor(double newLoadFactor) throws IllegalArgumentException {
if(newLoadFactor <= 1.0 && newLoadFactor > 0.0)
fLoadFactor = newLoadFactor;
else
throw new IllegalArgumentException("cache.invalidLoadFactor"); //$NON-NLS-1$
}
/**
* Sets the maximum amount of space that the cache can store
*
* @param limit Number of units of cache space
*/
public void setSpaceLimit(int limit) {
if (limit < fSpaceLimit) {
makeSpace(fSpaceLimit - limit);
}
fSpaceLimit = limit;
}
/**
* Attempts to shrink the cache if it has overflown.
* Returns true if the cache shrinks to less than or equal to <code>fSpaceLimit</code>.
*/
public boolean shrink() {
if (fOverflow > 0)
return makeSpace(0);
return true;
}
/**
* Returns a String that represents the value of this object. This method
* is for debugging purposes only.
*/
public String toString() {
return
"OverflowingLRUCache " + this.fillingRatio() + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$
this.toStringContents();
}
/**
* Updates the timestamp for the given entry, ensuring that the queue is
* kept in correct order. The entry must exist.
*
* <p>This method will do nothing if timestamps have been disabled.
*/
protected void updateTimestamp(LRUCacheEntry entry) {
if (fTimestampsOn) {
entry._fTimestamp = fTimestampCounter++;
if (fEntryQueue != entry) {
this.privateRemoveEntry(entry, true);
this.privateAddEntry(entry, true);
}
}
}
}