mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
2004-09-10 Alain Magloire
Remove annoying warnings and prevent the PathEntryManger from firing on working Copies. * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
This commit is contained in:
parent
bae54f4e47
commit
3f14afc110
43 changed files with 1042 additions and 1037 deletions
|
@ -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
|
2004-09-07 Alain Magloire
|
||||||
|
|
||||||
Part of the uncoming work to supply formatting in CDT
|
Part of the uncoming work to supply formatting in CDT
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.CProjectNature;
|
import org.eclipse.cdt.core.CProjectNature;
|
||||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||||
import org.eclipse.cdt.core.resources.IPathEntryStore;
|
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.BatchOperation;
|
||||||
import org.eclipse.cdt.internal.core.model.CModel;
|
import org.eclipse.cdt.internal.core.model.CModel;
|
||||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
@ -368,7 +369,7 @@ public class CoreModel {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static IOutputEntry newOutputEntry(IPath outputPath) {
|
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) {
|
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
|
* @return IIncludeEntry
|
||||||
*/
|
*/
|
||||||
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath basePath, IPath includePath, boolean isSystemInclude) {
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
public static IMacroEntry newMacroEntry(IPath resourcePath, String macroName, String macroValue) {
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
public static IMacroEntry newMacroRefEntry(IPath resourcePath, IPath baseRef, String macroName) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
public class ArchiveContainer extends Openable implements IArchiveContainer {
|
public class ArchiveContainer extends Openable implements IArchiveContainer {
|
||||||
|
|
||||||
public ArchiveContainer (CProject cProject) {
|
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 {
|
public IArchive[] getArchives() throws CModelException {
|
||||||
|
|
|
@ -35,15 +35,14 @@ public class BatchOperation extends CModelOperation {
|
||||||
} catch (CoreException ce) {
|
} catch (CoreException ce) {
|
||||||
if (ce instanceof CModelException) {
|
if (ce instanceof CModelException) {
|
||||||
throw (CModelException)ce;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
public class BinaryContainer extends Openable implements IBinaryContainer {
|
public class BinaryContainer extends Openable implements IBinaryContainer {
|
||||||
|
|
||||||
public BinaryContainer (CProject cProject) {
|
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 {
|
public IBinary[] getBinaries() throws CModelException {
|
||||||
|
|
|
@ -214,9 +214,8 @@ public class Buffer implements IBuffer {
|
||||||
public boolean isReadOnly() {
|
public boolean isReadOnly() {
|
||||||
if (this.file == null) {
|
if (this.file == null) {
|
||||||
return (this.flags & F_IS_READ_ONLY) != 0;
|
return (this.flags & F_IS_READ_ONLY) != 0;
|
||||||
} else {
|
|
||||||
return this.file.isReadOnly();
|
|
||||||
}
|
}
|
||||||
|
return this.file.isReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,10 +56,9 @@ public class BufferManager implements IBufferFactory {
|
||||||
IBuffer buffer= (IBuffer) entry._fValue;
|
IBuffer buffer= (IBuffer) entry._fValue;
|
||||||
if (buffer.hasUnsavedChanges()) {
|
if (buffer.hasUnsavedChanges()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
buffer.close();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
buffer.close();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of the reciever.
|
* Returns a new instance of the reciever.
|
||||||
|
|
|
@ -83,11 +83,10 @@ public class CContainerInfo extends OpenableInfo {
|
||||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) &&
|
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) &&
|
||||||
root.isOnSourceEntry(member)) {
|
root.isOnSourceEntry(member)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
if (root.isOnSourceEntry(member)) {
|
if (root.isOnSourceEntry(member)) {
|
||||||
if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
|
if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.IOpenable;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
@ -290,12 +291,12 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toDebugString() {
|
public String toDebugString() {
|
||||||
return getElementName() + " " + getTypeString(getElementType()); //$NON-NLS-1$
|
return getElementName() + " " + getTypeString(); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
// util
|
// util
|
||||||
public static String getTypeString(int type) {
|
public String getTypeString() {
|
||||||
switch (type) {
|
switch (getElementType()) {
|
||||||
case C_MODEL:
|
case C_MODEL:
|
||||||
return "CMODEL"; //$NON-NLS-1$
|
return "CMODEL"; //$NON-NLS-1$
|
||||||
case C_PROJECT:
|
case C_PROJECT:
|
||||||
|
@ -303,6 +304,9 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
||||||
case C_CCONTAINER:
|
case C_CCONTAINER:
|
||||||
return "CCONTAINER"; //$NON-NLS-1$
|
return "CCONTAINER"; //$NON-NLS-1$
|
||||||
case C_UNIT:
|
case C_UNIT:
|
||||||
|
if (this instanceof IWorkingCopy) {
|
||||||
|
return "WORKING_UNIT"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
return "TRANSLATION_UNIT"; //$NON-NLS-1$
|
return "TRANSLATION_UNIT"; //$NON-NLS-1$
|
||||||
case C_FUNCTION:
|
case C_FUNCTION:
|
||||||
return "C_FUNCTION"; //$NON-NLS-1$
|
return "C_FUNCTION"; //$NON-NLS-1$
|
||||||
|
|
|
@ -270,15 +270,15 @@ private void insertPositions(ICElement[] elements, boolean isNew) {
|
||||||
* none of the internal calls need to use the locally cached contents
|
* none of the internal calls need to use the locally cached contents
|
||||||
* of the old translation unit.
|
* of the old translation unit.
|
||||||
*/
|
*/
|
||||||
private boolean isIdentical(CElement e1, CElement e2) {
|
//private boolean isIdentical(CElement e1, CElement e2) {
|
||||||
if (e1 == null ^ e2 == null)
|
// if (e1 == null ^ e2 == null)
|
||||||
return false;
|
// return false;
|
||||||
|
//
|
||||||
if (e1 == null)
|
// if (e1 == null)
|
||||||
return true;
|
// return true;
|
||||||
|
//
|
||||||
return e1.isIdentical(e2);
|
// return e1.isIdentical(e2);
|
||||||
}
|
//}
|
||||||
/**
|
/**
|
||||||
* Answers true if the elements position has not changed.
|
* Answers true if the elements position has not changed.
|
||||||
* Takes into account additions so that elements following
|
* Takes into account additions so that elements following
|
||||||
|
@ -296,9 +296,8 @@ private boolean isPositionedCorrectly(ICElement element) {
|
||||||
|
|
||||||
if (oldPrevious == null) {
|
if (oldPrevious == null) {
|
||||||
return newPrevious == null;
|
return newPrevious == null;
|
||||||
} else {
|
}
|
||||||
return oldPrevious.equals(newPrevious);
|
return oldPrevious.equals(newPrevious);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void putElementInfo(ICElement element, CElementInfo info) {
|
private void putElementInfo(ICElement element, CElementInfo info) {
|
||||||
this.infos.put(element, info);
|
this.infos.put(element, info);
|
||||||
|
|
|
@ -64,7 +64,7 @@ import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IResolverChangeListener {
|
public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IResolverChangeListener {
|
||||||
|
|
||||||
public static boolean VERBOSE = false;
|
public static boolean VERBOSE = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique handle onto the CModel
|
* Unique handle onto the CModel
|
||||||
|
|
|
@ -336,16 +336,15 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo
|
||||||
} catch (CoreException ce) {
|
} catch (CoreException ce) {
|
||||||
if (ce instanceof CModelException) {
|
if (ce instanceof CModelException) {
|
||||||
throw (CModelException)ce;
|
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() {
|
public ICModel getCModel() {
|
||||||
if (fElementsToProcess == null || fElementsToProcess.length == 0) {
|
if (fElementsToProcess == null || fElementsToProcess.length == 0) {
|
||||||
return getParentElement().getCModel();
|
return getParentElement().getCModel();
|
||||||
} else {
|
|
||||||
return fElementsToProcess[0].getCModel();
|
|
||||||
}
|
}
|
||||||
|
return fElementsToProcess[0].getCModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -62,9 +62,8 @@ public class CommitWorkingCopyOperation extends CModelOperation {
|
||||||
IWorkspace workspace = resource.getWorkspace();
|
IWorkspace workspace = resource.getWorkspace();
|
||||||
if (resource.exists()) {
|
if (resource.exists()) {
|
||||||
return workspace.getRuleFactory().modifyRule(resource);
|
return workspace.getRuleFactory().modifyRule(resource);
|
||||||
} else {
|
|
||||||
return workspace.getRuleFactory().createRule(resource);
|
|
||||||
}
|
}
|
||||||
|
return workspace.getRuleFactory().createRule(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.IContainerEntry;
|
import org.eclipse.cdt.core.model.IContainerEntry;
|
||||||
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
public class ContainerEntry extends PathEntry implements IContainerEntry {
|
public class ContainerEntry extends PathEntry implements IContainerEntry {
|
||||||
|
|
||||||
public ContainerEntry(IPath path, boolean isExported) {
|
public ContainerEntry(IPath path, boolean isExported) {
|
||||||
super(IContainerEntry.CDT_CONTAINER, path, isExported);
|
super(IPathEntry.CDT_CONTAINER, path, isExported);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
|
|
@ -194,9 +194,9 @@ public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListe
|
||||||
if (projSegment != null && projSegment.equals(project.getName())) { // this
|
if (projSegment != null && projSegment.equals(project.getName())) { // this
|
||||||
// project
|
// project
|
||||||
return CoreModel.newSourceEntry(path, exclusionPatterns);
|
return CoreModel.newSourceEntry(path, exclusionPatterns);
|
||||||
} else { // another project
|
|
||||||
return CoreModel.newProjectEntry(path, isExported);
|
|
||||||
}
|
}
|
||||||
|
// another project
|
||||||
|
return CoreModel.newProjectEntry(path, isExported);
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_OUTPUT :
|
case IPathEntry.CDT_OUTPUT :
|
||||||
return CoreModel.newOutputEntry(path, exclusionPatterns);
|
return CoreModel.newOutputEntry(path, exclusionPatterns);
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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.
|
* 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 {
|
protected void verify(ICElement element) throws CModelException {
|
||||||
if (element == null || !element.exists())
|
if (element == null || !element.exists())
|
||||||
error(CModelStatus.ELEMENT_DOES_NOT_EXIST, element);
|
error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,9 @@ public class ElementCache extends OverflowingLRUCache {
|
||||||
try {
|
try {
|
||||||
if (element.hasUnsavedChanges()) {
|
if (element.hasUnsavedChanges()) {
|
||||||
return false;
|
return false;
|
||||||
} /*else {
|
}
|
||||||
// We must close an entire JarPackageFragmentRoot at once.
|
element.close();
|
||||||
if (element instanceof JarPackageFragment) {
|
return true;
|
||||||
JarPackageFragment packageFragment= (JarPackageFragment) element;
|
|
||||||
JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent();
|
|
||||||
root.close();
|
|
||||||
}*/ else {
|
|
||||||
element.close();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
// }
|
|
||||||
} catch (CModelException npe) {
|
} catch (CModelException npe) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.cdt.core.model.IEnumeration;
|
||||||
public class Enumeration extends SourceManipulation implements IEnumeration{
|
public class Enumeration extends SourceManipulation implements IEnumeration{
|
||||||
|
|
||||||
public Enumeration(ICElement parent, String name) {
|
public Enumeration(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_ENUMERATION);
|
super(parent, name, ICElement.C_ENUMERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CElementInfo createElementInfo () {
|
protected CElementInfo createElementInfo () {
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class Enumerator extends SourceManipulation implements IEnumerator{
|
||||||
String constantExpression = ""; //$NON-NLS-1$
|
String constantExpression = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
public Enumerator(ICElement parent, String name) {
|
public Enumerator(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_ENUMERATOR);
|
super(parent, name, ICElement.C_ENUMERATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CElementInfo createElementInfo () {
|
protected CElementInfo createElementInfo () {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
public class Field extends VariableDeclaration implements IField {
|
public class Field extends VariableDeclaration implements IField {
|
||||||
|
|
||||||
public Field(ICElement parent, String name) {
|
public Field(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_FIELD);
|
super(parent, name, ICElement.C_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMutable() throws CModelException{
|
public boolean isMutable() throws CModelException{
|
||||||
|
|
|
@ -11,6 +11,6 @@ import org.eclipse.cdt.core.model.IFunction;
|
||||||
public class Function extends FunctionDeclaration implements IFunction {
|
public class Function extends FunctionDeclaration implements IFunction {
|
||||||
|
|
||||||
public Function(ICElement parent, String name) {
|
public Function(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_FUNCTION);
|
super(parent, name, ICElement.C_FUNCTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
|
||||||
protected String returnType;
|
protected String returnType;
|
||||||
|
|
||||||
public FunctionDeclaration(ICElement parent, String name) {
|
public FunctionDeclaration(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_FUNCTION_DECLARATION);
|
super(parent, name, ICElement.C_FUNCTION_DECLARATION);
|
||||||
fParameterTypes= fgEmptyList;
|
fParameterTypes= fgEmptyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReturnType(){
|
public String getReturnType(){
|
||||||
if (returnType != null)
|
if (returnType != null) {
|
||||||
return returnType;
|
return returnType;
|
||||||
else
|
}
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReturnType(String type){
|
public void setReturnType(String type){
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class FunctionTemplate extends FunctionDeclaration implements ITemplate{
|
||||||
protected String[] templateParameterTypes;
|
protected String[] templateParameterTypes;
|
||||||
|
|
||||||
public FunctionTemplate(ICElement parent, String name) {
|
public FunctionTemplate(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_TEMPLATE_FUNCTION);
|
super(parent, name, ICElement.C_TEMPLATE_FUNCTION);
|
||||||
templateParameterTypes= fgEmptyList;
|
templateParameterTypes= fgEmptyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class Include extends SourceManipulation implements IInclude {
|
||||||
private String fullPath;
|
private String fullPath;
|
||||||
|
|
||||||
public Include(ICElement parent, String name, boolean isStandard) {
|
public Include(ICElement parent, String name, boolean isStandard) {
|
||||||
super(parent, name, CElement.C_INCLUDE);
|
super(parent, name, ICElement.C_INCLUDE);
|
||||||
standard = isStandard;
|
standard = isStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.IIncludeEntry;
|
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.IResource;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
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,
|
public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude,
|
||||||
IPath[] exclusionPatterns, boolean isExported) {
|
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.includePath = (includePath == null) ? Path.EMPTY : includePath;
|
||||||
this.isSystemInclude = isSystemInclude;
|
this.isSystemInclude = isSystemInclude;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ILibraryEntry;
|
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.IResource;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
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,
|
public LibraryEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath libraryPath, IPath sourceAttachmentPath,
|
||||||
IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) {
|
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.libraryPath = (libraryPath == null) ? Path.EMPTY : libraryPath;
|
||||||
this.sourceAttachmentPath = sourceAttachmentPath;
|
this.sourceAttachmentPath = sourceAttachmentPath;
|
||||||
this.sourceAttachmentRootPath = sourceAttachmentRootPath;
|
this.sourceAttachmentRootPath = sourceAttachmentRootPath;
|
||||||
|
@ -144,9 +145,9 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
|
||||||
}
|
}
|
||||||
p = loc.append(lib);
|
p = loc.append(lib);
|
||||||
return p;
|
return p;
|
||||||
} else {
|
|
||||||
p = lib;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = lib;
|
||||||
if (!p.isAbsolute()) {
|
if (!p.isAbsolute()) {
|
||||||
IPath resPath = getPath();
|
IPath resPath = getPath();
|
||||||
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(resPath);
|
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(resPath);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.eclipse.cdt.core.model.IMacro;
|
||||||
public class Macro extends SourceManipulation implements IMacro {
|
public class Macro extends SourceManipulation implements IMacro {
|
||||||
|
|
||||||
public Macro(ICElement parent, String name) {
|
public Macro(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_MACRO);
|
super(parent, name, ICElement.C_MACRO);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdentifierList() {
|
public String getIdentifierList() {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.IMacroEntry;
|
import org.eclipse.cdt.core.model.IMacroEntry;
|
||||||
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
public class MacroEntry extends APathEntry implements IMacroEntry {
|
public class MacroEntry extends APathEntry implements IMacroEntry {
|
||||||
|
@ -19,7 +20,7 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
|
||||||
String macroValue;
|
String macroValue;
|
||||||
|
|
||||||
public MacroEntry (IPath path, IPath baseRef, String macroName, String macroValue, IPath[] exclusionPatterns, boolean isExported) {
|
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) {
|
if ( macroName == null) {
|
||||||
throw new IllegalArgumentException("Macro name cannot be null"); //$NON-NLS-1$
|
throw new IllegalArgumentException("Macro name cannot be null"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,6 @@ import org.eclipse.cdt.core.model.IMethod;
|
||||||
public class Method extends MethodDeclaration implements IMethod{
|
public class Method extends MethodDeclaration implements IMethod{
|
||||||
|
|
||||||
public Method(ICElement parent, String name){
|
public Method(ICElement parent, String name){
|
||||||
super(parent, name, CElement.C_METHOD);
|
super(parent, name, ICElement.C_METHOD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class MethodDeclaration extends FunctionDeclaration implements IMethodDec
|
||||||
boolean isDestructor = false;
|
boolean isDestructor = false;
|
||||||
|
|
||||||
public MethodDeclaration(ICElement parent, String name){
|
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){
|
public MethodDeclaration(ICElement parent, String name, int type){
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class MethodTemplate extends MethodDeclaration implements ITemplate{
|
||||||
protected String[] templateParameterTypes;
|
protected String[] templateParameterTypes;
|
||||||
|
|
||||||
public MethodTemplate(ICElement parent, String name) {
|
public MethodTemplate(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_TEMPLATE_METHOD);
|
super(parent, name, ICElement.C_TEMPLATE_METHOD);
|
||||||
templateParameterTypes= fgEmptyList;
|
templateParameterTypes= fgEmptyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,10 @@ public abstract class MultiOperation extends CModelOperation {
|
||||||
* if there are no renamings specified.
|
* if there are no renamings specified.
|
||||||
*/
|
*/
|
||||||
protected String getNewNameFor(ICElement element) {
|
protected String getNewNameFor(ICElement element) {
|
||||||
if (fRenamings != null)
|
if (fRenamings != null) {
|
||||||
return (String) fRenamings.get(element);
|
return (String) fRenamings.get(element);
|
||||||
else
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
* Rational Software - Initial API and implementation
|
* 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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.INamespace;
|
import org.eclipse.cdt.core.model.INamespace;
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ public class Namespace extends SourceManipulation implements INamespace{
|
||||||
|
|
||||||
String typeName = ""; //$NON-NLS-1$
|
String typeName = ""; //$NON-NLS-1$
|
||||||
public Namespace(ICElement parent, String name) {
|
public Namespace(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_NAMESPACE);
|
super(parent, name, ICElement.C_NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.cdt.core.model.IPathEntryContainer;
|
import org.eclipse.cdt.core.model.IPathEntryContainer;
|
||||||
import org.eclipse.cdt.core.model.IProjectEntry;
|
import org.eclipse.cdt.core.model.IProjectEntry;
|
||||||
import org.eclipse.cdt.core.model.ISourceEntry;
|
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.model.PathEntryContainerInitializer;
|
||||||
import org.eclipse.cdt.core.resources.IPathEntryStore;
|
import org.eclipse.cdt.core.resources.IPathEntryStore;
|
||||||
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
||||||
|
@ -1209,13 +1210,19 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// project change, traverse children.
|
// 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
|
return true; // add/remove we validate all paths
|
||||||
}
|
}
|
||||||
ICElementDelta[] affectedChildren = delta.getAffectedChildren();
|
if (type == ICElement.C_MODEL || type == ICElement.C_CCONTAINER || type == ICElement.C_PROJECT) {
|
||||||
for (int i = 0; i < affectedChildren.length; i++) {
|
ICElementDelta[] affectedChildren = delta.getAffectedChildren();
|
||||||
if (processDelta(affectedChildren[i]) == true) {
|
for (int i = 0; i < affectedChildren.length; i++) {
|
||||||
return true;
|
if (processDelta(affectedChildren[i]) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.cdt.core.model.IProjectEntry;
|
import org.eclipse.cdt.core.model.IProjectEntry;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ import org.eclipse.core.runtime.IPath;
|
||||||
public class ProjectEntry extends PathEntry implements IProjectEntry {
|
public class ProjectEntry extends PathEntry implements IProjectEntry {
|
||||||
|
|
||||||
public ProjectEntry(IPath path, boolean isExported) {
|
public ProjectEntry(IPath path, boolean isExported) {
|
||||||
super(IProjectEntry.CDT_PROJECT, path, isExported);
|
super(IPathEntry.CDT_PROJECT, path, isExported);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.cdt.core.model.ISourceEntry;
|
import org.eclipse.cdt.core.model.ISourceEntry;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ public class SourceEntry extends APathEntry implements ISourceEntry {
|
||||||
* @param exclusionPatterns
|
* @param exclusionPatterns
|
||||||
*/
|
*/
|
||||||
public SourceEntry(IPath sourcePath, IPath[] 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) {
|
public boolean equals (Object obj) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class TypeDef extends SourceManipulation implements ITypeDef{
|
||||||
|
|
||||||
String typeName= ""; //$NON-NLS-1$
|
String typeName= ""; //$NON-NLS-1$
|
||||||
public TypeDef(ICElement parent, String name) {
|
public TypeDef(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_TYPEDEF);
|
super(parent, name, ICElement.C_TYPEDEF);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the typeName.
|
* Returns the typeName.
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class Using extends SourceManipulation implements IUsing {
|
||||||
boolean directive;
|
boolean directive;
|
||||||
|
|
||||||
public Using(ICElement parent, String name, boolean isDirective) {
|
public Using(ICElement parent, String name, boolean isDirective) {
|
||||||
super(parent, name, CElement.C_USING);
|
super(parent, name, ICElement.C_USING);
|
||||||
directive = isDirective;
|
directive = isDirective;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.eclipse.cdt.core.model.IVariable;
|
||||||
public class Variable extends VariableDeclaration implements IVariable {
|
public class Variable extends VariableDeclaration implements IVariable {
|
||||||
|
|
||||||
public Variable(ICElement parent, String name) {
|
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) {
|
public Variable(ICElement parent, String name, int kind) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.eclipse.cdt.core.model.IVariableDeclaration;
|
||||||
public class VariableDeclaration extends SourceManipulation implements IVariableDeclaration {
|
public class VariableDeclaration extends SourceManipulation implements IVariableDeclaration {
|
||||||
|
|
||||||
public VariableDeclaration(ICElement parent, String name) {
|
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) {
|
public VariableDeclaration(ICElement parent, String name, int type) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class VariableTemplate extends Variable implements ITemplate {
|
||||||
protected String[] templateParameterTypes;
|
protected String[] templateParameterTypes;
|
||||||
|
|
||||||
public VariableTemplate(ICElement parent, String name) {
|
public VariableTemplate(ICElement parent, String name) {
|
||||||
super(parent, name, CElement.C_TEMPLATE_VARIABLE);
|
super(parent, name, ICElement.C_TEMPLATE_VARIABLE);
|
||||||
templateParameterTypes= fgEmptyList;
|
templateParameterTypes= fgEmptyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,429 +1,427 @@
|
||||||
package org.eclipse.cdt.internal.core.util;
|
package org.eclipse.cdt.internal.core.util;
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v0.5
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Rational Software - Initial API and implementation
|
* Rational Software - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.util.LRUCache;
|
import org.eclipse.cdt.internal.core.util.LRUCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>OverflowingLRUCache</code> is an LRUCache which attempts
|
* The <code>OverflowingLRUCache</code> is an LRUCache which attempts
|
||||||
* to maintain a size equal or less than its <code>fSpaceLimit</code>
|
* to maintain a size equal or less than its <code>fSpaceLimit</code>
|
||||||
* by removing the least recently used elements.
|
* by removing the least recently used elements.
|
||||||
*
|
*
|
||||||
* <p>The cache will remove elements which successfully close and all
|
* <p>The cache will remove elements which successfully close and all
|
||||||
* elements which are explicitly removed.
|
* elements which are explicitly removed.
|
||||||
*
|
*
|
||||||
* <p>If the cache cannot remove enough old elements to add new elements
|
* <p>If the cache cannot remove enough old elements to add new elements
|
||||||
* it will grow beyond <code>fSpaceLimit</code>. Later, it will attempt to
|
* it will grow beyond <code>fSpaceLimit</code>. Later, it will attempt to
|
||||||
* shink back to the maximum space limit.
|
* shink back to the maximum space limit.
|
||||||
*
|
*
|
||||||
* The method <code>close</code> should attempt to close the element. If
|
* The method <code>close</code> should attempt to close the element. If
|
||||||
* the element is successfully closed it will return true and the element will
|
* 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.
|
* be removed from the cache. Otherwise the element will remain in the cache.
|
||||||
*
|
*
|
||||||
* <p>The cache implicitly attempts shrinks on calls to <code>put</code>and
|
* <p>The cache implicitly attempts shrinks on calls to <code>put</code>and
|
||||||
* <code>setSpaceLimit</code>. Explicitly calling the <code>shrink</code> method
|
* <code>setSpaceLimit</code>. Explicitly calling the <code>shrink</code> method
|
||||||
* will also cause the cache to attempt to shrink.
|
* will also cause the cache to attempt to shrink.
|
||||||
*
|
*
|
||||||
* <p>The cache calculates the used space of all elements which implement
|
* <p>The cache calculates the used space of all elements which implement
|
||||||
* <code>ILRUCacheable</code>. All other elements are assumed to be of size one.
|
* <code>ILRUCacheable</code>. All other elements are assumed to be of size one.
|
||||||
*
|
*
|
||||||
* <p>Use the <code>#peek(Object)</code> and <code>#disableTimestamps()</code> method to
|
* <p>Use the <code>#peek(Object)</code> and <code>#disableTimestamps()</code> method to
|
||||||
* circumvent the timestamp feature of the cache. This feature is intended to be used
|
* circumvent the timestamp feature of the cache. This feature is intended to be used
|
||||||
* only when the <code>#close(LRUCacheEntry)</code> method causes changes to the cache.
|
* only when the <code>#close(LRUCacheEntry)</code> method causes changes to the cache.
|
||||||
* For example, if a parent closes its children when </code>#close(LRUCacheEntry)</code> is called,
|
* For example, if a parent closes its children when </code>#close(LRUCacheEntry)</code> is called,
|
||||||
* it should be careful not to change the LRU linked list. It can be sure it is not causing
|
* it should be careful not to change the LRU linked list. It can be sure it is not causing
|
||||||
* problems by calling <code>#peek(Object)</code> instead of <code>#get(Object)</code> method.
|
* problems by calling <code>#peek(Object)</code> instead of <code>#get(Object)</code> method.
|
||||||
*
|
*
|
||||||
* @see LRUCache
|
* @see LRUCache
|
||||||
*
|
*
|
||||||
* This class is similar to the JDT OverflowingLRUCache class.
|
* This class is similar to the JDT OverflowingLRUCache class.
|
||||||
*/
|
*/
|
||||||
public abstract class OverflowingLRUCache extends LRUCache {
|
public abstract class OverflowingLRUCache extends LRUCache {
|
||||||
/**
|
/**
|
||||||
* Indicates if the cache has been over filled and by how much.
|
* Indicates if the cache has been over filled and by how much.
|
||||||
*/
|
*/
|
||||||
protected int fOverflow = 0;
|
protected int fOverflow = 0;
|
||||||
/**
|
/**
|
||||||
* Indicates whether or not timestamps should be updated
|
* Indicates whether or not timestamps should be updated
|
||||||
*/
|
*/
|
||||||
protected boolean fTimestampsOn = true;
|
protected boolean fTimestampsOn = true;
|
||||||
/**
|
/**
|
||||||
* Indicates how much space should be reclaimed when the cache overflows.
|
* Indicates how much space should be reclaimed when the cache overflows.
|
||||||
* Inital load factor of one third.
|
* Inital load factor of one third.
|
||||||
*/
|
*/
|
||||||
protected double fLoadFactor = 0.333;
|
protected double fLoadFactor = 0.333;
|
||||||
/**
|
/**
|
||||||
* Creates a OverflowingLRUCache.
|
* Creates a OverflowingLRUCache.
|
||||||
* @param size Size limit of cache.
|
* @param size Size limit of cache.
|
||||||
*/
|
*/
|
||||||
public OverflowingLRUCache(int size) {
|
public OverflowingLRUCache(int size) {
|
||||||
this(size, 0);
|
this(size, 0);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Creates a OverflowingLRUCache.
|
* Creates a OverflowingLRUCache.
|
||||||
* @param size Size limit of cache.
|
* @param size Size limit of cache.
|
||||||
* @param overflow Size of the overflow.
|
* @param overflow Size of the overflow.
|
||||||
*/
|
*/
|
||||||
public OverflowingLRUCache(int size, int overflow) {
|
public OverflowingLRUCache(int size, int overflow) {
|
||||||
super(size);
|
super(size);
|
||||||
fOverflow = overflow;
|
fOverflow = overflow;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a new cache containing the same contents.
|
* Returns a new cache containing the same contents.
|
||||||
*
|
*
|
||||||
* @return New copy of this object.
|
* @return New copy of this object.
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
|
|
||||||
OverflowingLRUCache newCache = (OverflowingLRUCache)newInstance(fSpaceLimit, fOverflow);
|
OverflowingLRUCache newCache = (OverflowingLRUCache)newInstance(fSpaceLimit, fOverflow);
|
||||||
LRUCacheEntry qEntry;
|
LRUCacheEntry qEntry;
|
||||||
|
|
||||||
/* Preserve order of entries by copying from oldest to newest */
|
/* Preserve order of entries by copying from oldest to newest */
|
||||||
qEntry = this.fEntryQueueTail;
|
qEntry = this.fEntryQueueTail;
|
||||||
while (qEntry != null) {
|
while (qEntry != null) {
|
||||||
newCache.privateAdd (qEntry._fKey, qEntry._fValue, qEntry._fSpace);
|
newCache.privateAdd (qEntry._fKey, qEntry._fValue, qEntry._fSpace);
|
||||||
qEntry = qEntry._fPrevious;
|
qEntry = qEntry._fPrevious;
|
||||||
}
|
}
|
||||||
return newCache;
|
return newCache;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if the element is successfully closed and
|
* Returns true if the element is successfully closed and
|
||||||
* removed from the cache, otherwise false.
|
* removed from the cache, otherwise false.
|
||||||
*
|
*
|
||||||
* <p>NOTE: this triggers an external remove from the cache
|
* <p>NOTE: this triggers an external remove from the cache
|
||||||
* by closing the obejct.
|
* by closing the obejct.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected abstract boolean close(LRUCacheEntry entry);
|
protected abstract boolean close(LRUCacheEntry entry);
|
||||||
/**
|
/**
|
||||||
* Returns an enumerator of the values in the cache with the most
|
* Returns an enumerator of the values in the cache with the most
|
||||||
* recently used first.
|
* recently used first.
|
||||||
*/
|
*/
|
||||||
public Enumeration elements() {
|
public Enumeration elements() {
|
||||||
if (fEntryQueue == null)
|
if (fEntryQueue == null)
|
||||||
return new LRUCacheEnumerator(null);
|
return new LRUCacheEnumerator(null);
|
||||||
LRUCacheEnumerator.LRUEnumeratorElement head =
|
LRUCacheEnumerator.LRUEnumeratorElement head =
|
||||||
new LRUCacheEnumerator.LRUEnumeratorElement(fEntryQueue._fValue);
|
new LRUCacheEnumerator.LRUEnumeratorElement(fEntryQueue._fValue);
|
||||||
LRUCacheEntry currentEntry = fEntryQueue._fNext;
|
LRUCacheEntry currentEntry = fEntryQueue._fNext;
|
||||||
LRUCacheEnumerator.LRUEnumeratorElement currentElement = head;
|
LRUCacheEnumerator.LRUEnumeratorElement currentElement = head;
|
||||||
while(currentEntry != null) {
|
while(currentEntry != null) {
|
||||||
currentElement.fNext = new LRUCacheEnumerator.LRUEnumeratorElement(currentEntry._fValue);
|
currentElement.fNext = new LRUCacheEnumerator.LRUEnumeratorElement(currentEntry._fValue);
|
||||||
currentElement = currentElement.fNext;
|
currentElement = currentElement.fNext;
|
||||||
|
|
||||||
currentEntry = currentEntry._fNext;
|
currentEntry = currentEntry._fNext;
|
||||||
}
|
}
|
||||||
return new LRUCacheEnumerator(head);
|
return new LRUCacheEnumerator(head);
|
||||||
}
|
}
|
||||||
public double fillingRatio() {
|
public double fillingRatio() {
|
||||||
return (fCurrentSpace + fOverflow) * 100.0 / fSpaceLimit;
|
return (fCurrentSpace + fOverflow) * 100.0 / fSpaceLimit;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* For internal testing only.
|
* For internal testing only.
|
||||||
* This method exposed only for testing purposes!
|
* This method exposed only for testing purposes!
|
||||||
*
|
*
|
||||||
* @return Hashtable of entries
|
* @return Hashtable of entries
|
||||||
*/
|
*/
|
||||||
public java.util.Hashtable getEntryTable() {
|
public java.util.Hashtable getEntryTable() {
|
||||||
return fEntryTable;
|
return fEntryTable;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the load factor for the cache. The load factor determines how
|
* Returns the load factor for the cache. The load factor determines how
|
||||||
* much space is reclaimed when the cache exceeds its space limit.
|
* much space is reclaimed when the cache exceeds its space limit.
|
||||||
* @return double
|
* @return double
|
||||||
*/
|
*/
|
||||||
public double getLoadFactor() {
|
public double getLoadFactor() {
|
||||||
return fLoadFactor;
|
return fLoadFactor;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return The space by which the cache has overflown.
|
* @return The space by which the cache has overflown.
|
||||||
*/
|
*/
|
||||||
public int getOverflow() {
|
public int getOverflow() {
|
||||||
return fOverflow;
|
return fOverflow;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Ensures there is the specified amount of free space in the receiver,
|
* 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
|
* 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
|
* made available, false otherwise. May not be able to free enough space
|
||||||
* since some elements cannot be removed until they are saved.
|
* since some elements cannot be removed until they are saved.
|
||||||
*
|
*
|
||||||
* @param space Amount of space to free up
|
* @param space Amount of space to free up
|
||||||
*/
|
*/
|
||||||
protected boolean makeSpace(int space) {
|
protected boolean makeSpace(int space) {
|
||||||
|
|
||||||
int limit = fSpaceLimit;
|
int limit = fSpaceLimit;
|
||||||
if (fOverflow == 0) {
|
if (fOverflow == 0) {
|
||||||
/* if space is already available */
|
/* if space is already available */
|
||||||
if (fCurrentSpace + space <= limit) {
|
if (fCurrentSpace + space <= limit) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free up space by removing oldest entries */
|
/* Free up space by removing oldest entries */
|
||||||
int spaceNeeded = (int)((1 - fLoadFactor) * fSpaceLimit);
|
int spaceNeeded = (int)((1 - fLoadFactor) * fSpaceLimit);
|
||||||
spaceNeeded = (spaceNeeded > space) ? spaceNeeded : space;
|
spaceNeeded = (spaceNeeded > space) ? spaceNeeded : space;
|
||||||
LRUCacheEntry entry = fEntryQueueTail;
|
LRUCacheEntry entry = fEntryQueueTail;
|
||||||
|
|
||||||
while (fCurrentSpace + spaceNeeded > limit && entry != null) {
|
while (fCurrentSpace + spaceNeeded > limit && entry != null) {
|
||||||
this.privateRemoveEntry(entry, false, false);
|
this.privateRemoveEntry(entry, false, false);
|
||||||
entry = entry._fPrevious;
|
entry = entry._fPrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check again, since we may have aquired enough space */
|
/* check again, since we may have aquired enough space */
|
||||||
if (fCurrentSpace + space <= limit) {
|
if (fCurrentSpace + space <= limit) {
|
||||||
fOverflow = 0;
|
fOverflow = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update fOverflow */
|
/* update fOverflow */
|
||||||
fOverflow = fCurrentSpace + space - limit;
|
fOverflow = fCurrentSpace + space - limit;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of the reciever.
|
* Returns a new instance of the reciever.
|
||||||
*/
|
*/
|
||||||
protected abstract LRUCache newInstance(int size, int overflow);
|
protected abstract LRUCache newInstance(int size, int overflow);
|
||||||
/**
|
/**
|
||||||
* Answers the value in the cache at the given key.
|
* Answers the value in the cache at the given key.
|
||||||
* If the value is not in the cache, returns null
|
* If the value is not in the cache, returns null
|
||||||
*
|
*
|
||||||
* This function does not modify timestamps.
|
* This function does not modify timestamps.
|
||||||
*/
|
*/
|
||||||
public Object peek(Object key) {
|
public Object peek(Object key) {
|
||||||
|
|
||||||
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key);
|
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return entry._fValue;
|
return entry._fValue;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* For testing purposes only
|
* For testing purposes only
|
||||||
*/
|
*/
|
||||||
public void printStats() {
|
public void printStats() {
|
||||||
int forwardListLength = 0;
|
int forwardListLength = 0;
|
||||||
LRUCacheEntry entry = fEntryQueue;
|
LRUCacheEntry entry = fEntryQueue;
|
||||||
while(entry != null) {
|
while(entry != null) {
|
||||||
forwardListLength++;
|
forwardListLength++;
|
||||||
entry = entry._fNext;
|
entry = entry._fNext;
|
||||||
}
|
}
|
||||||
System.out.println("Forward length: " + forwardListLength); //$NON-NLS-1$
|
System.out.println("Forward length: " + forwardListLength); //$NON-NLS-1$
|
||||||
|
|
||||||
int backwardListLength = 0;
|
int backwardListLength = 0;
|
||||||
entry = fEntryQueueTail;
|
entry = fEntryQueueTail;
|
||||||
while(entry != null) {
|
while(entry != null) {
|
||||||
backwardListLength++;
|
backwardListLength++;
|
||||||
entry = entry._fPrevious;
|
entry = entry._fPrevious;
|
||||||
}
|
}
|
||||||
System.out.println("Backward length: " + backwardListLength); //$NON-NLS-1$
|
System.out.println("Backward length: " + backwardListLength); //$NON-NLS-1$
|
||||||
|
|
||||||
Enumeration keys = fEntryTable.keys();
|
Enumeration keys = fEntryTable.keys();
|
||||||
class Temp {
|
class Temp {
|
||||||
public Class fClass;
|
public Class fClass;
|
||||||
public int fCount;
|
public int fCount;
|
||||||
public Temp(Class aClass) {
|
public Temp(Class aClass) {
|
||||||
fClass = aClass;
|
fClass = aClass;
|
||||||
fCount = 1;
|
fCount = 1;
|
||||||
}
|
}
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Class: " + fClass + " has " + fCount + " entries."; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
|
return "Class: " + fClass + " has " + fCount + " entries."; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
java.util.HashMap h = new java.util.HashMap();
|
java.util.HashMap h = new java.util.HashMap();
|
||||||
while(keys.hasMoreElements()) {
|
while(keys.hasMoreElements()) {
|
||||||
entry = (LRUCacheEntry)fEntryTable.get(keys.nextElement());
|
entry = (LRUCacheEntry)fEntryTable.get(keys.nextElement());
|
||||||
Class key = entry._fValue.getClass();
|
Class key = entry._fValue.getClass();
|
||||||
Temp t = (Temp)h.get(key);
|
Temp t = (Temp)h.get(key);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
h.put(key, new Temp(key));
|
h.put(key, new Temp(key));
|
||||||
} else {
|
} else {
|
||||||
t.fCount++;
|
t.fCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator iter = h.keySet().iterator(); iter.hasNext();){
|
for (Iterator iter = h.keySet().iterator(); iter.hasNext();){
|
||||||
System.out.println(h.get(iter.next()));
|
System.out.println(h.get(iter.next()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Removes the entry from the entry queue.
|
* Removes the entry from the entry queue.
|
||||||
* Calls <code>privateRemoveEntry</code> with the external functionality enabled.
|
* Calls <code>privateRemoveEntry</code> with the external functionality enabled.
|
||||||
*
|
*
|
||||||
* @param shuffle indicates whether we are just shuffling the queue
|
* @param shuffle indicates whether we are just shuffling the queue
|
||||||
* (i.e., the entry table is left alone).
|
* (i.e., the entry table is left alone).
|
||||||
*/
|
*/
|
||||||
protected void privateRemoveEntry (LRUCacheEntry entry, boolean shuffle) {
|
protected void privateRemoveEntry (LRUCacheEntry entry, boolean shuffle) {
|
||||||
privateRemoveEntry(entry, shuffle, true);
|
privateRemoveEntry(entry, shuffle, true);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Removes the entry from the entry queue. If <i>external</i> is true, the entry is removed
|
* Removes the entry from the entry queue. If <i>external</i> is true, the entry is removed
|
||||||
* without checking if it can be removed. It is assumed that the client has already closed
|
* 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).
|
* the element it is trying to remove (or will close it promptly).
|
||||||
*
|
*
|
||||||
* If <i>external</i> is false, and the entry could not be closed, it is not removed and the
|
* If <i>external</i> is false, and the entry could not be closed, it is not removed and the
|
||||||
* pointers are not changed.
|
* pointers are not changed.
|
||||||
*
|
*
|
||||||
* @param shuffle indicates whether we are just shuffling the queue
|
* @param shuffle indicates whether we are just shuffling the queue
|
||||||
* (i.e., the entry table is left alone).
|
* (i.e., the entry table is left alone).
|
||||||
*/
|
*/
|
||||||
protected void privateRemoveEntry(LRUCacheEntry entry, boolean shuffle, boolean external) {
|
protected void privateRemoveEntry(LRUCacheEntry entry, boolean shuffle, boolean external) {
|
||||||
|
|
||||||
if (!shuffle) {
|
if (!shuffle) {
|
||||||
if (external) {
|
if (external) {
|
||||||
fEntryTable.remove(entry._fKey);
|
fEntryTable.remove(entry._fKey);
|
||||||
fCurrentSpace -= entry._fSpace;
|
fCurrentSpace -= entry._fSpace;
|
||||||
privateNotifyDeletionFromCache(entry);
|
privateNotifyDeletionFromCache(entry);
|
||||||
} else {
|
} else {
|
||||||
if (!close(entry)) return;
|
if (!close(entry)) return;
|
||||||
// buffer close will recursively call #privateRemoveEntry with external==true
|
// buffer close will recursively call #privateRemoveEntry with external==true
|
||||||
// thus entry will already be removed if reaching this point.
|
// thus entry will already be removed if reaching this point.
|
||||||
if (fEntryTable.get(entry._fKey) == null){
|
if (fEntryTable.get(entry._fKey) == null){
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
// basic removal
|
// basic removal
|
||||||
fEntryTable.remove(entry._fKey);
|
fEntryTable.remove(entry._fKey);
|
||||||
fCurrentSpace -= entry._fSpace;
|
fCurrentSpace -= entry._fSpace;
|
||||||
privateNotifyDeletionFromCache(entry);
|
privateNotifyDeletionFromCache(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
LRUCacheEntry previous = entry._fPrevious;
|
||||||
LRUCacheEntry previous = entry._fPrevious;
|
LRUCacheEntry next = entry._fNext;
|
||||||
LRUCacheEntry next = entry._fNext;
|
|
||||||
|
/* if this was the first entry */
|
||||||
/* if this was the first entry */
|
if (previous == null) {
|
||||||
if (previous == null) {
|
fEntryQueue = next;
|
||||||
fEntryQueue = next;
|
} else {
|
||||||
} else {
|
previous._fNext = next;
|
||||||
previous._fNext = next;
|
}
|
||||||
}
|
/* if this was the last entry */
|
||||||
/* if this was the last entry */
|
if (next == null) {
|
||||||
if (next == null) {
|
fEntryQueueTail = previous;
|
||||||
fEntryQueueTail = previous;
|
} else {
|
||||||
} else {
|
next._fPrevious = previous;
|
||||||
next._fPrevious = previous;
|
}
|
||||||
}
|
}
|
||||||
}
|
/**
|
||||||
/**
|
* Sets the value in the cache at the given key. Returns the value.
|
||||||
* Sets the value in the cache at the given key. Returns the value.
|
*
|
||||||
*
|
* @param key Key of object to add.
|
||||||
* @param key Key of object to add.
|
* @param value Value of object to add.
|
||||||
* @param value Value of object to add.
|
* @return added value.
|
||||||
* @return added value.
|
*/
|
||||||
*/
|
public Object put(Object key, Object value) {
|
||||||
public Object put(Object key, Object value) {
|
/* attempt to rid ourselves of the overflow, if there is any */
|
||||||
/* attempt to rid ourselves of the overflow, if there is any */
|
if (fOverflow > 0)
|
||||||
if (fOverflow > 0)
|
shrink();
|
||||||
shrink();
|
|
||||||
|
/* Check whether there's an entry in the cache */
|
||||||
/* Check whether there's an entry in the cache */
|
int newSpace = spaceFor (key, value);
|
||||||
int newSpace = spaceFor (key, value);
|
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get (key);
|
||||||
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get (key);
|
|
||||||
|
if (entry != null) {
|
||||||
if (entry != null) {
|
|
||||||
|
/**
|
||||||
/**
|
* Replace the entry in the cache if it would not overflow
|
||||||
* Replace the entry in the cache if it would not overflow
|
* the cache. Otherwise flush the entry and re-add it so as
|
||||||
* the cache. Otherwise flush the entry and re-add it so as
|
* to keep cache within budget
|
||||||
* to keep cache within budget
|
*/
|
||||||
*/
|
int oldSpace = entry._fSpace;
|
||||||
int oldSpace = entry._fSpace;
|
int newTotal = fCurrentSpace - oldSpace + newSpace;
|
||||||
int newTotal = fCurrentSpace - oldSpace + newSpace;
|
if (newTotal <= fSpaceLimit) {
|
||||||
if (newTotal <= fSpaceLimit) {
|
updateTimestamp (entry);
|
||||||
updateTimestamp (entry);
|
entry._fValue = value;
|
||||||
entry._fValue = value;
|
entry._fSpace = newSpace;
|
||||||
entry._fSpace = newSpace;
|
fCurrentSpace = newTotal;
|
||||||
fCurrentSpace = newTotal;
|
fOverflow = 0;
|
||||||
fOverflow = 0;
|
return value;
|
||||||
return value;
|
}
|
||||||
} else {
|
privateRemoveEntry (entry, false, false);
|
||||||
privateRemoveEntry (entry, false, false);
|
}
|
||||||
}
|
|
||||||
}
|
// attempt to make new space
|
||||||
|
makeSpace(newSpace);
|
||||||
// attempt to make new space
|
|
||||||
makeSpace(newSpace);
|
// add without worring about space, it will
|
||||||
|
// be handled later in a makeSpace call
|
||||||
// add without worring about space, it will
|
privateAdd (key, value, newSpace);
|
||||||
// be handled later in a makeSpace call
|
|
||||||
privateAdd (key, value, newSpace);
|
return value;
|
||||||
|
}
|
||||||
return value;
|
/**
|
||||||
}
|
* Removes and returns the value in the cache for the given key.
|
||||||
/**
|
* If the key is not in the cache, returns null.
|
||||||
* 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.
|
||||||
* @param key Key of object to remove from cache.
|
*/
|
||||||
* @return Value removed from cache.
|
public Object remove(Object key) {
|
||||||
*/
|
return removeKey(key);
|
||||||
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.
|
||||||
* Sets the load factor for the cache. The load factor determines how
|
* @param newLoadFactor double
|
||||||
* much space is reclaimed when the cache exceeds its space limit.
|
* @throws IllegalArgumentException when the new load factor is not in (0.0, 1.0]
|
||||||
* @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)
|
||||||
public void setLoadFactor(double newLoadFactor) throws IllegalArgumentException {
|
fLoadFactor = newLoadFactor;
|
||||||
if(newLoadFactor <= 1.0 && newLoadFactor > 0.0)
|
else
|
||||||
fLoadFactor = newLoadFactor;
|
throw new IllegalArgumentException("cache.invalidLoadFactor"); //$NON-NLS-1$
|
||||||
else
|
}
|
||||||
throw new IllegalArgumentException("cache.invalidLoadFactor"); //$NON-NLS-1$
|
/**
|
||||||
}
|
* Sets the maximum amount of space that the cache can store
|
||||||
/**
|
*
|
||||||
* Sets the maximum amount of space that the cache can store
|
* @param limit Number of units of cache space
|
||||||
*
|
*/
|
||||||
* @param limit Number of units of cache space
|
public void setSpaceLimit(int limit) {
|
||||||
*/
|
if (limit < fSpaceLimit) {
|
||||||
public void setSpaceLimit(int limit) {
|
makeSpace(fSpaceLimit - limit);
|
||||||
if (limit < fSpaceLimit) {
|
}
|
||||||
makeSpace(fSpaceLimit - limit);
|
fSpaceLimit = limit;
|
||||||
}
|
}
|
||||||
fSpaceLimit = limit;
|
/**
|
||||||
}
|
* Attempts to shrink the cache if it has overflown.
|
||||||
/**
|
* Returns true if the cache shrinks to less than or equal to <code>fSpaceLimit</code>.
|
||||||
* Attempts to shrink the cache if it has overflown.
|
*/
|
||||||
* Returns true if the cache shrinks to less than or equal to <code>fSpaceLimit</code>.
|
public boolean shrink() {
|
||||||
*/
|
if (fOverflow > 0)
|
||||||
public boolean shrink() {
|
return makeSpace(0);
|
||||||
if (fOverflow > 0)
|
return true;
|
||||||
return makeSpace(0);
|
}
|
||||||
return true;
|
/**
|
||||||
}
|
* Returns a String that represents the value of this object. This method
|
||||||
/**
|
* is for debugging purposes only.
|
||||||
* Returns a String that represents the value of this object. This method
|
*/
|
||||||
* is for debugging purposes only.
|
public String toString() {
|
||||||
*/
|
return
|
||||||
public String toString() {
|
"OverflowingLRUCache " + this.fillingRatio() + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
return
|
this.toStringContents();
|
||||||
"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.
|
||||||
* Updates the timestamp for the given entry, ensuring that the queue is
|
*
|
||||||
* kept in correct order. The entry must exist.
|
* <p>This method will do nothing if timestamps have been disabled.
|
||||||
*
|
*/
|
||||||
* <p>This method will do nothing if timestamps have been disabled.
|
protected void updateTimestamp(LRUCacheEntry entry) {
|
||||||
*/
|
if (fTimestampsOn) {
|
||||||
protected void updateTimestamp(LRUCacheEntry entry) {
|
entry._fTimestamp = fTimestampCounter++;
|
||||||
if (fTimestampsOn) {
|
if (fEntryQueue != entry) {
|
||||||
entry._fTimestamp = fTimestampCounter++;
|
this.privateRemoveEntry(entry, true);
|
||||||
if (fEntryQueue != entry) {
|
this.privateAddEntry(entry, true);
|
||||||
this.privateRemoveEntry(entry, true);
|
}
|
||||||
this.privateAddEntry(entry, true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue