Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2003-03-19 20:19:48 +0000
committerAlain Magloire2003-03-19 20:19:48 +0000
commit31945e2ce6c2ed250b83c71797266f0091cba296 (patch)
treecaa3321743f01e598af0814202ebfdc73c34dd27 /core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java
parent305ae53cf558016d6c23e703a24b043a55458f65 (diff)
downloadorg.eclipse.cdt-31945e2ce6c2ed250b83c71797266f0091cba296.tar.gz
org.eclipse.cdt-31945e2ce6c2ed250b83c71797266f0091cba296.tar.xz
org.eclipse.cdt-31945e2ce6c2ed250b83c71797266f0091cba296.zip
Changes from Oda introducing LRUCaching
and the notion of WorkingCopy in the mode.
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java156
1 files changed, 143 insertions, 13 deletions
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 5efd24e05c1..9ef9f1afadb 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
@@ -4,15 +4,17 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+import org.eclipse.cdt.core.model.ICOpenable;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ICRoot;
+import org.eclipse.cdt.core.model.IParent;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.core.runtime.IPath;
-
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ICRoot;
-import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.cdt.core.model.CModelException;
public abstract class CElement extends PlatformObject implements ICElement {
@@ -20,8 +22,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
protected ICElement fParent;
- protected CElementInfo fCElementInfo;
-
protected String fName;
protected int fStartPos;
@@ -37,7 +37,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
fParent= parent;
fName= name;
fType= type;
- fCElementInfo = null;
}
// setters
@@ -89,7 +88,14 @@ public abstract class CElement extends PlatformObject implements ICElement {
}
public boolean isReadOnly () {
- return getElementInfo().isReadOnly();
+ try {
+ IResource r = getUnderlyingResource();
+ if (r != null) {
+ return r.isReadOnly();
+ }
+ } catch (CModelException e) {
+ }
+ return false;
}
public boolean isStructureKnown() throws CModelException {
@@ -206,10 +212,22 @@ public abstract class CElement extends PlatformObject implements ICElement {
}
public CElementInfo getElementInfo () {
- if (fCElementInfo == null) {
- fCElementInfo = createElementInfo();
+ try {
+ CModelManager manager;
+ synchronized(manager = CModelManager.getDefault()){
+ Object info = manager.getInfo(this);
+ if (info == null) {
+ openHierarchy();
+ info= manager.getInfo(this);
+ if (info == null) {
+ throw newNotPresentException();
+ }
+ }
+ return (CElementInfo)info;
+ }
+ } catch(CModelException e) {
+ return null;
}
- return fCElementInfo;
}
public String toString() {
@@ -264,4 +282,116 @@ public abstract class CElement extends PlatformObject implements ICElement {
protected void runOperation(CModelOperation operation, IProgressMonitor monitor) throws CModelException {
CModelManager.getDefault().runOperation(operation, monitor);
}
+
+ /**
+ * Close the C Element
+ * @throws CModelException
+ */
+ public void close() throws CModelException {
+ Object info = CModelManager.getDefault().peekAtInfo(this);
+ if (info != null) {
+ if (this instanceof IParent) {
+ ICElement[] children = ((CElementInfo) info).getChildren();
+ for (int i = 0, size = children.length; i < size; ++i) {
+ CElement child = (CElement) children[i];
+ child.close();
+ }
+ }
+ closing(info);
+ CModelManager.getDefault().removeInfo(this);
+ }
+ }
+ /**
+ * This element is being closed. Do any necessary cleanup.
+ */
+ protected void closing(Object info) throws CModelException {
+ }
+
+ /**
+ * This element has just been opened. Do any necessary setup.
+ */
+ protected void opening(Object info) {
+ }
+
+ /**
+ * Return the first instance of IOpenable in the parent
+ * hierarchy of this element.
+ *
+ * <p>Subclasses that are not IOpenable's must override this method.
+ */
+ public ICOpenable getOpenableParent() {
+
+ return (ICOpenable)fParent;
+ }
+
+
+ /**
+ * Opens this element and all parents that are not already open.
+ *
+ * @exception CModelException this element is not present or accessible
+ */
+ protected void openHierarchy() throws CModelException {
+ if (this instanceof ICOpenable) {
+ ((CResource) this).openWhenClosed(null);
+ } else {
+ CResource openableParent = (CResource)getOpenableParent();
+ if (openableParent != null) {
+ CElementInfo openableParentInfo = (CElementInfo) CModelManager.getDefault().getInfo((ICElement) openableParent);
+ if (openableParentInfo == null) {
+ openableParent.openWhenClosed(null);
+ } else {
+ CModelManager.getDefault().putInfo( this, createElementInfo());
+ }
+ }
+ }
+ }
+ /**
+ * Returns true if this element is an ancestor of the given element,
+ * otherwise false.
+ */
+ protected boolean isAncestorOf(ICElement e) {
+ ICElement parent= e.getParent();
+ while (parent != null && !parent.equals(this)) {
+ parent= parent.getParent();
+ }
+ return parent != null;
+ }
+
+ /**
+ * Creates and returns and not present exception for this element.
+ */
+ protected CModelException newNotPresentException() {
+ return new CModelException(new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
+ }
+ /**
+ * Removes all cached info from the C Model, including all children,
+ * but does not close this element.
+ */
+ protected void removeInfo() {
+ Object info = CModelManager.getDefault().peekAtInfo(this);
+ if (info != null) {
+ if (this instanceof IParent) {
+ ICElement[] children = ((CElementInfo)info).getChildren();
+ for (int i = 0, size = children.length; i < size; ++i) {
+ CElement child = (CElement) children[i];
+ child.removeInfo();
+ }
+ }
+ CModelManager.getDefault().removeInfo(this);
+ }
+ }
+
+ /**
+ * Returns the hash code for this Java element. By default,
+ * the hash code for an element is a combination of its name
+ * and parent's hash code. Elements with other requirements must
+ * override this method.
+ */
+ // CHECKPOINT: making not equal objects seem equal
+ // What elements should override this?
+ public int hashCode() {
+ if (fParent == null) return super.hashCode();
+ return Util.combineHashCodes(fName.hashCode(), fParent.hashCode());
+ }
+
}

Back to the top