1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

More support for external headers

and cleanup of the CElement.close() method
This commit is contained in:
Alain Magloire 2004-04-06 05:36:32 +00:00
parent 70aaf923d3
commit ceefe291d8
9 changed files with 306 additions and 98 deletions

View file

@ -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 2004-04-03 Alain Magloire
Draft work on LibraryReferences and IncludeReferences. Draft work on LibraryReferences and IncludeReferences.

View file

@ -13,6 +13,7 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; 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.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -87,4 +88,16 @@ public class Archive extends Openable implements IArchive {
public boolean exists() { public boolean exists() {
return getResource() != null; 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);
}
} }

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; 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.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -357,4 +358,15 @@ public class Binary extends Openable implements IBinary {
public boolean exists() { public boolean exists() {
return getResource() != null; 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);
}
} }

View file

@ -302,19 +302,21 @@ public abstract class CElement extends PlatformObject implements ICElement {
* @throws CModelException * @throws CModelException
*/ */
public void close() throws CModelException { public void close() throws CModelException {
Object info = CModelManager.getDefault().peekAtInfo(this); //Object info = CModelManager.getDefault().peekAtInfo(this);
if (info != null) { //if (info != null) {
if (this instanceof IParent) { // if (this instanceof IParent) {
ICElement[] children = ((CElementInfo) info).getChildren(); // ICElement[] children = ((CElementInfo) info).getChildren();
for (int i = 0, size = children.length; i < size; ++i) { // for (int i = 0, size = children.length; i < size; ++i) {
CElement child = (CElement) children[i]; // CElement child = (CElement) children[i];
child.close(); // child.close();
} // }
} // }
closing(info); // closing(info);
CModelManager.getDefault().removeInfo(this); // CModelManager.getDefault().removeInfo(this);
} //}
CModelManager.getDefault().releaseCElement(this);
} }
/** /**
* This element is being closed. Do any necessary cleanup. * This element is being closed. Do any necessary cleanup.
*/ */

View file

@ -288,17 +288,18 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
// try in the outputEntry and save in the container // 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)) { if (celement == null && !checkIfBinary && cproject.isOnOutputEntry(file)) {
IBinaryFile bin = createBinaryFile(file); IBinaryFile bin = createBinaryFile(file);
if (bin != null) { if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin); celement = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(archive); vlib.addChild(celement);
} else { } else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
IBinary binary = new Binary(vbin, file, (IBinaryObject)bin); celement = new Binary(vbin, file, (IBinaryObject)bin);
vbin.addChild(binary); vbin.addChild(celement);
} }
} }
} }
@ -349,15 +350,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
// try in the outputEntry and save in the container // 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 (celement == null) {
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin); celement = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(archive); vlib.addChild(celement);
} else { } else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
IBinary binary = new Binary(vbin, file, (IBinaryObject)bin); celement = new Binary(vbin, file, (IBinaryObject)bin);
vbin.addChild(binary); vbin.addChild(celement);
} }
} }
} catch (CModelException e) { } catch (CModelException e) {
@ -375,87 +377,65 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
//System.out.println("RELEASE " + celement.getElementName()); //System.out.println("RELEASE " + celement.getElementName());
// Remove from the containers. // 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 (celement instanceof IParent) {
if (peekAtInfo(celement) != null) { CElementInfo info = (CElementInfo)peekAtInfo(celement);
CElementInfo info = ((CElement)celement).getElementInfo(); if (info != null) {
if (info != null) { ICElement[] children = info.getChildren();
ICElement[] children = info.getChildren(); for (int i = 0; i < children.length; i++) {
for (int i = 0; i < children.length; i++) { releaseCElement(children[i]);
releaseCElement(children[i]); }
} // Make sure any object specifics not part of the children be destroy
// Make sure we destroy the BinaryContainer and ArchiveContainer // For example the CProject needs to destroy the BinaryContainer and ArchiveContainer
// Since they are not part of the children. if (celement instanceof CElement) {
if (info instanceof CProjectInfo) { try {
CProjectInfo pinfo = (CProjectInfo) info; ((CElement)celement).closing(info);
if (pinfo.vBin != null) { } catch (CModelException e) {
releaseCElement(pinfo.vBin); //
}
if (pinfo.vLib != null) {
releaseCElement(pinfo.vLib);
}
pinfo.resetCaches();
IProject project = celement.getCProject().getProject();
removeBinaryRunner(project);
} }
} }
} 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(); ICProject cproject = celement.getCProject();
CProjectInfo info = (CProjectInfo)peekAtInfo(cproject); CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject);
if (info != null && info.vBin != null) { ArrayList list = new ArrayList(5);
if (peekAtInfo(info.vBin) != null) { if (pinfo != null && pinfo.vBin != null) {
ICElement[] bins = info.vBin.getChildren(); if (peekAtInfo(pinfo.vBin) != null) {
ICElement[] bins = pinfo.vBin.getChildren();
for (int i = 0; i < bins.length; i++) { for (int i = 0; i < bins.length; i++) {
if (celement.getPath().isPrefixOf(bins[i].getPath())) { if (celement.getPath().isPrefixOf(bins[i].getPath())) {
CElementDelta delta = new CElementDelta(getCModel()); //pinfo.vBin.removeChild(bins[i]);
delta.changed(info.vBin, ICElementDelta.CHANGED); list.add(bins[i]);
registerCModelDelta(delta);
info.vBin.removeChild(bins[i]);
} }
} }
} }
} }
if (info != null && info.vLib != null) { if (pinfo != null && pinfo.vLib != null) {
if (peekAtInfo(info.vLib) != null) { if (peekAtInfo(pinfo.vLib) != null) {
ICElement[] ars = info.vLib.getChildren(); ICElement[] ars = pinfo.vLib.getChildren();
for (int i = 0; i < ars.length; i++) { for (int i = 0; i < ars.length; i++) {
if (celement.getPath().isPrefixOf(ars[i].getPath())) { if (celement.getPath().isPrefixOf(ars[i].getPath())) {
CElementDelta delta = new CElementDelta(getCModel()); //pinfo.vLib.removeChild(ars[i]);
delta.changed(info.vLib, ICElementDelta.CHANGED); list.add(ars[i]);
registerCModelDelta(delta);
info.vLib.removeChild(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. // Remove the child from the parent list.
Parent parent = (Parent)celement.getParent(); //Parent parent = (Parent)celement.getParent();
if (parent != null && peekAtInfo(parent) != null) { //if (parent != null && peekAtInfo(parent) != null) {
parent.removeChild(celement); // parent.removeChild(celement);
} //}
removeInfo(celement); removeInfo(celement);
} }

View file

@ -585,6 +585,7 @@ public class CProject extends Openable implements ICProject {
public Object[] getNonCResources() throws CModelException { public Object[] getNonCResources() throws CModelException {
return ((CProjectInfo) getElementInfo()).getNonCResources(getResource()); return ((CProjectInfo) getElementInfo()).getNonCResources(getResource());
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object)
*/ */

View file

@ -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; 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. * 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:<ul> * Processing for an element that has been added:<ul>
* <li>If the element is a project, do nothing, and do not process * <li>If the element is a project, do nothing, and do not process

View file

@ -0,0 +1,84 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* ExternalTranslationUnit
*/
public class ExternalTranslationUnit extends TranslationUnit {
IPath fPath;
/**
* @param parent
* @param path
*/
public ExternalTranslationUnit(ICElement parent, IPath path) {
super(parent, path);
fPath = path;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException {
// create buffer - translation units only use default buffer factory
BufferManager bufManager = getBufferManager();
IBuffer buffer = getBufferFactory().createBuffer(this);
if (buffer == null)
return null;
// set the buffer source
if (buffer.getCharacters() == null){
IPath path = this.getPath();
File file = path.toFile();
if (file != null && file.isFile()) {
try {
InputStream stream = new FileInputStream(file);
buffer.setContents(Util.getInputStreamAsCharArray(stream, (int)file.length(), null));
} catch (IOException e) {
buffer.setContents(new char[0]);
}
} else {
buffer.setContents(new char[0]);
}
}
// add buffer to buffer cache
bufManager.addBuffer(buffer);
// listen to buffer changes
buffer.addBufferChangedListener(this);
return buffer;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
public IPath getPath() {
return fPath;
}
}

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.io.File;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
@ -21,6 +23,7 @@ import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
/** /**
* IncludeReference * IncludeReference
@ -28,6 +31,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class IncludeReference extends Openable implements IIncludeReference { public class IncludeReference extends Openable implements IIncludeReference {
IIncludeEntry fIncludeEntry; IIncludeEntry fIncludeEntry;
IPath fPath;
/** /**
* @param parent * @param parent
@ -35,8 +39,13 @@ public class IncludeReference extends Openable implements IIncludeReference {
* @param type * @param type
*/ */
public IncludeReference(ICProject cproject, IIncludeEntry entry) { public IncludeReference(ICProject cproject, IIncludeEntry entry) {
super(cproject, null, entry.getIncludePath().toString(), ICElement.C_VCONTAINER); this(cproject, entry, entry.getIncludePath());
}
public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) {
super(celement, null, path.toString(), ICElement.C_VCONTAINER);
fIncludeEntry = entry; fIncludeEntry = entry;
fPath = path;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -64,7 +73,7 @@ public class IncludeReference extends Openable implements IIncludeReference {
* @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) * @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource)
*/ */
protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException {
return false; return computeChildren(info, underlyingResource);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -73,4 +82,38 @@ public class IncludeReference extends Openable implements IIncludeReference {
public IPath getAffectedPath() { public IPath getAffectedPath() {
return fIncludeEntry.getPath(); return fIncludeEntry.getPath();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CContainer#computeChildren(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.resources.IResource)
*/
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
ArrayList vChildren = new ArrayList();
final CModelManager factory = CModelManager.getDefault();
File file = fIncludeEntry.getIncludePath().toFile();
String[] names = null;
if (file != null && file.isDirectory()) {
names = file.list();
}
if (names != null) {
IPath path = new Path(file.getAbsolutePath());
for (int i = 0; i < names.length; i++) {
File child = new File(file, names[i]);
ICElement celement = null;
if (child.isDirectory()) {
celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath()));
} else if (child.isFile()) {
celement = new ExternalTranslationUnit(this, path.append(names[i]));
}
if (celement != null) {
vChildren.add(celement);
}
}
}
ICElement[] children = new ICElement[vChildren.size()];
vChildren.toArray(children);
info.setChildren(children);
return true;
}
} }