From 3f14afc11066ba56ee44d52df0f9bdeaa92e5948 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 10 Sep 2004 15:48:15 +0000 Subject: [PATCH] 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 --- core/org.eclipse.cdt.core/ChangeLog | 7 + .../org/eclipse/cdt/core/model/CoreModel.java | 11 +- .../internal/core/model/ArchiveContainer.java | 2 +- .../internal/core/model/BatchOperation.java | 15 +- .../internal/core/model/BinaryContainer.java | 2 +- .../cdt/internal/core/model/Buffer.java | 3 +- .../internal/core/model/BufferManager.java | 5 +- .../internal/core/model/CContainerInfo.java | 9 +- .../cdt/internal/core/model/CElement.java | 10 +- .../core/model/CElementDeltaBuilder.java | 23 +- .../internal/core/model/CModelManager.java | 2 +- .../internal/core/model/CModelOperation.java | 20 +- .../model/CommitWorkingCopyOperation.java | 3 +- .../internal/core/model/ContainerEntry.java | 3 +- .../core/model/DefaultPathEntryStore.java | 4 +- .../DeleteResourceElementsOperation.java | 3 +- .../cdt/internal/core/model/ElementCache.java | 14 +- .../cdt/internal/core/model/Enumeration.java | 2 +- .../cdt/internal/core/model/Enumerator.java | 2 +- .../cdt/internal/core/model/Field.java | 2 +- .../cdt/internal/core/model/Function.java | 2 +- .../core/model/FunctionDeclaration.java | 8 +- .../internal/core/model/FunctionTemplate.java | 2 +- .../cdt/internal/core/model/Include.java | 2 +- .../cdt/internal/core/model/IncludeEntry.java | 3 +- .../cdt/internal/core/model/LibraryEntry.java | 7 +- .../cdt/internal/core/model/Macro.java | 2 +- .../cdt/internal/core/model/MacroEntry.java | 3 +- .../cdt/internal/core/model/Method.java | 2 +- .../core/model/MethodDeclaration.java | 2 +- .../internal/core/model/MethodTemplate.java | 2 +- .../internal/core/model/MultiOperation.java | 6 +- .../cdt/internal/core/model/Namespace.java | 3 +- .../internal/core/model/PathEntryManager.java | 17 +- .../cdt/internal/core/model/ProjectEntry.java | 3 +- .../cdt/internal/core/model/SourceEntry.java | 3 +- .../cdt/internal/core/model/TypeDef.java | 2 +- .../cdt/internal/core/model/Using.java | 2 +- .../cdt/internal/core/model/Variable.java | 2 +- .../core/model/VariableDeclaration.java | 2 +- .../internal/core/model/VariableTemplate.java | 2 +- .../cdt/internal/core/util/LRUCache.java | 1004 ++++++++--------- .../core/util/OverflowingLRUCache.java | 856 +++++++------- 43 files changed, 1042 insertions(+), 1037 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 573be87eeee..5f95101ba0a 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index a034eae910a..2ed568bc3f6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -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); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java index 7d346ab4e78..ced5765f2c1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java index dcc13bb615e..598c8cafdb4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java @@ -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); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java index 631ab2133a2..ff3c75bf7b7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java index 03d132349f5..edd493d8142 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java @@ -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(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java index 786835b347e..f7aa6435739 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java index a48beb479a7..3b786b2899b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java @@ -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; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index 04b4de4d735..0be365d492d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -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$ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java index cfaa49243c3..83ed1d048fd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java @@ -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); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 59213d8c1a4..76cecc0e082 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java index b855bca5edb..e719378b8a7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java @@ -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(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java index 6ea25a80ed9..250e4f5ce05 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java @@ -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); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java index 38c203568f2..307b0fdcf3e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java index 483524ab4d2..1f27be1623f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java @@ -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); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java index 858b6d790b3..d2bac38a2ae 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java @@ -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); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java index 63656a5d469..17978081b05 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java index 344e5c6c6e1..db28ecea134 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java @@ -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 () { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java index b72cf36d3d9..8a292bc1b40 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java @@ -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 () { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java index 9808c4fa20f..e9a4ada3742 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java @@ -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{ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java index 7246a96c54e..412615193b9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java @@ -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); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java index d857c4657c0..8185ed078c6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java @@ -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){ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java index 3c734d33532..17da161474d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java index dffe3cdfaa9..dc903108a5d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java index 6259dc64a73..ef71b252cf7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java index 61144d7bda0..893b10ecca0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java @@ -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); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java index 8570ed04640..34b8e91d709 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java @@ -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() { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java index 0f0f9dbae35..83ecbf2a7d0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java @@ -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$ } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java index adaf4a5bfa8..145b60a1f14 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java @@ -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); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java index f64950dbcce..af4db93dfeb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java @@ -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){ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java index 9901c881a9a..86c820de551 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java index 4ae5aaec649..3dd18d4bb7b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java @@ -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; } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java index 24424c9233d..6a43ed8f126 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java @@ -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); } /* diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index 040cfd3c9ce..4465cb0f97b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -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; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java index cb45b87a9e4..50241341e9c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java index 2128bf72e93..88960cafba0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java index cb4684baa87..976bb2e6101 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java index 01d0f9ccdd8..110b9638d5a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java index 1324cdc8b8c..328bb97a1cd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java index 924c2cd01b5..a9e86b47629 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java index f7e0d4b7d0b..d052ae5abeb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/LRUCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/LRUCache.java index 9ab85bb9d90..f8e97ee68b2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/LRUCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/LRUCache.java @@ -1,503 +1,501 @@ -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.Hashtable; - -/** - * The LRUCache is a hashtable that stores a finite number of elements. - * When an attempt is made to add values to a full cache, the least recently used values - * in the cache are discarded to make room for the new values as necessary. - * - *

The data structure is based on the LRU virtual memory paging scheme. - * - *

Objects can take up a variable amount of cache space by implementing - * the ILRUCacheable interface. - * - *

This implementation is NOT thread-safe. Synchronization wrappers would - * have to be added to ensure atomic insertions and deletions from the cache. - * - * @see ILRUCacheable - * - * This class is similar to the JDT LRUCache class. - */ -public class LRUCache implements Cloneable { - - /** - * This type is used internally by the LRUCache to represent entries - * stored in the cache. - * It is static because it does not require a pointer to the cache - * which contains it. - * - * @see LRUCache - */ - protected static class LRUCacheEntry { - - /** - * Hash table key - */ - public Object _fKey; - - /** - * Hash table value (an LRUCacheEntry object) - */ - public Object _fValue; - - /** - * Time value for queue sorting - */ - public int _fTimestamp; - - /** - * Cache footprint of this entry - */ - public int _fSpace; - - /** - * Previous entry in queue - */ - public LRUCacheEntry _fPrevious; - - /** - * Next entry in queue - */ - public LRUCacheEntry _fNext; - - /** - * Creates a new instance of the receiver with the provided values - * for key, value, and space. - */ - public LRUCacheEntry (Object key, Object value, int space) { - _fKey = key; - _fValue = value; - _fSpace = space; - } - - /** - * Returns a String that represents the value of this object. - */ - public String toString() { - - return "LRUCacheEntry [" + _fKey + "-->" + _fValue + "]"; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Amount of cache space used so far - */ - protected int fCurrentSpace; - - /** - * Maximum space allowed in cache - */ - protected int fSpaceLimit; - - /** - * Counter for handing out sequential timestamps - */ - protected int fTimestampCounter; - - /** - * Hash table for fast random access to cache entries - */ - protected Hashtable fEntryTable; - - /** - * Start of queue (most recently used entry) - */ - protected LRUCacheEntry fEntryQueue; - - /** - * End of queue (least recently used entry) - */ - protected LRUCacheEntry fEntryQueueTail; - - /** - * Default amount of space in the cache - */ - protected static final int DEFAULT_SPACELIMIT = 100; - /** - * Creates a new cache. Size of cache is defined by - * DEFAULT_SPACELIMIT. - */ - public LRUCache() { - - this(DEFAULT_SPACELIMIT); - } - /** - * Creates a new cache. - * @param size Size of Cache - */ - public LRUCache(int size) { - - fTimestampCounter = fCurrentSpace = 0; - fEntryQueue = fEntryQueueTail = null; - fEntryTable = new Hashtable(size); - fSpaceLimit = size; - } - /** - * Returns a new cache containing the same contents. - * - * @return New copy of object. - */ - public Object clone() { - - LRUCache newCache = newInstance(fSpaceLimit); - 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; - } - /** - * Flushes all entries from the cache. - */ - public void flush() { - - fCurrentSpace = 0; - LRUCacheEntry entry = fEntryQueueTail; // Remember last entry - fEntryTable = new Hashtable(); // Clear it out - fEntryQueue = fEntryQueueTail = null; - while (entry != null) { // send deletion notifications in LRU order - privateNotifyDeletionFromCache(entry); - entry = entry._fPrevious; - } - } - /** - * Flushes the given entry from the cache. Does nothing if entry does not - * exist in cache. - * - * @param key Key of object to flush - */ - public void flush (Object key) { - - LRUCacheEntry entry; - - entry = (LRUCacheEntry) fEntryTable.get(key); - - /* If entry does not exist, return */ - if (entry == null) return; - - this.privateRemoveEntry (entry, false); - } - /** - * Answers the value in the cache at the given key. - * If the value is not in the cache, returns null - * - * @param key Hash table key of object to retrieve - * @return Retreived object, or null if object does not exist - */ - public Object get(Object key) { - - LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); - if (entry == null) { - return null; - } - - this.updateTimestamp (entry); - return entry._fValue; - } - /** - * Returns the amount of space that is current used in the cache. - */ - public int getCurrentSpace() { - return fCurrentSpace; - } - /** - * Returns the maximum amount of space available in the cache. - */ - public int getSpaceLimit() { - return fSpaceLimit; - } - /** - * Returns an Enumeration of the keys currently in the cache. - */ - public Enumeration keys() { - - return fEntryTable.keys(); - } - /** - * Returns an enumeration that iterates over all the keys and values - * currently in the cache. - */ - public ICacheEnumeration keysAndValues() { - return new ICacheEnumeration() { - - Enumeration fValues = fEntryTable.elements(); - LRUCacheEntry fEntry; - - public boolean hasMoreElements() { - return fValues.hasMoreElements(); - } - - public Object nextElement() { - fEntry = (LRUCacheEntry) fValues.nextElement(); - return fEntry._fKey; - } - - public Object getValue() { - if (fEntry == null) { - throw new java.util.NoSuchElementException(); - } - return fEntry._fValue; - } - }; - } - /** - * 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. - * - * @param space Amount of space to free up - */ - protected boolean makeSpace (int space) { - - int limit; - - limit = this.getSpaceLimit(); - - /* if space is already available */ - if (fCurrentSpace + space <= limit) { - return true; - } - - /* if entry is too big for cache */ - if (space > limit) { - return false; - } - - /* Free up space by removing oldest entries */ - while (fCurrentSpace + space > limit && fEntryQueueTail != null) { - this.privateRemoveEntry (fEntryQueueTail, false); - } - return true; - } - /** - * Returns a new LRUCache instance - */ - protected LRUCache newInstance(int size) { - return new LRUCache(size); - } - /** - * Adds an entry for the given key/value/space. - */ - protected void privateAdd (Object key, Object value, int space) { - - LRUCacheEntry entry; - - entry = new LRUCacheEntry(key, value, space); - this.privateAddEntry (entry, false); - } - /** - * Adds the given entry from the receiver. - * @param shuffle Indicates whether we are just shuffling the queue - * (i.e., the entry table is left alone). - */ - protected void privateAddEntry (LRUCacheEntry entry, boolean shuffle) { - - if (!shuffle) { - fEntryTable.put (entry._fKey, entry); - fCurrentSpace += entry._fSpace; - } - - entry._fTimestamp = fTimestampCounter++; - entry._fNext = this.fEntryQueue; - entry._fPrevious = null; - - if (fEntryQueue == null) { - /* this is the first and last entry */ - fEntryQueueTail = entry; - } else { - fEntryQueue._fPrevious = entry; - } - - fEntryQueue = entry; - } - /** - * An entry has been removed from the cache, for example because it has - * fallen off the bottom of the LRU queue. - * Subclasses could over-ride this to implement a persistent cache below the LRU cache. - */ - protected void privateNotifyDeletionFromCache(LRUCacheEntry entry) { - // Default is NOP. - } - /** - * Removes the entry from the entry queue. - * @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) { - - LRUCacheEntry previous, next; - - previous = entry._fPrevious; - next = entry._fNext; - - if (!shuffle) { - fEntryTable.remove(entry._fKey); - fCurrentSpace -= entry._fSpace; - privateNotifyDeletionFromCache(entry); - } - - /* 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) { - - int newSpace, oldSpace, newTotal; - LRUCacheEntry entry; - - /* Check whether there's an entry in the cache */ - newSpace = spaceFor (key, value); - 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 - */ - oldSpace = entry._fSpace; - newTotal = getCurrentSpace() - oldSpace + newSpace; - if (newTotal <= getSpaceLimit()) { - updateTimestamp (entry); - entry._fValue = value; - entry._fSpace = newSpace; - this.fCurrentSpace = newTotal; - return value; - } else { - privateRemoveEntry (entry, false); - } - } - if (makeSpace(newSpace)) { - 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 removeKey (Object key) { - - LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); - if (entry == null) { - return null; - } - Object value = entry._fValue; - this.privateRemoveEntry (entry, false); - return value; - } - /** - * 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; - } - /** - * Returns the space taken by the given key and value. - */ - protected int spaceFor (Object key, Object value) { - - if (value instanceof ILRUCacheable) { - return ((ILRUCacheable) value).getCacheFootprint(); - } else { - return 1; - } - } -/** - * Returns a String that represents the value of this object. This method - * is for debugging purposes only. - */ -public String toString() { - return - "LRUCache " + (fCurrentSpace * 100.0 / fSpaceLimit) + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$ - this.toStringContents(); -} -/** - * Returns a String that represents the contents of this object. This method - * is for debugging purposes only. - */ -protected String toStringContents() { - StringBuffer result = new StringBuffer(); - int length = fEntryTable.size(); - Object[] unsortedKeys = new Object[length]; - String[] unsortedToStrings = new String[length]; - Enumeration e = this.keys(); - for (int i = 0; i < length; i++) { - Object key = e.nextElement(); - unsortedKeys[i] = key; - unsortedToStrings[i] = - (key instanceof org.eclipse.cdt.internal.core.model.CElement) ? - ((org.eclipse.cdt.internal.core.model.CElement)key).getElementName() : - key.toString(); - } - ToStringSorter sorter = new ToStringSorter(); - sorter.sort(unsortedKeys, unsortedToStrings); - for (int i = 0; i < length; i++) { - String toString = sorter.sortedStrings[i]; - Object value = this.get(sorter.sortedObjects[i]); - result.append(toString); - result.append(" -> "); //$NON-NLS-1$ - result.append(value); - result.append("\n"); //$NON-NLS-1$ - } - return result.toString(); -} - /** - * Updates the timestamp for the given entry, ensuring that the queue is - * kept in correct order. The entry must exist - */ - protected void updateTimestamp (LRUCacheEntry entry) { - - entry._fTimestamp = fTimestampCounter++; - if (fEntryQueue != entry) { - this.privateRemoveEntry (entry, true); - this.privateAddEntry (entry, true); - } - return; - } - -} +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.Hashtable; + +/** + * The LRUCache is a hashtable that stores a finite number of elements. + * When an attempt is made to add values to a full cache, the least recently used values + * in the cache are discarded to make room for the new values as necessary. + * + *

The data structure is based on the LRU virtual memory paging scheme. + * + *

Objects can take up a variable amount of cache space by implementing + * the ILRUCacheable interface. + * + *

This implementation is NOT thread-safe. Synchronization wrappers would + * have to be added to ensure atomic insertions and deletions from the cache. + * + * @see ILRUCacheable + * + * This class is similar to the JDT LRUCache class. + */ +public class LRUCache implements Cloneable { + + /** + * This type is used internally by the LRUCache to represent entries + * stored in the cache. + * It is static because it does not require a pointer to the cache + * which contains it. + * + * @see LRUCache + */ + protected static class LRUCacheEntry { + + /** + * Hash table key + */ + public Object _fKey; + + /** + * Hash table value (an LRUCacheEntry object) + */ + public Object _fValue; + + /** + * Time value for queue sorting + */ + public int _fTimestamp; + + /** + * Cache footprint of this entry + */ + public int _fSpace; + + /** + * Previous entry in queue + */ + public LRUCacheEntry _fPrevious; + + /** + * Next entry in queue + */ + public LRUCacheEntry _fNext; + + /** + * Creates a new instance of the receiver with the provided values + * for key, value, and space. + */ + public LRUCacheEntry (Object key, Object value, int space) { + _fKey = key; + _fValue = value; + _fSpace = space; + } + + /** + * Returns a String that represents the value of this object. + */ + public String toString() { + + return "LRUCacheEntry [" + _fKey + "-->" + _fValue + "]"; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Amount of cache space used so far + */ + protected int fCurrentSpace; + + /** + * Maximum space allowed in cache + */ + protected int fSpaceLimit; + + /** + * Counter for handing out sequential timestamps + */ + protected int fTimestampCounter; + + /** + * Hash table for fast random access to cache entries + */ + protected Hashtable fEntryTable; + + /** + * Start of queue (most recently used entry) + */ + protected LRUCacheEntry fEntryQueue; + + /** + * End of queue (least recently used entry) + */ + protected LRUCacheEntry fEntryQueueTail; + + /** + * Default amount of space in the cache + */ + protected static final int DEFAULT_SPACELIMIT = 100; + /** + * Creates a new cache. Size of cache is defined by + * DEFAULT_SPACELIMIT. + */ + public LRUCache() { + + this(DEFAULT_SPACELIMIT); + } + /** + * Creates a new cache. + * @param size Size of Cache + */ + public LRUCache(int size) { + + fTimestampCounter = fCurrentSpace = 0; + fEntryQueue = fEntryQueueTail = null; + fEntryTable = new Hashtable(size); + fSpaceLimit = size; + } + /** + * Returns a new cache containing the same contents. + * + * @return New copy of object. + */ + public Object clone() { + + LRUCache newCache = newInstance(fSpaceLimit); + 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; + } + /** + * Flushes all entries from the cache. + */ + public void flush() { + + fCurrentSpace = 0; + LRUCacheEntry entry = fEntryQueueTail; // Remember last entry + fEntryTable = new Hashtable(); // Clear it out + fEntryQueue = fEntryQueueTail = null; + while (entry != null) { // send deletion notifications in LRU order + privateNotifyDeletionFromCache(entry); + entry = entry._fPrevious; + } + } + /** + * Flushes the given entry from the cache. Does nothing if entry does not + * exist in cache. + * + * @param key Key of object to flush + */ + public void flush (Object key) { + + LRUCacheEntry entry; + + entry = (LRUCacheEntry) fEntryTable.get(key); + + /* If entry does not exist, return */ + if (entry == null) return; + + this.privateRemoveEntry (entry, false); + } + /** + * Answers the value in the cache at the given key. + * If the value is not in the cache, returns null + * + * @param key Hash table key of object to retrieve + * @return Retreived object, or null if object does not exist + */ + public Object get(Object key) { + + LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); + if (entry == null) { + return null; + } + + this.updateTimestamp (entry); + return entry._fValue; + } + /** + * Returns the amount of space that is current used in the cache. + */ + public int getCurrentSpace() { + return fCurrentSpace; + } + /** + * Returns the maximum amount of space available in the cache. + */ + public int getSpaceLimit() { + return fSpaceLimit; + } + /** + * Returns an Enumeration of the keys currently in the cache. + */ + public Enumeration keys() { + + return fEntryTable.keys(); + } + /** + * Returns an enumeration that iterates over all the keys and values + * currently in the cache. + */ + public ICacheEnumeration keysAndValues() { + return new ICacheEnumeration() { + + Enumeration fValues = fEntryTable.elements(); + LRUCacheEntry fEntry; + + public boolean hasMoreElements() { + return fValues.hasMoreElements(); + } + + public Object nextElement() { + fEntry = (LRUCacheEntry) fValues.nextElement(); + return fEntry._fKey; + } + + public Object getValue() { + if (fEntry == null) { + throw new java.util.NoSuchElementException(); + } + return fEntry._fValue; + } + }; + } + /** + * 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. + * + * @param space Amount of space to free up + */ + protected boolean makeSpace (int space) { + + int limit; + + limit = this.getSpaceLimit(); + + /* if space is already available */ + if (fCurrentSpace + space <= limit) { + return true; + } + + /* if entry is too big for cache */ + if (space > limit) { + return false; + } + + /* Free up space by removing oldest entries */ + while (fCurrentSpace + space > limit && fEntryQueueTail != null) { + this.privateRemoveEntry (fEntryQueueTail, false); + } + return true; + } + /** + * Returns a new LRUCache instance + */ + protected LRUCache newInstance(int size) { + return new LRUCache(size); + } + /** + * Adds an entry for the given key/value/space. + */ + protected void privateAdd (Object key, Object value, int space) { + + LRUCacheEntry entry; + + entry = new LRUCacheEntry(key, value, space); + this.privateAddEntry (entry, false); + } + /** + * Adds the given entry from the receiver. + * @param shuffle Indicates whether we are just shuffling the queue + * (i.e., the entry table is left alone). + */ + protected void privateAddEntry (LRUCacheEntry entry, boolean shuffle) { + + if (!shuffle) { + fEntryTable.put (entry._fKey, entry); + fCurrentSpace += entry._fSpace; + } + + entry._fTimestamp = fTimestampCounter++; + entry._fNext = this.fEntryQueue; + entry._fPrevious = null; + + if (fEntryQueue == null) { + /* this is the first and last entry */ + fEntryQueueTail = entry; + } else { + fEntryQueue._fPrevious = entry; + } + + fEntryQueue = entry; + } + /** + * An entry has been removed from the cache, for example because it has + * fallen off the bottom of the LRU queue. + * Subclasses could over-ride this to implement a persistent cache below the LRU cache. + */ + protected void privateNotifyDeletionFromCache(LRUCacheEntry entry) { + // Default is NOP. + } + /** + * Removes the entry from the entry queue. + * @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) { + + LRUCacheEntry previous, next; + + previous = entry._fPrevious; + next = entry._fNext; + + if (!shuffle) { + fEntryTable.remove(entry._fKey); + fCurrentSpace -= entry._fSpace; + privateNotifyDeletionFromCache(entry); + } + + /* 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) { + + int newSpace, oldSpace, newTotal; + LRUCacheEntry entry; + + /* Check whether there's an entry in the cache */ + newSpace = spaceFor (key, value); + 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 + */ + oldSpace = entry._fSpace; + newTotal = getCurrentSpace() - oldSpace + newSpace; + if (newTotal <= getSpaceLimit()) { + updateTimestamp (entry); + entry._fValue = value; + entry._fSpace = newSpace; + this.fCurrentSpace = newTotal; + return value; + } + privateRemoveEntry (entry, false); + } + if (makeSpace(newSpace)) { + 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 removeKey (Object key) { + + LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); + if (entry == null) { + return null; + } + Object value = entry._fValue; + this.privateRemoveEntry (entry, false); + return value; + } + /** + * 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; + } + /** + * Returns the space taken by the given key and value. + */ + protected int spaceFor (Object key, Object value) { + + if (value instanceof ILRUCacheable) { + return ((ILRUCacheable) value).getCacheFootprint(); + } + return 1; + } +/** + * Returns a String that represents the value of this object. This method + * is for debugging purposes only. + */ +public String toString() { + return + "LRUCache " + (fCurrentSpace * 100.0 / fSpaceLimit) + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$ + this.toStringContents(); +} +/** + * Returns a String that represents the contents of this object. This method + * is for debugging purposes only. + */ +protected String toStringContents() { + StringBuffer result = new StringBuffer(); + int length = fEntryTable.size(); + Object[] unsortedKeys = new Object[length]; + String[] unsortedToStrings = new String[length]; + Enumeration e = this.keys(); + for (int i = 0; i < length; i++) { + Object key = e.nextElement(); + unsortedKeys[i] = key; + unsortedToStrings[i] = + (key instanceof org.eclipse.cdt.internal.core.model.CElement) ? + ((org.eclipse.cdt.internal.core.model.CElement)key).getElementName() : + key.toString(); + } + ToStringSorter sorter = new ToStringSorter(); + sorter.sort(unsortedKeys, unsortedToStrings); + for (int i = 0; i < length; i++) { + String toString = sorter.sortedStrings[i]; + Object value = this.get(sorter.sortedObjects[i]); + result.append(toString); + result.append(" -> "); //$NON-NLS-1$ + result.append(value); + result.append("\n"); //$NON-NLS-1$ + } + return result.toString(); +} + /** + * Updates the timestamp for the given entry, ensuring that the queue is + * kept in correct order. The entry must exist + */ + protected void updateTimestamp (LRUCacheEntry entry) { + + entry._fTimestamp = fTimestampCounter++; + if (fEntryQueue != entry) { + this.privateRemoveEntry (entry, true); + this.privateAddEntry (entry, true); + } + return; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/OverflowingLRUCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/OverflowingLRUCache.java index c479f797d83..39801a96b65 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/OverflowingLRUCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/OverflowingLRUCache.java @@ -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 OverflowingLRUCache is an LRUCache which attempts - * to maintain a size equal or less than its fSpaceLimit - * by removing the least recently used elements. - * - *

The cache will remove elements which successfully close and all - * elements which are explicitly removed. - * - *

If the cache cannot remove enough old elements to add new elements - * it will grow beyond fSpaceLimit. Later, it will attempt to - * shink back to the maximum space limit. - * - * The method close 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. - * - *

The cache implicitly attempts shrinks on calls to putand - * setSpaceLimit. Explicitly calling the shrink method - * will also cause the cache to attempt to shrink. - * - *

The cache calculates the used space of all elements which implement - * ILRUCacheable. All other elements are assumed to be of size one. - * - *

Use the #peek(Object) and #disableTimestamps() method to - * circumvent the timestamp feature of the cache. This feature is intended to be used - * only when the #close(LRUCacheEntry) method causes changes to the cache. - * For example, if a parent closes its children when #close(LRUCacheEntry) is called, - * it should be careful not to change the LRU linked list. It can be sure it is not causing - * problems by calling #peek(Object) instead of #get(Object) 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. - * - *

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 privateRemoveEntry 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 external 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 external 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 fSpaceLimit. - */ - 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. - * - *

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 OverflowingLRUCache is an LRUCache which attempts + * to maintain a size equal or less than its fSpaceLimit + * by removing the least recently used elements. + * + *

The cache will remove elements which successfully close and all + * elements which are explicitly removed. + * + *

If the cache cannot remove enough old elements to add new elements + * it will grow beyond fSpaceLimit. Later, it will attempt to + * shink back to the maximum space limit. + * + * The method close 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. + * + *

The cache implicitly attempts shrinks on calls to putand + * setSpaceLimit. Explicitly calling the shrink method + * will also cause the cache to attempt to shrink. + * + *

The cache calculates the used space of all elements which implement + * ILRUCacheable. All other elements are assumed to be of size one. + * + *

Use the #peek(Object) and #disableTimestamps() method to + * circumvent the timestamp feature of the cache. This feature is intended to be used + * only when the #close(LRUCacheEntry) method causes changes to the cache. + * For example, if a parent closes its children when #close(LRUCacheEntry) is called, + * it should be careful not to change the LRU linked list. It can be sure it is not causing + * problems by calling #peek(Object) instead of #get(Object) 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. + * + *

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 privateRemoveEntry 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 external 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 external 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 fSpaceLimit. + */ + 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. + * + *

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); + } + } + } +}