diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 4a29a3f0266..652f5082375 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,17 @@ +2004-04-04 Alain Magloire + + More support for external headers. + Cleanup of the CElement.close() calls. + + * model/org/eclipse/cdt/internal/core/model/Archive.java + * model/org/eclipse/cdt/internal/core/model/Binary.java + * model/org/eclipse/cdt/internal/core/model/CElement.java + * model/org/eclipse/cdt/internal/core/model/CModelManager.java + * model/org/eclipse/cdt/internal/core/model/CProject.java + * model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java + * model/org/eclipse/cdt/internal/core/model/ExternaltranslationUnit.java + * model/org/eclipse/cdt/internal/core/model/IncludeReference.java + 2004-04-03 Alain Magloire Draft work on LibraryReferences and IncludeReferences. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java index 0eb0afee7ae..a3c2297f303 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java @@ -13,6 +13,7 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -87,4 +88,16 @@ public class Archive extends Openable implements IArchive { public boolean exists() { return getResource() != null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) + */ + protected void closing(Object info) throws CModelException { + ICProject cproject = getCProject(); + CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(cproject); + if (pinfo != null && pinfo.vLib != null) { + pinfo.vLib.removeChild(this); + } + super.closing(info); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java index 754185f6ead..f33f0acbe41 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -357,4 +358,15 @@ public class Binary extends Openable implements IBinary { public boolean exists() { return getResource() != null; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) + */ + protected void closing(Object info) throws CModelException { + ICProject cproject = getCProject(); + CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(cproject); + if (pinfo != null && pinfo.vBin != null) { + pinfo.vBin.removeChild(this); + } + super.closing(info); + } } 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 40409dbbd56..0830eff8be7 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 @@ -302,19 +302,21 @@ public abstract class CElement extends PlatformObject implements ICElement { * @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); - } + //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); + //} + CModelManager.getDefault().releaseCElement(this); } + /** * This element is being closed. Do any necessary cleanup. */ 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 ddc87b54bc0..de31e767a8d 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 @@ -288,17 +288,18 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } // try in the outputEntry and save in the container + // But do not create an ICElement since they are not in the Model per say if (celement == null && !checkIfBinary && cproject.isOnOutputEntry(file)) { IBinaryFile bin = createBinaryFile(file); if (bin != null) { if (bin.getType() == IBinaryFile.ARCHIVE) { ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin); - vlib.addChild(archive); + celement = new Archive(vlib, file, (IBinaryArchive)bin); + vlib.addChild(celement); } else { BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - IBinary binary = new Binary(vbin, file, (IBinaryObject)bin); - vbin.addChild(binary); + celement = new Binary(vbin, file, (IBinaryObject)bin); + vbin.addChild(celement); } } } @@ -349,15 +350,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } // try in the outputEntry and save in the container + // But do not create a ICElement since they are not in the Model per say if (celement == null) { if (bin.getType() == IBinaryFile.ARCHIVE) { ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin); - vlib.addChild(archive); + celement = new Archive(vlib, file, (IBinaryArchive)bin); + vlib.addChild(celement); } else { BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - IBinary binary = new Binary(vbin, file, (IBinaryObject)bin); - vbin.addChild(binary); + celement = new Binary(vbin, file, (IBinaryObject)bin); + vbin.addChild(celement); } } } catch (CModelException e) { @@ -375,87 +377,65 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe //System.out.println("RELEASE " + celement.getElementName()); // Remove from the containers. - int type = celement.getElementType(); - if (type == ICElement.C_ARCHIVE) { -//System.out.println("RELEASE Archive " + cfile.getElementName()); - CProject cproj = (CProject)celement.getCProject(); - ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); - container.removeChild(celement); - CElementDelta delta = new CElementDelta(getCModel()); - delta.changed(container, ICElementDelta.CHANGED); - registerCModelDelta(delta); - } else if (type == ICElement.C_BINARY) { -//System.out.println("RELEASE Binary " + celement.getElementName()); - CProject cproj = (CProject)celement.getCProject(); - BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); - container.removeChild(celement); - CElementDelta delta = new CElementDelta(getCModel()); - delta.changed(container, ICElementDelta.CHANGED); - registerCModelDelta(delta); - } - if (celement instanceof IParent) { - if (peekAtInfo(celement) != null) { - CElementInfo info = ((CElement)celement).getElementInfo(); - if (info != null) { - ICElement[] children = info.getChildren(); - for (int i = 0; i < children.length; i++) { - releaseCElement(children[i]); - } - // Make sure we destroy the BinaryContainer and ArchiveContainer - // Since they are not part of the children. - if (info instanceof CProjectInfo) { - CProjectInfo pinfo = (CProjectInfo) info; - if (pinfo.vBin != null) { - releaseCElement(pinfo.vBin); - } - if (pinfo.vLib != null) { - releaseCElement(pinfo.vLib); - } - pinfo.resetCaches(); - IProject project = celement.getCProject().getProject(); - removeBinaryRunner(project); + CElementInfo info = (CElementInfo)peekAtInfo(celement); + if (info != null) { + ICElement[] children = info.getChildren(); + for (int i = 0; i < children.length; i++) { + releaseCElement(children[i]); + } + // Make sure any object specifics not part of the children be destroy + // For example the CProject needs to destroy the BinaryContainer and ArchiveContainer + if (celement instanceof CElement) { + try { + ((CElement)celement).closing(info); + } catch (CModelException e) { + // } } - } else { - // If an entire folder was deleted we need to update the - // BinaryContainer/ArchiveContainer also. + } + + // If an entire folder was deleted we need to update the + // BinaryContainer/ArchiveContainer also. + if (celement.getElementType() == ICElement.C_CCONTAINER) { ICProject cproject = celement.getCProject(); - CProjectInfo info = (CProjectInfo)peekAtInfo(cproject); - if (info != null && info.vBin != null) { - if (peekAtInfo(info.vBin) != null) { - ICElement[] bins = info.vBin.getChildren(); + CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject); + ArrayList list = new ArrayList(5); + if (pinfo != null && pinfo.vBin != null) { + if (peekAtInfo(pinfo.vBin) != null) { + ICElement[] bins = pinfo.vBin.getChildren(); for (int i = 0; i < bins.length; i++) { if (celement.getPath().isPrefixOf(bins[i].getPath())) { - CElementDelta delta = new CElementDelta(getCModel()); - delta.changed(info.vBin, ICElementDelta.CHANGED); - registerCModelDelta(delta); - info.vBin.removeChild(bins[i]); + //pinfo.vBin.removeChild(bins[i]); + list.add(bins[i]); } } } } - if (info != null && info.vLib != null) { - if (peekAtInfo(info.vLib) != null) { - ICElement[] ars = info.vLib.getChildren(); + if (pinfo != null && pinfo.vLib != null) { + if (peekAtInfo(pinfo.vLib) != null) { + ICElement[] ars = pinfo.vLib.getChildren(); for (int i = 0; i < ars.length; i++) { if (celement.getPath().isPrefixOf(ars[i].getPath())) { - CElementDelta delta = new CElementDelta(getCModel()); - delta.changed(info.vLib, ICElementDelta.CHANGED); - registerCModelDelta(delta); - info.vLib.removeChild(ars[i]); + //pinfo.vLib.removeChild(ars[i]); + list.add(ars[i]); } } } } + // release any binary/archive that was in the path + for (int i = 0; i < list.size(); i++) { + ICElement b = (ICElement)list.get(i); + releaseCElement(b); + } } } // Remove the child from the parent list. - Parent parent = (Parent)celement.getParent(); - if (parent != null && peekAtInfo(parent) != null) { - parent.removeChild(celement); - } + //Parent parent = (Parent)celement.getParent(); + //if (parent != null && peekAtInfo(parent) != null) { + // parent.removeChild(celement); + //} removeInfo(celement); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index cc1c654453b..15acb4568d2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -585,6 +585,7 @@ public class CProject extends Openable implements ICProject { public Object[] getNonCResources() throws CModelException { return ((CProjectInfo) getElementInfo()).getNonCResources(getResource()); } + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 18acc967653..79bfc678a9d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -125,24 +125,16 @@ public class DeltaProcessor { } } + // It is not a C resource if the parent is a Binary/ArchiveContainer + if (celement != null && resource.getType() == IResource.FILE) { + ICElement parent = celement.getParent(); + if (parent instanceof IArchiveContainer || parent instanceof IBinaryContainer) { + celement = null; + } + } return celement; } - /** - * Creates the create corresponding to this resource. - * Returns null if none was found. - */ - protected ICElement createElement(IPath path) { - return CModelManager.getDefault().create(path); - } - - /** - * Release the Element and cleaning. - */ - protected void releaseCElement(ICElement celement) { - CModelManager.getDefault().releaseCElement(celement); - } - /** * Adds the given child handle to its parent's cache of children. */ @@ -154,6 +146,73 @@ public class DeltaProcessor { } } + /** + * Removes the given element from its parents cache of children. If the + * element does not have a parent, or the parent is not currently open, + * this has no effect. + */ + private void removeFromParentInfo(ICElement child) { + CModelManager factory = CModelManager.getDefault(); + + // Remove the child from the parent list. + ICElement parent = child.getParent(); + if (parent != null && parent instanceof Parent && factory.peekAtInfo(parent) != null) { + ((Parent)parent).removeChild(child); + } + } + + /** + * Release the Element and cleaning. + */ + protected void releaseCElement(ICElement celement) { + CModelManager factory = CModelManager.getDefault(); + int type = celement.getElementType(); + if (type == ICElement.C_ARCHIVE) { + ICProject cproject = celement.getCProject(); + IArchiveContainer container = cproject.getArchiveContainer(); + fCurrentDelta.changed(container, ICElementDelta.CHANGED); + } else if (type == ICElement.C_BINARY) { + ICProject cproject = celement.getCProject(); + IBinaryContainer container = cproject.getBinaryContainer(); + fCurrentDelta.changed(container, ICElementDelta.CHANGED); + } else { + // If an entire folder was deleted we need to update the + // BinaryContainer/ArchiveContainer also. + ICProject cproject = celement.getCProject(); + CProjectInfo pinfo = (CProjectInfo)factory.peekAtInfo(cproject); + if (pinfo != null && pinfo.vBin != null) { + if (factory.peekAtInfo(pinfo.vBin) != null) { + ICElement[] bins = pinfo.vBin.getChildren(); + for (int i = 0; i < bins.length; i++) { + if (celement.getPath().isPrefixOf(bins[i].getPath())) { + fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + } + } + } + } + if (pinfo != null && pinfo.vLib != null) { + if (factory.peekAtInfo(pinfo.vLib) != null) { + ICElement[] ars = pinfo.vLib.getChildren(); + for (int i = 0; i < ars.length; i++) { + if (celement.getPath().isPrefixOf(ars[i].getPath())) { + fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + } + } + } + } + } + removeFromParentInfo(celement); + factory.releaseCElement(celement); + } + + /** + * Creates the create corresponding to this resource. + * Returns null if none was found. + */ + protected ICElement createElement(IPath path) { + return CModelManager.getDefault().create(path); + } + /** * Processing for an element that has been added: