diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferChangedEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/BufferChangedEvent.java similarity index 98% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferChangedEvent.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/BufferChangedEvent.java index 9abfab0a1fa..e0753637a20 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferChangedEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/BufferChangedEvent.java @@ -1,4 +1,4 @@ -package org.eclipse.cdt.internal.core.model; +package org.eclipse.cdt.core.model; /********************************************************************** * Copyright (c) 2002,2003 Rational Software Corporation and others. * All rights reserved. This program and the accompanying materials @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.model; import java.util.EventObject; + /** * A buffer changed event describes how a buffer has changed. These events are * used in IBufferChangedListener notifications. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index e4a4b9df7df..919215a0820 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -24,7 +24,7 @@ public class CoreModel { * Creates an ICElement form and IPath. * Returns null if not found. */ - public ICResource create(IPath path) { + public ICElement create(IPath path) { return manager.create(path); } @@ -32,7 +32,7 @@ public class CoreModel { * Creates an ICElement form and IFile. * Returns null if not found. */ - public ICFile create(IFile file) { + public ICElement create(IFile file) { return manager.create(file); } @@ -40,7 +40,7 @@ public class CoreModel { * Creates an ICElement form and IFolder. * Returns null if not found. */ - public ICFolder create(IFolder folder) { + public ICContainer create(IFolder folder) { return manager.create(folder); } @@ -56,15 +56,15 @@ public class CoreModel { * Creates an ICElement form and IResource. * Returns null if not found. */ - public ICResource create(IResource resource) { + public ICElement create(IResource resource) { return manager.create(resource); } /** - * Returns the default ICRoot. + * Returns the default ICModel. */ - public ICRoot getCRoot() { - return manager.getCRoot(); + public ICModel getCModel() { + return manager.getCModel(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java index 449164dd1b0..1f1f471099b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java @@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model; * An IArchive represents a group of files combined into a * single file(the Archive), for example libxx.a. */ -public interface IArchive extends ICFile { +public interface IArchive extends ICElement, IParent, IOpenable { /** * Return the binaries contain in the archive. * It does not actually extract the files. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java index 8e0f54c9b7a..6554e42fd04 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java @@ -9,6 +9,6 @@ package org.eclipse.cdt.core.model; * Represents a container of all the IArchive's found in the project * while inspecting the project. */ -public interface IArchiveContainer extends IParent, ICElement { +public interface IArchiveContainer extends ICElement, IParent, IOpenable { public IArchive[] getArchives(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java index e84d1a716ff..4c9d361be08 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java @@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model; * Represents a Binary file, for example an ELF excutable. * An ELF parser will inspect the binary. */ -public interface IBinary extends ICFile { +public interface IBinary extends ICElement, IParent, IOpenable { /** * Return whether the file was compiling with debug symbols. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java index 0746357341c..2a937c485a9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java @@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model; * Represents a container of all the IBinary's found in the project * while inspecting the project. */ -public interface IBinaryContainer extends IParent, ICElement { +public interface IBinaryContainer extends ICElement, IParent, IOpenable { public IBinary[] getBinaries(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBuffer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBuffer.java similarity index 98% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBuffer.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBuffer.java index d8d03998a99..34e1a95f2c8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBuffer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBuffer.java @@ -1,4 +1,4 @@ -package org.eclipse.cdt.internal.core.model; +package org.eclipse.cdt.core.model; /********************************************************************** * Copyright (c) 2002,2003 Rational Software Corporation and others. @@ -11,8 +11,6 @@ package org.eclipse.cdt.internal.core.model; * Rational Software - Initial API and implementation ***********************************************************************/ -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICOpenable; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; @@ -119,7 +117,7 @@ public interface IBuffer { * * @return the resource element owning this buffer */ - public ICOpenable getOwner(); + public IOpenable getOwner(); /** * Returns the given range of text in this buffer. *

diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferChangedListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBufferChangedListener.java similarity index 96% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferChangedListener.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBufferChangedListener.java index fbb3c829509..a7caa0d8769 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferChangedListener.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBufferChangedListener.java @@ -1,4 +1,6 @@ -package org.eclipse.cdt.internal.core.model; +package org.eclipse.cdt.core.model; + + /********************************************************************** * Copyright (c) 2002,2003 Rational Software Corporation and others. * All rights reserved. This program and the accompanying materials diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java new file mode 100644 index 00000000000..7b1a1c2b3ab --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java @@ -0,0 +1,27 @@ +package org.eclipse.cdt.core.model; + +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ + + +/** + * A C Folder Resource. + */ +public interface ICContainer extends ICElement, IParent, IOpenable { + /** + * Returns an array of non-C resources directly contained in this project. + * It does not transitively answer non-C resources contained in folders; + * these would have to be explicitly iterated over. + *

+ * Non-C resources includes files, folders, projects not accounted for. + *

+ * + * @return an array of non-C resources directly contained in this project + * @exception JavaModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource + */ + Object[] getNonCResources() throws CModelException; + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java index 3e56741fab4..46fe5194dfb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java @@ -20,163 +20,160 @@ public interface ICElement extends IAdaptable { /** * Constant representing a C Root workspace (IWorkspaceRoot object). - * A C element with this type can be safely cast to ICRoot. + * A C element with this type can be safely cast to ICModel. */ - public static final int C_ROOT = 10; + static final int C_MODEL = 10; /** * Constant representing a C project(IProject object). * A C element with this type can be safely cast to ICProject. */ - public static final int C_PROJECT = 11; + static final int C_PROJECT = 11; /** - * Constant representing a folder(ICFolder object). - * A C element with this type can be safely cast to ICFolder. + * Constant representing a folder(ICContainer object). + * A C element with this type can be safely cast to ICContainer. */ - public static final int C_FOLDER = 12; - - /** - * Constant representing a file(ICFile object). - * A C element with this type can be safely cast to ICFile. - */ - public static final int C_FILE = 13; + static final int C_CCONTAINER = 12; + static final int C_BINARY = 14; + + static final int C_ARCHIVE = 18; /** * Virtual container serving as a place holder. */ - public static final int C_CONTAINER = 30; + static final int C_VCONTAINER = 30; /** * Constant representing a C/C++ children of a Translation Unit */ - public static final int C_UNIT = 60; + static final int C_UNIT = 60; /** * Namespace. */ - public static final int C_NAMESPACE = 61; + static final int C_NAMESPACE = 61; /** * Using. */ - public static final int C_USING = 62; + static final int C_USING = 62; /** * Enumeration. */ - public static final int C_ENUMERATION = 63; + static final int C_ENUMERATION = 63; /** * Constant representing a class structure. */ - public static final int C_CLASS = 64; + static final int C_CLASS = 64; /** * Constant representing a struct structure. */ - public static final int C_STRUCT = 65; + static final int C_STRUCT = 65; /** * Constant representing a union structure. */ - public static final int C_UNION = 66; + static final int C_UNION = 66; /** * A method definition part of a structure(class, struct, union). */ - public static final int C_METHOD = 67; + static final int C_METHOD = 67; /** * A method declaration part of a structure(class, struct, union). */ - public static final int C_METHOD_DECLARATION = 68; + static final int C_METHOD_DECLARATION = 68; /** * A Field definition part of a structure(class, struct, union). */ - public static final int C_FIELD = 69; + static final int C_FIELD = 69; /** * a C/C++ function prototype. */ - public static final int C_FUNCTION_DECLARATION = 70; + static final int C_FUNCTION_DECLARATION = 70; /** * a C/C++ function. */ - public static final int C_FUNCTION = 71; + static final int C_FUNCTION = 71; /** * Preprocessor #include directive. */ - public static final int C_INCLUDE = 72; + static final int C_INCLUDE = 72; /** * C++ template class. */ - public static final int C_TEMPLATE = 73; + static final int C_TEMPLATE = 73; /** * Global variable. */ - public static final int C_VARIABLE = 74; + static final int C_VARIABLE = 74; /** * variable Declaration. */ - public static final int C_VARIABLE_DECLARATION = 75; + static final int C_VARIABLE_DECLARATION = 75; /** * Local Variable. */ - public static final int C_VARIABLE_LOCAL = 76; + static final int C_VARIABLE_LOCAL = 76; /** * A preprocessor macro. */ - public static final int C_MACRO = 77; + static final int C_MACRO = 77; /** * a Typedef. */ - public static final int C_TYPEDEF = 78; + static final int C_TYPEDEF = 78; /** * Modifier indicating a class constructor */ - public static final int C_CLASS_CTOR = 0x100; + static final int C_CLASS_CTOR = 0x100; /** * Modifier indicating a class destructor */ - public static final int C_CLASS_DTOR = 0x200; + static final int C_CLASS_DTOR = 0x200; /** * Modifier indicating a static storage attribute */ - public static final int C_STORAGE_STATIC = 0x400; + static final int C_STORAGE_STATIC = 0x400; /** * Modifier indicating an extern storage attribute */ - public static final int C_STORAGE_EXTERN = 0x800; + static final int C_STORAGE_EXTERN = 0x800; /** * Modifier indicating a private class */ - public static final int CPP_PRIVATE = 0x1000; + static final int CPP_PRIVATE = 0x1000; /** * Modifier indicating a public class */ - public static final int CPP_PUBLIC = 0x2000; + static final int CPP_PUBLIC = 0x2000; /** * Modifier indicating a friend class */ - public static final int CPP_FRIEND = 0x4000; + static final int CPP_FRIEND = 0x4000; /** * Returns whether this C element exists in the model. @@ -200,14 +197,14 @@ public interface ICElement extends IAdaptable { * ICElement * @see ICElement */ - public int getElementType(); + int getElementType(); /** * Returns the C model. * * @return the C model */ - ICRoot getCRoot(); + ICModel getCModel(); /** * Returns the C project this element is contained in, diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java index c230ca65f93..c46d515927b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java @@ -5,18 +5,9 @@ package org.eclipse.cdt.core.model; * All Rights Reserved. */ -import org.eclipse.core.resources.IFile; /** * A C File Resource. */ -public interface ICFile extends IParent, ICResource { - - public boolean isBinary(); - - public boolean isArchive(); - - public boolean isTranslationUnit(); - - public IFile getFile(); +public interface ICFile extends ICElement { } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java deleted file mode 100644 index 6068a89a6c3..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.eclipse.cdt.core.model; - -/* - * (c) Copyright QNX Software Systems Ltd. 2002. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IFolder; - -/** - * A C Folder Resource. - */ -public interface ICFolder extends IParent, ICResource { - - public IFolder getFolder(); -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java similarity index 93% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java index a6cc0cf940f..599b1477176 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java @@ -5,7 +5,6 @@ package org.eclipse.cdt.core.model; * All Rights Reserved. */ import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IProgressMonitor; /** @@ -22,7 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor; * * @see CCore#create(org.eclipse.core.resources.IWorkspaceRoot) */ -public interface ICRoot extends IParent, ICResource { +public interface ICModel extends ICElement, IParent, IOpenable { /** * Copies the given elements to the specified container(s). * If one container is specified, all elements are copied to that @@ -170,10 +169,24 @@ public interface ICRoot extends IParent, ICResource { */ ICProject[] getCProjects(); + /** + * Returns an array of non-C resources (i.e. non-C projects) in + * the workspace. + *

+ * Non-C projects include all projects that are closed (even if they have the + * C nature). + *

+ * + * @return an array of non-C projects contained in the workspace. + * @throws CModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource + * @since 2.1 + */ + Object[] getNonCResources() throws CModelException; + /** * Returns the workspace associated with this C model. */ IWorkspace getWorkspace(); - IWorkspaceRoot getRoot(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java index 486c7f64c8b..57099bdca31 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java @@ -10,14 +10,14 @@ import org.eclipse.core.runtime.IPath; /** * A C project represents a view of a project resource in terms of C - * elements such as ICFile, ICFolder .... + * elements such as , ICContainer, ITranslationUnit .... * CCore.create(project). *

* * @see CCore#create(org.eclipse.core.resources.IProject) * @see IBuildEntry */ -public interface ICProject extends IParent, ICResource { +public interface ICProject extends ICContainer { /** * Returns the ICElement corresponding to the given diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICResource.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICResource.java index bffc4730ed2..348b560be32 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICResource.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICResource.java @@ -6,5 +6,5 @@ package org.eclipse.cdt.core.model; -public interface ICResource extends IParent, ICElement, ICOpenable { +public interface ICResource extends IParent, ICElement, IOpenable { } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICOpenable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOpenable.java similarity index 93% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICOpenable.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOpenable.java index 02114977968..4339c4cc2d9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICOpenable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOpenable.java @@ -11,15 +11,13 @@ package org.eclipse.cdt.core.model; * Rational Software - Initial API and implementation ***********************************************************************/ -import org.eclipse.cdt.internal.core.model.IBuffer; -import org.eclipse.cdt.internal.core.model.IBufferChangedListener; import org.eclipse.core.runtime.IProgressMonitor; /** * An openable is an element that can be opened, saved, and closed. * An openable might or might not have an associated buffer. */ -public interface ICOpenable extends IBufferChangedListener{ +public interface IOpenable extends IBufferChangedListener{ /** * Closes this element and its buffer (if any). */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java index 5ce58ffc2ec..3fdb5b60396 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.IProgressMonitor; * Use ICElement.isStructureKnown to determine whether this is * the case. */ -public interface ITranslationUnit extends ICFile , ISourceReference, ISourceManipulation { +public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISourceReference, ISourceManipulation { /** * Creates and returns an include declaration in this translation unit * with the given name. 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 47d27872a2c..5727ce434ce 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 @@ -5,23 +5,31 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import java.io.IOException; +import java.util.Map; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +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.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; -public class Archive extends CFile implements IArchive { - - IResource archive; +public class Archive extends Openable implements IArchive { public Archive(ICElement parent, IFile file) { - super(parent, file); + this(parent, file.getLocation()); } public Archive(ICElement parent, IPath path) { - super (parent, path); + super (parent, path, ICElement.C_ARCHIVE); } public IBinary[] getBinaries() { @@ -38,4 +46,59 @@ public class Archive extends CFile implements IArchive { protected ArchiveInfo getArchiveInfo() { return (ArchiveInfo)getElementInfo(); } + /* (non-Javadoc) + * @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 { + CModelManager.getDefault().putInfo(this, info); + return computeChildren(info, underlyingResource); + } + + + public boolean computeChildren(OpenableInfo info, IResource res) { + IBinaryArchive ar = getBinaryArchive(res); + if (ar != null) { + IBinaryObject[] objects = ar.getObjects(); + for (int i = 0; i < objects.length; i++) { + final IBinaryObject obj = objects[i]; + Binary binary = new Binary(this, res.getLocation().append(obj.getName())) { + protected IBinaryObject getBinaryObject(IResource res) { + return obj; + } + }; + + // Force the loading of the children inf the Info by callin getElementInfo. + binary.getElementInfo(); + info.addChild(binary); + } + } else { + return false; + } + return true; + } + + IBinaryArchive getBinaryArchive(IResource res) { + IBinaryArchive archive = null; + IProject project = null; + IBinaryParser parser = null; + if (res != null) { + project = res.getProject(); + } + if (project != null) { + parser = CModelManager.getDefault().getBinaryParser(project); + } + if (parser != null) { + try { + IPath path = res.getLocation(); + IBinaryFile bfile = parser.getBinary(path); + if (bfile instanceof IBinaryArchive) { + archive = (IBinaryArchive) bfile; + } + } catch (IOException e) { + } + } + return archive; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java index e22639f6bd2..37b094dd67e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java @@ -5,72 +5,41 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import java.util.Map; + +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; -public class ArchiveContainer extends Parent implements IArchiveContainer { +public class ArchiveContainer extends Openable implements IArchiveContainer { - CProject cProject; - public ArchiveContainer (CProject cProject) { - super (cProject, null, "lib", CElement.C_CONTAINER); - this.cProject = cProject; - IProject project = cProject.getProject(); - IFolder folder = project.getFolder("Virtual.lib"); - setUnderlyingResource(folder); + super (cProject, null, "libraries", CElement.C_VCONTAINER); } public IArchive[] getArchives() { - ICElement[] e = getChildren(true); + ((ArchiveContainerInfo)getElementInfo()).sync(); + ICElement[] e = getChildren(); IArchive[] a = new IArchive[e.length]; System.arraycopy(e, 0, a, 0, e.length); return a; } - public boolean hasChildren() { - return (getChildren(true).length > 0); - } - - public ICElement [] getChildren() { - return getChildren(false); - } - - public ICElement [] getChildren(boolean sync) { - if (!cProject.hasStartBinaryRunner()) { - // It is vital to set this to true first, if not we are going to loop - cProject.setStartBinaryRunner(true); - BinaryRunner runner = new BinaryRunner(cProject); - Thread thread = new Thread(runner, "Archive Runner"); - // thread.setPriority(Thread.NORM_PRIORITY - 1); - thread.setDaemon(true); - thread.start(); - if (sync) { - try { - thread.join(); - } catch (InterruptedException e) { - } - } - } - return super.getChildren(); - } - - void addChildIfLib(IFile file) { - CModelManager factory = CModelManager.getDefault(); - if (factory.isArchive(file)) { - ICElement celement = factory.create(file); - if (celement != null) { - if (celement instanceof IArchive) { - addChild (celement); - } - } - } - } - public CElementInfo createElementInfo() { - return new CElementInfo(this); + return new ArchiveContainerInfo(this); } + + /* (non-Javadoc) + * @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 { + // this will bootstrap/start the runner for the project. + CModelManager.getDefault().getBinaryRunner(getCProject()); + return true; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java new file mode 100644 index 00000000000..22900b75445 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java @@ -0,0 +1,27 @@ +package org.eclipse.cdt.internal.core.model; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +/** + */ +public class ArchiveContainerInfo extends OpenableInfo { + + /** + * Constructs a new C Model Info + */ + protected ArchiveContainerInfo(CElement element) { + super(element); + } + + synchronized void sync() { + BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject()); + if (runner != null) { + runner.waitIfRunning(); + } + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java index 702824f722e..415dff5e3d5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java @@ -5,25 +5,12 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import java.io.IOException; - -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; /** * Info for ICProject. */ -class ArchiveInfo extends CFileInfo { - - IBinaryArchive archive; +class ArchiveInfo extends OpenableInfo { /** */ @@ -31,58 +18,4 @@ class ArchiveInfo extends CFileInfo { super(element); } - public ICElement[] getChildren() { - if (hasChanged()) { - removeChildren(); - IResource res = null; - try { - res = getElement().getResource(); - } catch (CModelException e) { - } - IBinaryArchive ar = getBinaryArchive(); - IBinaryObject[] objects = ar.getObjects(); - for (int i = 0; i < objects.length; i++) { - final IBinaryObject obj = objects[i]; - Binary binary = new Binary(getElement(), res.getLocation().append(obj.getName())) { - public CElementInfo createElementInfo() { - return new BinaryInfo(this) { - /** - * @see org.eclipse.cdt.internal.core.model.BinaryInfo#getBinaryObject() - */ - IBinaryObject getBinaryObject() { - return obj; - } - }; - } - }; - BinaryInfo info = (BinaryInfo)binary.getElementInfo(); - info.loadChildren(); - addChild(binary); - } - } - return super.getChildren(); - } - - public boolean isArchive() { - return true; - } - - IBinaryArchive getBinaryArchive() { - if (archive == null) { - IProject project = getElement().getCProject().getProject(); - IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); - if (parser != null) { - try { - IPath path = getElement().getUnderlyingResource().getLocation(); - IBinaryFile bfile = parser.getBinary(path); - if (bfile instanceof IBinaryArchive) { - archive = (IBinaryArchive) bfile; - } - } catch (CModelException e) { - } catch (IOException e) { - } - } - } - return archive; - } } 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 0f30e2f90e8..4fc5cde0761 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 @@ -5,28 +5,37 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.resources.IFile; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; -import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.IBinaryParser.ISymbol; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; -public class Binary extends CFile implements IBinary { +public class Binary extends Openable implements IBinary { public Binary(ICElement parent, IFile file) { - super(parent, file); + this(parent, file.getLocation()); } public Binary(ICElement parent, IPath path) { - super (parent, path); + super (parent, path, ICElement.C_BINARY); } public Binary(ICElement parent, IFile file, String name) { - super(parent, file, name); - } - - public boolean isBinary() { - return true; + super(parent, file, name, ICElement.C_BINARY); } public boolean hasDebug () { @@ -45,9 +54,6 @@ public class Binary extends CFile implements IBinary { return ((BinaryInfo)getElementInfo()).isSharedLib(); } - /** - * @see org.eclipse.cdt.core.model.IBinary#isCore() - */ public boolean isCore() { return ((BinaryInfo)getElementInfo()).isCore(); } @@ -87,4 +93,150 @@ public class Binary extends CFile implements IBinary { return new BinaryInfo(this); } + /* (non-Javadoc) + * @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 { + CModelManager.getDefault().putInfo(this, info); + return computeChildren(info, underlyingResource); + } + + + boolean computeChildren(OpenableInfo info, IResource res) { + IBinaryObject bin = getBinaryObject(res); + if (bin != null) { + Map hash = new HashMap(); + ISymbol[] symbols = bin.getSymbols(); + for (int i = 0; i < symbols.length; i++) { + switch (symbols[i].getType()) { + case ISymbol.FUNCTION : + addFunction(info, symbols[i], hash); + break; + + case ISymbol.VARIABLE : + addVariable(info, symbols[i], hash); + break; + } + } + if (info instanceof BinaryInfo) { + ((BinaryInfo)info).loadInfo(bin); + } + } else { + return false; + } + return true; + } + + protected IBinaryObject getBinaryObject(IResource res) { + IBinaryObject binary = null; + IBinaryParser parser = null; + IProject project = null; + if (res != null) { + project = res.getProject(); + } + if (project != null) { + parser = CModelManager.getDefault().getBinaryParser(project); + } + if (parser != null) { + try { + IPath path = res.getLocation(); + IBinaryFile bfile = parser.getBinary(path); + if (bfile instanceof IBinaryObject) { + binary = (IBinaryObject) bfile; + } + } catch (IOException e) { + } + } + return binary; + } + + private void addFunction(OpenableInfo info, ISymbol symbol, Map hash) { + ICElement parent = this; + String filename = filename = symbol.getFilename(); + Function function = null; + + // Addr2line returns the funny "??" when it can find the file. + if (filename != null && !filename.equals("??")) { + TranslationUnit tu = null; + IPath path = new Path(filename); + if (hash.containsKey(path)) { + tu = (TranslationUnit) hash.get(path); + } else { + // A special ITranslationUnit we do not want the file to be parse. + tu = new TranslationUnit(parent, path) { + ArrayList array = new ArrayList(5); + public void addChild(ICElement e) { + array.add(e); + array.trimToSize(); + } + + public ICElement [] getChildren() { + return (ICElement[])array.toArray(new ICElement[0]); + } + + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, + Map newElements, IResource underlyingResource) throws CModelException { + return true; + } + }; + hash.put(path, tu); + info.addChild(tu); + } + function = new Function(tu, symbol.getName()); + tu.addChild(function); + } else { + function = new Function(parent, symbol.getName()); + info.addChild(function); + } + // if (function != null) { + // if (!external) { + // function.getFunctionInfo().setAccessControl(IConstants.AccStatic); + // } + // } + } + + private void addVariable(OpenableInfo info, ISymbol symbol, Map hash) { + String filename = filename = symbol.getFilename(); + ICElement parent = this; + Variable variable = null; + // Addr2line returns the funny "??" when it can not find the file. + if (filename != null && !filename.equals("??")) { + TranslationUnit tu = null; + IPath path = new Path(filename); + if (hash.containsKey(path)) { + tu = (TranslationUnit) hash.get(path); + } else { + tu = new TranslationUnit(parent, path) { + ArrayList array = new ArrayList(5); + public void addChild(ICElement e) { + array.add(e); + array.trimToSize(); + } + + public ICElement [] getChildren() { + return (ICElement[])array.toArray(new ICElement[0]); + } + + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, + Map newElements, IResource underlyingResource) throws CModelException { + return true; + } + }; + hash.put(path, tu); + info.addChild(tu); + } + variable = new Variable(tu, symbol.getName()); + tu.addChild(variable); + } else { + variable = new Variable(parent, symbol.getName()); + info.addChild(variable); + } + //if (variable != null) { + // if (!external) { + // variable.getVariableInfo().setAccessControl(IConstants.AccStatic); + // } + //} + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java index 26b57407439..58464303e94 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java @@ -5,101 +5,41 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import org.eclipse.cdt.core.model.CoreModel; +import java.util.Map; + +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; -public class BinaryContainer extends Parent implements IBinaryContainer { - - CProject cProject; +public class BinaryContainer extends Openable implements IBinaryContainer { public BinaryContainer (CProject cProject) { - this (cProject, "bin"); - } - - public BinaryContainer (CProject cProject, String name) { - super (cProject, null, name, CElement.C_CONTAINER); - this.cProject = cProject; - IProject project = cProject.getProject(); - IFolder folder = project.getFolder("Virtual.bin"); - setUnderlyingResource(folder); + super (cProject, null, "binaries", CElement.C_VCONTAINER); } public IBinary[] getBinaries() { - ICElement[] e = getChildren(true); + ((BinaryContainerInfo)getElementInfo()).sync(); + ICElement[] e = getChildren(); IBinary[] b = new IBinary[e.length]; System.arraycopy(e, 0, b, 0, e.length); return b; } - public boolean hasChildren() { - return (getChildren(true).length > 0); - } - - public ICElement [] getChildren() { - return getChildren(false); - } - - public ICElement [] getChildren(boolean sync) { - // The first time probe the entire project to discover binaries. - if (!cProject.hasStartBinaryRunner()) { - cProject.setStartBinaryRunner(true); - BinaryRunner runner = new BinaryRunner(cProject); - Thread thread = new Thread(runner, "Binary Runner"); - // thread.setPriority(Thread.NORM_PRIORITY - 1); - thread.setDaemon(true); - thread.start(); - if (sync) { - try { - thread.join(); - } catch (InterruptedException e) { - } - } - } - return super.getChildren(); - } - - void addChildIfExec(CoreModel factory, IFile file) { - // Attempt to speed things up by rejecting up front - // Things we know should not be Binary files. - if (!factory.isTranslationUnit(file)) { - ICElement celement = factory.create(file); - if (celement != null) { - if (celement instanceof IBinary) { - IBinary bin = (IBinary)celement; - if (bin.isExecutable() || bin.isSharedLib()) { - addChild (bin); - } - } - } - } - } - public CElementInfo createElementInfo() { - return new CElementInfo(this); + return new BinaryContainerInfo(this); } - class Visitor implements IResourceVisitor { - CoreModel factory = CoreModel.getDefault(); - BinaryContainer cbin; - - public Visitor (BinaryContainer element) { - cbin = element; - } - - public boolean visit(IResource res) throws CoreException { - if (res instanceof IFile) { - cbin.addChildIfExec(factory, (IFile)res); - return false; - } - return true; - } + /* (non-Javadoc) + * @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 { + // this will bootstrap/start the runner for the project. + CModelManager.getDefault().getBinaryRunner(getCProject()); + return true; } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java new file mode 100644 index 00000000000..0edc1ae852e --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java @@ -0,0 +1,27 @@ +package org.eclipse.cdt.internal.core.model; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +/** + */ +public class BinaryContainerInfo extends OpenableInfo { + + /** + * Constructs a new C Model Info + */ + protected BinaryContainerInfo(CElement element) { + super(element); + } + + synchronized void sync() { + BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject()); + if (runner != null) { + runner.waitIfRunning(); + } + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java index 6e00fe12654..559d6784961 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java @@ -6,245 +6,120 @@ package org.eclipse.cdt.internal.core.model; */ import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -class BinaryInfo extends CFileInfo { +class BinaryInfo extends OpenableInfo { - IBinaryObject binary; - Map hash; + int type; + boolean debug; + String cpu = ""; + String shared[] = new String[0]; + long text; + long data; + long bss; + String soname = ""; + boolean littleE; public BinaryInfo(CElement element) { super(element); } - public boolean isBinary() { - return true; - } - - public ICElement[] getChildren() { - if (hasChanged()) { - loadChildren(); - } - return super.getChildren(); - } - public String getCPU() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getCPU(); - } - return ""; + return cpu; } public boolean isSharedLib() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getType() == IBinaryObject.SHARED; - } - return false; + return type == IBinaryObject.SHARED; } public boolean isExecutable() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getType() == IBinaryObject.EXECUTABLE; - } - return false; + return type == IBinaryObject.EXECUTABLE; } public boolean isObject() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getType() == IBinaryObject.OBJECT; - } - return false; + return type == IBinaryObject.OBJECT; } public boolean isCore() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getType() == IBinaryObject.CORE; - } - return false; + return type == IBinaryObject.CORE; } public boolean hasDebug() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.hasDebug(); - } - return false; + return debug; } public String[] getNeededSharedLibs() { - if (isExecutable()) { - IBinaryExecutable exec = (IBinaryExecutable) getBinaryObject(); - return exec.getNeededSharedLibs(); - } - return new String[0]; + return shared; } public long getText() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getText(); - } - return 0; + return text; } public long getData() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getData(); - } - return 0; + return data; } public long getBSS() { - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - return bin.getBSS(); - } - return 0; + return bss; } public String getSoname() { - if (isSharedLib()) { - IBinaryShared shared = (IBinaryShared) getBinaryObject(); - return shared.getSoName(); - } - return ""; + return soname; } public boolean isLittleEndian() { - IBinaryObject bin = getBinaryObject(); + return littleE; + } + + protected void loadInfo() { + loadInfo(getBinaryObject()); + } + + protected void loadInfo(IBinaryObject bin) { if (bin != null) { - return bin.isLittleEndian(); + type = bin.getType(); + cpu = bin.getCPU(); + debug = bin.hasDebug(); + if (isExecutable()) { + IBinaryExecutable exec = (IBinaryExecutable) bin; + shared = exec.getNeededSharedLibs(); + } + text = bin.getText(); + data = bin.getData(); + bss = bin.getBSS(); + if (isSharedLib()) { + IBinaryShared shared = (IBinaryShared) bin; + soname = shared.getSoName(); + } + littleE = bin.isLittleEndian(); } - return false; } - void loadChildren() { - if (hash == null) { - hash = new HashMap(); - } - hash.clear(); - removeChildren(); - setIsStructureKnown(true); - IBinaryObject bin = getBinaryObject(); - ISymbol[] symbols = bin.getSymbols(); - for (int i = 0; i < symbols.length; i++) { - switch (symbols[i].getType()) { - case ISymbol.FUNCTION : - addFunction(symbols[i]); - break; - - case ISymbol.VARIABLE : - addVariable(symbols[i]); - break; - } - } - } - - IBinaryObject getBinaryObject() { - if (binary == null) { - IProject project = getElement().getCProject().getProject(); - IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); - if (parser != null) { - try { - IPath path = getElement().getUnderlyingResource().getLocation(); - IBinaryFile bfile = parser.getBinary(path); - if (bfile instanceof IBinaryObject) { - binary = (IBinaryObject) bfile; - } - } catch (CModelException e) { - } catch (IOException e) { + private IBinaryObject getBinaryObject() { + IBinaryObject binary = null; + IProject project = getElement().getCProject().getProject(); + IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); + if (parser != null) { + try { + IPath path = getElement().getUnderlyingResource().getLocation(); + IBinaryFile bfile = parser.getBinary(path); + if (bfile instanceof IBinaryObject) { + binary = (IBinaryObject) bfile; } + } catch (CModelException e) { + } catch (IOException e) { } } return binary; } - private void addFunction(ISymbol symbol) { - ICElement parent = getElement(); - String filename = filename = symbol.getFilename(); - Function function = null; - - // Addr2line returns the funny "??" when it can find the file. - if (filename != null && !filename.equals("??")) { - TranslationUnit tu = null; - IPath path = new Path(filename); - if (hash.containsKey(path)) { - tu = (TranslationUnit) hash.get(path); - } else { - // A special ITranslationUnit we do not want the file to be parse. - tu = new TranslationUnit(parent, path) { - ArrayList array = new ArrayList(5); - public void addChild(ICElement e) { - array.add(e); - array.trimToSize(); - } - - public ICElement [] getChildren() { - return (ICElement[])array.toArray(new ICElement[0]); - } - }; - hash.put(path, tu); - addChild(tu); - } - function = new Function(tu, symbol.getName()); - tu.addChild(function); - } else { - function = new Function(parent, symbol.getName()); - addChild(function); - } - // if (function != null) { - // if (!external) { - // function.getFunctionInfo().setAccessControl(IConstants.AccStatic); - // } - // } - } - - private void addVariable(ISymbol symbol) { - String filename = filename = symbol.getFilename(); - ICElement parent = getElement(); - Variable variable = null; - // Addr2line returns the funny "??" when it can not find the file. - if (filename != null && !filename.equals("??")) { - TranslationUnit tu = null; - IPath path = new Path(filename); - if (hash.containsKey(path)) { - tu = (TranslationUnit) hash.get(path); - } else { - tu = new TranslationUnit(parent, path); - hash.put(path, tu); - addChild(tu); - } - variable = new Variable(tu, symbol.getName()); - tu.addChild(variable); - } else { - variable = new Variable(parent, symbol.getName()); - addChild(variable); - } - //if (variable != null) { - // if (!external) { - // variable.getVariableInfo().setAccessControl(IConstants.AccStatic); - // } - //} - } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java index 0fed9c66669..f778db4ade8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java @@ -5,39 +5,59 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICModel; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.runtime.CoreException; -import org.eclipse.cdt.core.model.CoreModel; -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.ICRoot; - -public class BinaryRunner implements Runnable { +public class BinaryRunner extends Thread { ArchiveContainer clib; BinaryContainer cbin; - CProject cproject; + ICProject cproject; + CModelManager factory; - public BinaryRunner(CProject cprj) { + public BinaryRunner(ICProject cprj) { + super("Binary Search Thread"); cproject = cprj; cbin = (BinaryContainer)cprj.getBinaryContainer(); clib = (ArchiveContainer)cprj.getArchiveContainer(); + factory = CModelManager.getDefault(); + start(); } public void run() { - cproject.setStartBinaryRunner(true); clib.removeChildren(); cbin.removeChildren(); try { cproject.getProject().accept(new Visitor(this)); } catch (CoreException e) { //e.printStackTrace(); + } catch (Exception e) { + // What is wrong ? + e.printStackTrace(); } fireEvents(cbin); fireEvents(clib); + // Tell the listeners we are done. + synchronized(this) { + notifyAll(); + } + } + + /** + * wrap the wait call and the interrupteException. + */ + public synchronized void waitIfRunning() { + while (isAlive()) { + try { + wait(); + } catch (InterruptedException e) { + } + } } public void fireEvents(Parent container) { @@ -45,7 +65,7 @@ public class BinaryRunner implements Runnable { ICElement[] children = container.getChildren(); if (children.length > 0) { CModelManager factory = CModelManager.getDefault(); - ICElement root = (ICRoot)factory.getCRoot(); + ICElement root = (ICModel)factory.getCModel(); CElementDelta cdelta = new CElementDelta(root); cdelta.added(cproject); cdelta.added(container); @@ -57,31 +77,21 @@ public class BinaryRunner implements Runnable { } } - void addChildIfBinary(CoreModel factory, IFile file) { + void addChildIfBinary(IFile file) { // Attempt to speed things up by rejecting up front // Things we know should not be Binary files. if (!factory.isTranslationUnit(file)) { - if (factory.isBinary(file)) { - ICElement celement = factory.create(file); - if (celement != null) { - if (celement instanceof IBinary) { - IBinary bin = (IBinary)celement; - if (bin.isExecutable() || bin.isSharedLib()) { - cbin.addChild(bin); - } - } - } - } else if (factory.isArchive(file)) { - ICElement celement = factory.create(file); - if (celement instanceof IArchive) { - clib.addChild(celement); - } + IBinaryFile bin = factory.createBinaryFile(file); + if (bin != null) { + IResource res = file.getParent(); + ICElement parent = factory.create(res); + // By creating the element, it will be added to the correct (bin/archive)container. + factory.create(parent, file, bin); } } } class Visitor implements IResourceVisitor { - CoreModel factory = CoreModel.getDefault(); BinaryRunner runner; public Visitor (BinaryRunner r) { @@ -90,7 +100,7 @@ public class BinaryRunner implements Runnable { public boolean visit(IResource res) throws CoreException { if (res instanceof IFile) { - runner.addChildIfBinary(factory, (IFile)res); + runner.addChildIfBinary((IFile)res); return false; } return true; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java index bb86f998572..1c130746acc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java @@ -14,8 +14,9 @@ package org.eclipse.cdt.internal.core.model; import java.io.ByteArrayInputStream; import java.util.ArrayList; +import org.eclipse.cdt.core.model.*; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICOpenable; +import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -32,7 +33,7 @@ public class Buffer implements IBuffer { protected int flags; protected char[] contents; protected ArrayList changeListeners; - protected ICOpenable owner; + protected IOpenable owner; protected int gapStart= -1; protected int gapEnd= -1; @@ -44,7 +45,7 @@ public class Buffer implements IBuffer { /** * Creates a new buffer on an underlying resource. */ - protected Buffer(IFile file, ICOpenable owner, boolean readOnly) { + protected Buffer(IFile file, IOpenable owner, boolean readOnly) { this.file = file; this.owner = owner; if (file == null) { @@ -157,7 +158,7 @@ public class Buffer implements IBuffer { /** * @see org.eclipse.cdt.internal.core.model.IBuffer#getOwner() */ - public ICOpenable getOwner() { + public IOpenable getOwner() { return this.owner; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java index 889b1bcd0af..1d7c2a14efc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java @@ -13,9 +13,10 @@ package org.eclipse.cdt.internal.core.model; import java.util.Enumeration; +import org.eclipse.cdt.core.model.*; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICOpenable; +import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.internal.core.util.LRUCache; import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; import org.eclipse.core.resources.IFile; @@ -92,7 +93,7 @@ public class BufferManager implements IBufferFactory { /** * @see org.eclipse.cdt.internal.core.model.IBufferFactory#createBuffer(org.eclipse.cdt.core.model.IOpenable) */ - public IBuffer createBuffer(ICOpenable owner) { + public IBuffer createBuffer(IOpenable owner) { ICElement element = (ICElement)owner; try{ IResource resource = element.getResource(); @@ -112,7 +113,7 @@ public class BufferManager implements IBufferFactory { * or null if the owner does not have an open * buffer associated with it. */ - public IBuffer getBuffer(ICOpenable owner) { + public IBuffer getBuffer(IOpenable owner) { return (IBuffer)openBuffers.get(owner); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java new file mode 100644 index 00000000000..58d28712996 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java @@ -0,0 +1,149 @@ +package org.eclipse.cdt.internal.core.model; + +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ + +import java.util.ArrayList; +import java.util.Map; + +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.ICContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class CContainer extends Openable implements ICContainer { + + public CContainer (ICElement parent, IResource res) { + this (parent, res, ICElement.C_CCONTAINER); + } + + public CContainer (ICElement parent, IResource res, int type) { + super (parent, res, type); + } + + /** + * Returns a the collection of binary files in this ccontainer + * + * @see ICContainer#getBinaries() + */ + public IBinary[] getBinaries() throws CModelException { + ArrayList list = getChildrenOfType(C_BINARY); + IBinary[] array = new IBinary[list.size()]; + list.toArray(array); + return array; + } + + /** + * Returns a the collection of archive files in this ccontainer + * + * @see ICContainer#getArchives() + */ + public IArchive[] getArchives() throws CModelException { + ArrayList list = getChildrenOfType(C_ARCHIVE); + IArchive[] array = new IArchive[list.size()]; + list.toArray(array); + return array; + } + + /** + * @see ICContainer#getTranslationUnits() + */ + public ITranslationUnit[] getTranslationUnit() throws CModelException { + ArrayList list = getChildrenOfType(C_UNIT); + ITranslationUnit[] array = new ITranslationUnit[list.size()]; + list.toArray(array); + return array; + } + + protected CElementInfo createElementInfo () { + return new CContainerInfo(this); + } + + // CHECKPOINT: folders will return the hash code of their path + public int hashCode() { + return getPath().hashCode(); + } + + /** + * @see Openable + */ + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, + Map newElements, IResource underlyingResource) throws CModelException { + + boolean validInfo = false; + try { + IResource res = getResource(); + if (res != null && (res instanceof IWorkspaceRoot || res.getProject().isOpen())) { + // put the info now, because computing the roots requires it + CModelManager.getDefault().putInfo(this, info); + validInfo = computeChildren(info, res); + } + } finally { + if (!validInfo) { + CModelManager.getDefault().removeInfo(this); + } + } + return validInfo; + } + + /* (non-Javadoc) + * Returns an array of non-c resources contained in the receiver. + * @see org.eclipse.cdt.core.model.ICContainer#getNonCResources() + */ + public Object[] getNonCResources() throws CModelException { + return ((CContainerInfo)getElementInfo()).getNonCResources(getResource()); + } + + protected boolean computeChildren(OpenableInfo info, IResource res) { + ArrayList vChildren = new ArrayList(); + ArrayList notChildren = new ArrayList(); + try { + IResource[] resources = null; + if (res != null) { + //System.out.println (" Resource: " + res.getFullPath().toOSString()); + switch(res.getType()) { + case IResource.ROOT: + case IResource.PROJECT: + case IResource.FOLDER: + IContainer container = (IContainer)res; + resources = container.members(false); + break; + + case IResource.FILE: + break; + } + } + + if (resources != null) { + CModelManager factory = CModelManager.getDefault(); + for (int i = 0; i < resources.length; i++) { + // Check for Valid C Element only. + ICElement celement = factory.create(this, resources[i]); + if (celement != null) { + vChildren.add(celement); + } else { + notChildren.add(resources[i]); + } + } + } + } catch (CoreException e) { + //System.out.println (e); + //CPlugin.log (e); + e.printStackTrace(); + } + ICElement[] children = new ICElement[vChildren.size()]; + vChildren.toArray(children); + info.setChildren(children); + ((CContainerInfo)getElementInfo()).setNonCResources(notChildren.toArray()); + return true; + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java similarity index 55% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java index 129ec8720d7..da3626c85a1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java @@ -1,38 +1,48 @@ package org.eclipse.cdt.internal.core.model; +import java.util.ArrayList; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; + /* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - /** */ -public class CResourceInfo extends CElementInfo { +public class CContainerInfo extends OpenableInfo { + + /** + * Shared empty collection used for efficiency. + */ + static Object[] NO_NON_C_RESOURCES = new Object[] {}; + + Object[] nonCResources = null; /** * Constructs a new C Model Info */ - protected CResourceInfo(CElement element) { + protected CContainerInfo(CElement element) { super(element); } - // Always return true, save the unnecessary probing from the Treeviewer. - protected boolean hasChildren () { - return true; - } + /** + * @param container + * @return + */ + public Object[] getNonCResources(IResource res) { + if (nonCResources != null) + return nonCResources; - protected ICElement [] getChildren () { + ArrayList notChildren = new ArrayList(); + ICElement parent = getElement(); try { IResource[] resources = null; - IResource res = getElement().getUnderlyingResource(); if (res != null) { - //System.out.println (" Resource: " + res.getFullPath().toOSString()); switch(res.getType()) { case IResource.ROOT: case IResource.PROJECT: @@ -50,13 +60,10 @@ public class CResourceInfo extends CElementInfo { CModelManager factory = CModelManager.getDefault(); for (int i = 0; i < resources.length; i++) { // Check for Valid C projects only. - if(resources[i].getType() == IResource.PROJECT) { - IProject proj = (IProject)resources[i]; - if (!factory.hasCNature(proj)) { - continue; - } + ICElement celement = factory.create(parent, resources[i]); + if (celement == null) { + notChildren.add(resources[i]); } - addChild(factory.create(getElement(), resources[i])); } } } catch (CoreException e) { @@ -64,6 +71,15 @@ public class CResourceInfo extends CElementInfo { //CPlugin.log (e); e.printStackTrace(); } - return super.getChildren(); + setNonCResources(notChildren.toArray()); + return nonCResources; + } + + /** + * @param container + * @return + */ + public void setNonCResources(Object[] resources) { + nonCResources = resources; } } 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 2fafb9cd91a..43f4fbefd23 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 @@ -7,9 +7,9 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICOpenable; +import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ICRoot; +import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.IParent; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -102,12 +102,20 @@ public abstract class CElement extends PlatformObject implements ICElement { return getElementInfo().isStructureKnown(); } - public ICRoot getCRoot () { - return getParent().getCRoot(); + public ICModel getCModel () { + ICElement current = this; + do { + if (current instanceof ICModel) return (ICModel) current; + } while ((current = current.getParent()) != null); + return null; } public ICProject getCProject() { - return getParent().getCProject(); + ICElement current = this; + do { + if (current instanceof ICProject) return (ICProject) current; + } while ((current = current.getParent()) != null); + return null; } protected void addChild(ICElement e) { @@ -159,28 +167,6 @@ public abstract class CElement extends PlatformObject implements ICElement { protected abstract CElementInfo createElementInfo(); - /** - * Finds a member corresponding to a give element. - */ - //public ICElement findEqualMember(ICElement elem) { - // if (this instanceof IParent) { - // ICElement[] members = ((IParent)this).getChildren(); - // if (members != null) { - // for (int i= members.length - 1; i >= 0; i--) { - // ICElement curr= members[i]; - // if (curr.equals(elem)) { - // return curr; - // } else { - // ICElement res= curr.findEqualMember(elem); - // if (res != null) { - // return res; - // } - // } - // } - // } - // return null; - //} - /** * Tests if an element has the same name, type and an equal parent. */ @@ -189,15 +175,6 @@ public abstract class CElement extends PlatformObject implements ICElement { return true; if (o instanceof CElement) { CElement other = (CElement) o; - try { - IResource tres = getResource(); - IResource ores = other.getResource(); - if (ores != null && tres != null) { - return tres.equals(ores); - } - } catch (CModelException e) { - //e.printStackTrace(); - } if (fType != other.fType) return false; if (other.fName != null && fName.equals(other.fName)) { @@ -241,14 +218,14 @@ public abstract class CElement extends PlatformObject implements ICElement { // util public static String getTypeString(int type) { switch (type) { - case C_ROOT: - return "CROOT"; + case C_MODEL: + return "CMODEL"; case C_PROJECT: return "CPROJECT"; - case C_FOLDER: - return "CFOLDER"; - case C_FILE: - return "CFILE"; + case C_CCONTAINER: + return "CCONTAINER"; + case C_UNIT: + return "TRANSLATION_UNIT"; case C_FUNCTION: return "C_FUNCTION"; case C_FUNCTION_DECLARATION: @@ -319,9 +296,9 @@ public abstract class CElement extends PlatformObject implements ICElement { * *

Subclasses that are not IOpenable's must override this method. */ - public ICOpenable getOpenableParent() { + public IOpenable getOpenableParent() { - return (ICOpenable)fParent; + return (IOpenable)fParent; } @@ -331,17 +308,18 @@ public abstract class CElement extends PlatformObject implements ICElement { * @exception CModelException this element is not present or accessible */ protected void openHierarchy() throws CModelException { - if (this instanceof ICOpenable) { - ((CResource) this).openWhenClosed(null); + if (this instanceof IOpenable) { + ((Openable) this).openWhenClosed(null); } else { - CResource openableParent = (CResource)getOpenableParent(); + Openable openableParent = (Openable)getOpenableParent(); if (openableParent != null) { CElementInfo openableParentInfo = (CElementInfo) CModelManager.getDefault().getInfo((ICElement) openableParent); if (openableParentInfo == null) { openableParent.openWhenClosed(null); - } else { + } + //else { CModelManager.getDefault().putInfo( this, createElementInfo()); - } + //} } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java index 7d832ce2aa6..e280042d280 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java @@ -6,11 +6,8 @@ package org.eclipse.cdt.internal.core.model; */ import java.util.ArrayList; -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.ICElementDelta; -import org.eclipse.cdt.core.model.ICResource; import org.eclipse.core.resources.IResourceDelta; @@ -101,7 +98,7 @@ public class CElementDelta implements ICElementDelta { // if a child delta is added to a translation unit delta or below, // it's a fine grained delta - if (!(fChangedElement instanceof ICResource)) { + if (!(fChangedElement.getElementType() >= ICElement.C_UNIT)) { fineGrained(); } @@ -203,18 +200,6 @@ public class CElementDelta implements ICElementDelta { CElementDelta addedDelta = new CElementDelta(element); addedDelta.fKind = ADDED; insertDeltaTree(element, addedDelta); - // Added also to the Containers - if (element instanceof IArchive) { - CProject cproj = (CProject)element.getCProject(); - ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); - container.addChild(element); - } else if (element instanceof IBinary) { - if (((IBinary)element).isExecutable() ||((IBinary)element).isSharedLib()) { - CProject cproj = (CProject)element.getCProject(); - BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); - container.addChild(element); - } - } } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java index b07944388bb..579ef48f8e5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java @@ -10,19 +10,6 @@ package org.eclipse.cdt.internal.core.model; * Rational Software - Initial API and implementation ***********************************************************************/ -import org.eclipse.cdt.core.model.ICElement; - -/** - * A C element delta biulder creates a C element delta on a C element between - * the version of the C element at the time the comparator was created and the - * current version of the C element. - * - * It performs this operation by locally caching the contents of - * the C element when it is created. When the method buildDeltas() is called, it - * creates a delta over the cached contents and the new contents. - * - * This class is similar to the JDT CElementDeltaBuilder class. - */ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -252,7 +239,7 @@ private void initialize() { // if building a delta on a translation unit or below, // it's a fine grained delta - if (cElement.getElementType() >= ICElement.C_FILE) { + if (cElement.getElementType() >= ICElement.C_UNIT) { this.delta.fineGrained(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java index 333c15e2ac0..42d77f538e8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java @@ -31,6 +31,7 @@ class CElementInfo { * Shared empty collection used for efficiency. */ protected static ICElement[] fgEmptyChildren = new ICElement[]{}; + /** * Is the structure of this element known * @see ICElement.isStructureKnown() diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java index 61e80946793..d090593081f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java @@ -12,29 +12,36 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -public class CFile extends CResource implements ICFile { +public class CFile extends CElement implements ICFile { + + IFile file; IPath location; - public CFile(ICElement parent, IFile file) { - this(parent, file, file.getLocation(), file.getName()); + public CFile(ICElement parent, IFile file){ + //this (parent, file, ICElement.C_FILE); + this(parent, file, 0); } - public CFile(ICElement parent, IFile file, String name) { - this(parent, file, file.getLocation(), name); + public CFile(ICElement parent, IFile file, int type) { + this(parent, file, file.getLocation(), file.getName(), type); } - public CFile(ICElement parent, IPath location) { + public CFile(ICElement parent, IFile file, String name, int type) { + this(parent, file, file.getLocation(), name, type); + } + + public CFile(ICElement parent, IPath location, int type) { this(parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location), - location, location.lastSegment()); + location, location.lastSegment(), type); } - public CFile(ICElement parent, IResource res, IPath location, String name) { - super(parent, res, name, CElement.C_FILE); + public CFile(ICElement parent, IFile res, IPath location, String name, int type) { + super(parent, name, type); this.location = location; + file = res; } - public IPath getLocation () { return location; } @@ -44,24 +51,7 @@ public class CFile extends CResource implements ICFile { } public IFile getFile () { - try { - return (IFile)getUnderlyingResource(); - } catch (CModelException e) { - e.printStackTrace(); - } - return null; - } - - public boolean isBinary() { - return getCFileInfo().isBinary(); - } - - public boolean isArchive() { - return getCFileInfo().isArchive(); - } - - public boolean isTranslationUnit() { - return getCFileInfo().isTranslationUnit(); + return file; } protected CFileInfo getCFileInfo() { @@ -71,4 +61,18 @@ public class CFile extends CResource implements ICFile { protected CElementInfo createElementInfo () { return new CFileInfo(this); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ICElement#getResource() + */ + public IResource getResource() throws CModelException { + return file; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ICElement#getUnderlyingResource() + */ + public IResource getUnderlyingResource() throws CModelException { + return file; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java index b31f3745031..b440f88689a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java @@ -5,7 +5,7 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -public class CFileInfo extends CResourceInfo { +public class CFileInfo extends CElementInfo { /** * Constructs a new C Model Info @@ -13,20 +13,4 @@ public class CFileInfo extends CResourceInfo { protected CFileInfo(CElement element) { super(element); } - - protected boolean hasChildren() { - return false; - } - - public boolean isBinary() { - return false; - } - - public boolean isArchive() { - return false; - } - - public boolean isTranslationUnit() { - return (this instanceof TranslationUnitInfo); - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java deleted file mode 100644 index 28c191cc76e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright QNX Software Systems Ltd. 2002. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICFolder; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.runtime.IProgressMonitor; - -public class CFolder extends CResource implements ICFolder { - - public CFolder (ICElement parent, IFolder folder) { - super (parent, folder, ICElement.C_FOLDER); - } - - public IFolder getFolder () { - try { - return (IFolder)getUnderlyingResource(); - } catch (CModelException e) { - e.printStackTrace(); - } - return null; - } - - protected CElementInfo createElementInfo () { - return new CFolderInfo(this); - } - - // CHECKPOINT: folders will return the hash code of their path - public int hashCode() { - return getPath().hashCode(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java similarity index 77% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java index 0bfa1209a8d..68ad75ce90e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java @@ -9,25 +9,27 @@ import java.util.ArrayList; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ICResource; -import org.eclipse.cdt.core.model.ICRoot; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IProgressMonitor; -public class CRoot extends CResource implements ICRoot { +public class CModel extends CContainer implements ICModel { - public CRoot(IWorkspaceRoot root) { - super (null, root, root.getName(), ICElement.C_ROOT); + public CModel () { + this(ResourcesPlugin.getWorkspace().getRoot()); } - - public ICRoot getCModel() { - return this; + + public CModel(IWorkspaceRoot root) { + super (null, root, ICElement.C_MODEL); } + public ICProject getCProject(String name) { - CModelManager factory = CModelManager.getDefault(); - return (ICProject)factory.create(getWorkspace().getRoot().getProject(name)); + IProject project = getWorkspace().getRoot().getProject(name); + return CModelManager.getDefault().create(project); } public ICProject[] getCProjects() { @@ -46,17 +48,9 @@ public class CRoot extends CResource implements ICRoot { return null; } - public IWorkspaceRoot getRoot() { - try { - return (IWorkspaceRoot)getUnderlyingResource(); - } catch (CModelException e) { - } - return null; - } - public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings, String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0] instanceof ICResource ) { + if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT ) { runOperation(new CopyResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor); } else { throw new CModelException (new CModelStatus()); @@ -66,7 +60,7 @@ public class CRoot extends CResource implements ICRoot { public void delete(ICElement[] elements, boolean force, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0] instanceof ICResource) { + if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { runOperation(new DeleteResourceElementsOperation(elements, force), monitor); } else { throw new CModelException (new CModelStatus()); @@ -76,7 +70,7 @@ public class CRoot extends CResource implements ICRoot { public void move(ICElement[] elements, ICElement[] containers, ICElement[] siblings, String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0] instanceof ICResource ) { + if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { runOperation(new MoveResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor); } else { throw new CModelException (new CModelStatus()); @@ -86,7 +80,7 @@ public class CRoot extends CResource implements ICRoot { public void rename(ICElement[] elements, ICElement[] destinations, String[] renamings, boolean force, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0] instanceof ICResource) { + if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { runOperation(new RenameResourceElementsOperation(elements, destinations, renamings, force), monitor); } else { @@ -109,7 +103,7 @@ public class CRoot extends CResource implements ICRoot { } protected CElementInfo createElementInfo () { - return new CRootInfo(this); + return new CModelInfo(this); } // CHECKPOINT: Roots will return the hashcode of their resource diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java index cf771685d5e..13b7ffb09c8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java @@ -66,12 +66,12 @@ public double openableFillingRatio() { */ public Object getInfo(ICElement element) { switch (element.getElementType()) { + case ICElement.C_MODEL: case ICElement.C_PROJECT: - case ICElement.C_ROOT: return this.projectAndRootCache.get(element); - case ICElement.C_FOLDER: + case ICElement.C_CCONTAINER: return this.folderCache.get(element); - case ICElement.C_FILE: + case ICElement.C_UNIT: return this.fileCache.get(element); default: return this.childrenCache.get(element); @@ -84,12 +84,12 @@ public Object getInfo(ICElement element) { */ protected Object peekAtInfo(ICElement element) { switch (element.getElementType()) { + case ICElement.C_MODEL: case ICElement.C_PROJECT: - case ICElement.C_ROOT: return this.projectAndRootCache.get(element); - case ICElement.C_FOLDER: + case ICElement.C_CCONTAINER: return this.folderCache.get(element); - case ICElement.C_FILE: + case ICElement.C_UNIT: return this.fileCache.peek(element); default: return this.childrenCache.get(element); @@ -101,14 +101,14 @@ protected Object peekAtInfo(ICElement element) { */ protected void putInfo(ICElement element, Object info) { switch (element.getElementType()) { + case ICElement.C_MODEL: case ICElement.C_PROJECT: - case ICElement.C_ROOT: this.projectAndRootCache.put(element, info); break; - case ICElement.C_FOLDER: + case ICElement.C_CCONTAINER: this.folderCache.put(element, info); break; - case ICElement.C_FILE: + case ICElement.C_UNIT: this.fileCache.put(element, info); break; default: @@ -120,14 +120,14 @@ protected void putInfo(ICElement element, Object info) { */ protected void removeInfo(ICElement element) { switch (element.getElementType()) { + case ICElement.C_MODEL: case ICElement.C_PROJECT: - case ICElement.C_ROOT: this.projectAndRootCache.remove(element); break; - case ICElement.C_FOLDER: + case ICElement.C_CCONTAINER: this.folderCache.remove(element); break; - case ICElement.C_FILE: + case ICElement.C_UNIT: this.fileCache.remove(element); break; default: diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java new file mode 100644 index 00000000000..316b890cb4c --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java @@ -0,0 +1,65 @@ +package org.eclipse.cdt.internal.core.model; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +/** + * @see ICModel + */ +public class CModelInfo extends CContainerInfo { + + /** + * A array with all the non-java projects contained by this model + */ + Object[] nonCResources; + + /** + * Constructs a new C Model Info + */ + protected CModelInfo(CElement element) { + super(element); + } + + /** + * Compute the non-java resources contained in this java project. + */ + private Object[] computeNonCResources() { + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + int length = projects.length; + Object[] nonCProjects = null; + int index = 0; + for (int i = 0; i < length; i++) { + IProject project = projects[i]; + if (!CProject.hasCNature(project)) { + if (nonCProjects == null) { + nonCProjects = new Object[length]; + } + nonCProjects[index++] = project; + } + } + if (index == 0) return NO_NON_C_RESOURCES; + if (index < length) { + System.arraycopy(nonCProjects, 0, nonCProjects = new Object[index], 0, index); + } + return nonCProjects; + } + + /** + * Returns an array of non-C resources contained in the receiver. + */ + Object[] getNonCResources() { + + Object[] resources = nonCResources; + if (resources == null) { + resources = computeNonCResources(); + nonCResources = resources; + } + return resources; + } + +} 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 9099a9a4173..ad8152d6c14 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 @@ -7,12 +7,9 @@ package org.eclipse.cdt.internal.core.model; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Set; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; @@ -23,13 +20,11 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICFile; -import org.eclipse.cdt.core.model.ICFolder; +import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ICResource; -import org.eclipse.cdt.core.model.ICRoot; import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -48,30 +43,31 @@ import org.eclipse.core.runtime.IProgressMonitor; public class CModelManager implements IResourceChangeListener { - private Map fParsedResources = Collections.synchronizedMap(new HashMap()); - - //private static HashMap fParsers = new HashMap(); - + /** + * Unique handle onto the CModel + */ + final CModel cModel = new CModel(); + /** * Used to convert IResourceDeltas into ICElementDeltas. */ - protected DeltaProcessor fDeltaProcessor= new DeltaProcessor(); + protected DeltaProcessor fDeltaProcessor = new DeltaProcessor(); /** * Queue of deltas created explicily by the C Model that * have yet to be fired. */ - private ArrayList fCModelDeltas= new ArrayList(); + private ArrayList fCModelDeltas = new ArrayList(); /** * Turns delta firing on/off. By default it is on. */ - protected boolean fFire= true; + protected boolean fFire = true; /** * Collection of listeners for C element deltas */ - protected ArrayList fElementChangedListeners= new ArrayList(); + protected ArrayList fElementChangedListeners = new ArrayList(); /** * A map from ITranslationUnit to IWorkingCopy of the shared working copies. @@ -92,6 +88,11 @@ public class CModelManager implements IResourceChangeListener { */ public ICProject[] cProjectsCache; + /** + * The list of started BinaryRunners on projects. + */ + private HashMap binaryRunners = new HashMap(); + public static final String [] sourceExtensions = {"c", "cxx", "cc", "C", "cpp"}; public static final String [] headerExtensions = {"h", "hh", "hpp"}; @@ -103,7 +104,7 @@ public class CModelManager implements IResourceChangeListener { public static CModelManager getDefault() { if (factory == null) { - factory = new CModelManager (); + factory = new CModelManager(); // Register to the workspace; ResourcesPlugin.getWorkspace().addResourceChangeListener(factory, @@ -116,35 +117,37 @@ public class CModelManager implements IResourceChangeListener { } /** - * Returns the CRoot for the given workspace, creating + * Returns the CModel for the given workspace, creating * it if it does not yet exist. */ - public ICRoot getCRoot(IWorkspaceRoot root) { - return create(root); + public ICModel getCModel(IWorkspaceRoot root) { + return getCModel(); + //return create(root); } - public ICRoot getCRoot () { - return create(ResourcesPlugin.getWorkspace().getRoot()); + public ICModel getCModel() { + return cModel; } - public ICResource create (IPath path) { + public ICElement create (IPath path) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // Assume it is fullpath relative to workspace IResource res = root.findMember(path); if (res == null) { IPath rootPath = root.getLocation(); if (path.equals(rootPath)) - return getCRoot(root); + return getCModel(root); res = root.getContainerForLocation(path); if (res == null || !res.exists()) res = root.getFileForLocation(path); if (res != null && !res.exists()) res = null; } - return create (res); + // TODO: for extenal resources ?? + return create(res); } - public ICResource create (IResource resource) { + public ICElement create (IResource resource) { if (resource == null) { return null; } @@ -163,7 +166,7 @@ public class CModelManager implements IResourceChangeListener { } } - public ICResource create(ICElement parent, IResource resource) { + public ICElement create(ICElement parent, IResource resource) { int type = resource.getType(); switch (type) { case IResource.PROJECT : @@ -179,54 +182,79 @@ public class CModelManager implements IResourceChangeListener { } } - public ICFile create(IFile file) { + public ICElement create(IFile file) { IResource parent = file.getParent(); ICElement cparent = null; if (parent instanceof IFolder) { - cparent = create ((IFolder)parent); + cparent = create((IFolder)parent); } else if (parent instanceof IProject) { - cparent = create ((IProject)parent); + cparent = create((IProject)parent); } if (cparent != null) - return (ICFile) create (cparent, file); + return create(cparent, file); return null; } - public synchronized ICFile create(ICElement parent, IFile file) { - ICFile cfile = (ICFile)fParsedResources.get(file); - if (cfile == null) { - if (file.exists()) { - if (isArchive(file)) { + public ICElement create(ICElement parent, IFile file) { + return create(parent, file, null); + } + + public synchronized ICElement create(ICElement parent, IFile file, IBinaryFile bin) { + ICElement cfile = null; + if (file.exists()) { + // Try to create the binaryFile first. + if (bin == null) { + bin = createBinaryFile(file); + } + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { cfile = new Archive(parent, file); - } else if (isBinary(file)) { - cfile = new Binary(parent, file); - } else if (isTranslationUnit(file)) { - cfile = new TranslationUnit(parent, file); } else { - cfile = new CFile(parent, file); + cfile = new Binary(parent, file); + } + } else if (isTranslationUnit(file)) { + cfile = new TranslationUnit(parent, file); + } + //else { + // cfile = new CFile(parent, file); + //} + } else { + // Probably it was deleted, find it + if (parent instanceof CElement) { + ICElement[] children = ((CElement)parent).getElementInfo().getChildren(); + for (int i = 0; i < children.length; i++) { + try { + IResource res = children[i].getResource(); + if (res != null && res.equals(file)) { + cfile = children[i]; + break; + } + } catch (CModelException e) { + } } - fParsedResources.put(file, cfile); } } // Added also to the Containers - if (cfile != null) { - if (cfile instanceof IArchive) { - CProject cproj = (CProject)cfile.getCProject(); - ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); - container.addChild(cfile); - } else if (cfile instanceof IBinary) { - IBinary bin = (IBinary)cfile; - if (bin.isExecutable() || bin.isSharedLib()) { + if (cfile != null && (cfile instanceof IBinary || cfile instanceof IArchive)) { + if (bin == null) { + bin = createBinaryFile(file); + } + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { + CProject cproj = (CProject)cfile.getCProject(); + ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); + container.addChild(cfile); + } else if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { CProject cproj = (CProject)cfile.getCProject(); BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); - container.addChild(bin); + container.addChild(cfile); } } } return cfile; } - public ICFolder create(IFolder folder) { + public ICContainer create(IFolder folder) { IResource parent = folder.getParent(); ICElement cparent = null; if (parent instanceof IFolder) { @@ -235,17 +263,12 @@ public class CModelManager implements IResourceChangeListener { cparent = create ((IProject)parent); } if (cparent != null) - return (ICFolder) create (cparent, folder); + return (ICContainer) create (cparent, folder); return null; } - public synchronized ICFolder create(ICElement parent, IFolder folder) { - ICFolder cfolder = (ICFolder)fParsedResources.get(folder); - if (cfolder == null) { - cfolder = new CFolder(parent, folder); - fParsedResources.put(folder, cfolder); - } - return cfolder; + public ICContainer create(ICElement parent, IFolder folder) { + return new CContainer(parent, folder); } public ICProject create(IProject project) { @@ -257,28 +280,20 @@ public class CModelManager implements IResourceChangeListener { return create(celement, project); } - public synchronized ICProject create(ICElement parent, IProject project) { - ICProject cproject = (ICProject)fParsedResources.get(project); - if (cproject == null) { - if (hasCNature(project)) { - cproject = new CProject(parent, project); - fParsedResources.put(project, cproject); - } + public ICProject create(ICElement parent, IProject project) { + if (hasCNature(project)) { + return new CProject(parent, project); } - return cproject; + return null; } - public ICRoot create(IWorkspaceRoot root) { - ICRoot croot = (ICRoot)fParsedResources.get(root); - if (croot == null) { - croot = new CRoot(root); - fParsedResources.put(root, croot); - } - return croot; + public ICModel create(IWorkspaceRoot root) { + return getCModel(); + //return new CModel(root); } private void removeChildrenContainer(Parent container, IResource resource) { - if ( container.hasChildren() ) { + if (container.hasChildren()) { ICElement[] children = container.getChildren(); for (int i = 0; i < children.length; i++) { try { @@ -322,70 +337,43 @@ public class CModelManager implements IResourceChangeListener { //System.out.println("RELEASE " + celement.getElementName()); // Remove from the containers. - if (celement.getElementType() == ICElement.C_FILE) { - CFile cfile = (CFile)celement; - if (cfile.isArchive()) { + int type = celement.getElementType(); + if (type == ICElement.C_ARCHIVE) { //System.out.println("RELEASE Archive " + cfile.getElementName()); - CProject cproj = (CProject)cfile.getCProject(); - ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); - container.removeChild(cfile); - } else if (cfile.isBinary()) { - if (! ((IBinary)celement).isObject()) { + CProject cproj = (CProject)celement.getCProject(); + ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); + container.removeChild(celement); + } else if (type == ICElement.C_BINARY) { + if (! ((IBinary)celement).isObject()) { //System.out.println("RELEASE Binary " + cfile.getElementName()); - CProject cproj = (CProject)cfile.getCProject(); - BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); - container.removeChild(cfile); - } + CProject cproj = (CProject)celement.getCProject(); + BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); + container.removeChild(celement); } } + // Remove the child from the parent list. Parent parent = (Parent)celement.getParent(); if (parent != null) { parent.removeChild(celement); } - try { - // Remove in the hashMap all the prefixOf the resource, this - // will catch things when it is a container to remove the entire hierarchy - IResource res = celement.getUnderlyingResource(); - if (res != null) { - IPath resPath = res.getFullPath(); - if (resPath != null) { - ArrayList list = new ArrayList(); - Set s = fParsedResources.keySet(); - synchronized (s) { - Iterator keys = s.iterator(); - while (keys.hasNext()) { - IResource r = (IResource)keys.next(); - IPath p = r.getFullPath(); - if (p != null && resPath.isPrefixOf(p)) { -//System.out.println("Removing [" + resPath + "] " + p); - list.add(r); - } - } - } - for (int i = 0; i < list.size(); i++) { - fParsedResources.remove((IResource)list.get(i)); - } - } - fParsedResources.remove(res); + + if (celement instanceof CElement) { + CElementInfo info = ((CElement)celement).getElementInfo(); + ICElement[] children = info.getChildren(); + for (int i = 0; i < children.length; i++) { + releaseCElement(children[i]); } - } catch (CModelException e) { } + removeInfo(celement); } public ICElement getCElement(IResource res) { - return (ICElement)fParsedResources.get(res); + return create(res); } public ICElement getCElement(IPath path) { - Iterator iterator = fParsedResources.keySet().iterator(); - while (iterator.hasNext()) { - IResource res = (IResource)iterator.next(); - if (res.getFullPath().equals(path)) { - return (ICElement)fParsedResources.get(res); - } - } - return null; + return create(path); } public IBinaryParser getBinaryParser(IProject project) { @@ -396,85 +384,14 @@ public class CModelManager implements IResourceChangeListener { return new NullBinaryParser(); } -// public IBinaryParser getBinaryParser(IProject project) { -// // It is in the property of the project of the cdtproject -// // For now the default is Elf. -// IBinaryParser parser = (IBinaryParser)fParsers.get(project); -// if (parser == null) { -// String format = getBinaryParserFormat(project); -// if (format == null || format.length() == 0) { -// format = getDefaultBinaryParserFormat(); -// } -// if (format != null && format.length() > 0) { -// parser = CCorePlugin.getDefault().getBinaryParser(format); -// } -// if (parser == null) { -// parser = defaultBinaryParser; -// } -// fParsers.put(project, parser); -// } -// return parser; -// } - -// public String getDefaultBinaryParserFormat() { -// String format = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(BINARY_PARSER); -// if (format == null || format.length() == 0) { -// return "ELF"; -// } -// return format; -// } - -// public String getBinaryParserFormat(IProject project) { -// // It can be in the property of the project or in the .cdtproject -// String format = null; -// // FIXME: Ask the .cdtproject. -// try { -// if (project != null) { -// format = project.getPersistentProperty(binaryParserKey); -// } -// } catch (CoreException e) { -// } -// return format; -// } - -// public void setDefaultBinaryParserFormat(String format) { -// CCorePlugin.getDefault().getPluginPreferences().setDefault(BINARY_PARSER, format); -// } -// -// public void setBinaryParserFormat(IProject project, String format, IProgressMonitor monitor) { -// try { -// if (project != null) { -// project.setPersistentProperty(binaryParserKey, format); -// fParsers.remove(project); -// IPath projPath = project.getFullPath(); -// if (projPath != null) { -// Collection c = fParsedResources.values(); -// ArrayList list = new ArrayList(); -// synchronized (c) { -// Iterator values = c.iterator(); -// while (values.hasNext()) { -// ICElement ce = (ICElement)values.next(); -// if (!(ce instanceof ICRoot || ce instanceof ICProject)) { -// if (ce.getCProject().getProject().equals(project)) { -// list.add(ce); -// } -// } -// } -// } -// for (int i = 0; i < list.size(); i++) { -// ICElement ce = (ICElement)list.get(i); -// releaseCElement(ce); -// } -// } -// // Fired and ICElementDelta.PARSER_CHANGED -// CElementDelta delta = new CElementDelta(getCRoot()); -// delta.binaryParserChanged(create(project)); -// registerCModelDelta(delta); -// fire(); -// } -// } catch (CoreException e) { -// } -// } + public IBinaryFile createBinaryFile(IFile file) { + try { + IBinaryParser parser = getBinaryParser(file.getProject()); + return parser.getBinary(file.getLocation()); + } catch (IOException e) { + } + return null; + } /** * TODO: this is a temporary hack until, the CDescriptor manager is @@ -482,28 +399,9 @@ public class CModelManager implements IResourceChangeListener { */ public void resetBinaryParser(IProject project) { if (project != null) { - IPath projPath = project.getFullPath(); - if (projPath != null) { - Collection c = fParsedResources.values(); - ArrayList list = new ArrayList(); - synchronized (c) { - Iterator values = c.iterator(); - while (values.hasNext()) { - ICElement ce = (ICElement)values.next(); - if (!(ce instanceof ICRoot || ce instanceof ICProject)) { - if (ce.getCProject().getProject().equals(project)) { - list.add(ce); - } - } - } - } - for (int i = 0; i < list.size(); i++) { - ICElement ce = (ICElement)list.get(i); - releaseCElement(ce); - } - } + releaseCElement(project); // Fired and ICElementDelta.PARSER_CHANGED - CElementDelta delta = new CElementDelta(getCRoot()); + CElementDelta delta = new CElementDelta(getCModel()); delta.binaryParserChanged(create(project)); registerCModelDelta(delta); fire(); @@ -628,6 +526,17 @@ public class CModelManager implements IResourceChangeListener { return ok; } + public BinaryRunner getBinaryRunner(ICProject cProject) { + BinaryRunner runner = null; + synchronized(binaryRunners) { + if (binaryRunners.get(cProject) == null) { + runner = new BinaryRunner(cProject); + binaryRunners.put(cProject, runner); + } + } + return runner; + } + /** * addElementChangedListener method comment. */ @@ -701,19 +610,6 @@ public class CModelManager implements IResourceChangeListener { } } - /** - * Note that the project is about to be deleted. - * - * fix for 1FW67PA - */ - public void deleting(IResource resource) { - deleting(getCElement(resource)); - } - - public void deleting(ICElement celement) { - releaseCElement(celement); - } - /** * Fire C Model deltas, flushing them after the fact. * If the firing mode has been turned off, this has no effect. @@ -759,7 +655,7 @@ public class CModelManager implements IResourceChangeListener { return; Iterator deltas = fCModelDeltas.iterator(); - ICElement cRoot = getCRoot(); + ICElement cRoot = getCModel(); CElementDelta rootDelta = new CElementDelta(cRoot); boolean insertedTree = false; while (deltas.hasNext()) { @@ -777,7 +673,7 @@ public class CModelManager implements IResourceChangeListener { insertedTree = true; } } - if (insertedTree){ + if (insertedTree) { fCModelDeltas = new ArrayList(1); fCModelDeltas.add(rootDelta); } else { @@ -795,7 +691,7 @@ public class CModelManager implements IResourceChangeListener { operation.run(monitor); } else { // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode - getCRoot().getUnderlyingResource().getWorkspace().run(operation, monitor); + getCModel().getUnderlyingResource().getWorkspace().run(operation, monitor); } } catch (CoreException ce) { if (ce instanceof CModelException) { @@ -827,7 +723,7 @@ public class CModelManager implements IResourceChangeListener { switch (resource.getType()) { case IResource.ROOT : if (this.cProjectsCache == null) { - this.cProjectsCache = this.getCRoot().getCProjects(); + this.cProjectsCache = this.getCModel().getCProjects(); } IResourceDelta[] children = delta.getAffectedChildren(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java index 95117b3699c..9295f24f628 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ICRoot; +import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICElementDelta; @@ -346,11 +346,11 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo /** * Returns the C Model this operation is operating in. */ - public ICRoot getCRoot() { + public ICModel getCModel() { if (fElementsToProcess == null || fElementsToProcess.length == 0) { - return getParentElement().getCRoot(); + return getParentElement().getCModel(); } else { - return fElementsToProcess[0].getCRoot(); + return fElementsToProcess[0].getCModel(); } } @@ -399,7 +399,7 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo if (fElementsToProcess != null && fElementsToProcess.length > 0) { ICProject project = fElementsToProcess[0].getCProject(); if (project != null) { - return project.getCRoot().getWorkspace(); + return project.getCModel().getWorkspace(); } } return null; @@ -459,7 +459,7 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo * on the C Model. */ public CElementDelta newCElementDelta() { - return new CElementDelta(getCRoot()); + return new CElementDelta(getCModel()); } /** 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 b66d8f99666..054665b29f9 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 @@ -5,30 +5,29 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.IArchiveContainer; +import org.eclipse.cdt.core.model.IBinaryContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICModelStatusConstants; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICModelStatusConstants; - -public class CProject extends CResource implements ICProject { - - boolean runner = false; +public class CProject extends CContainer implements ICProject { public CProject (ICElement parent, IProject project) { super (parent, project, CElement.C_PROJECT); } public IBinaryContainer getBinaryContainer() { - return getCProjectInfo().getBinaryContainer(); + return ((CProjectInfo)getElementInfo()).getBinaryContainer(); } public IArchiveContainer getArchiveContainer() { - return getCProjectInfo().getArchiveContainer(); + return ((CProjectInfo)getElementInfo()).getArchiveContainer(); } public IProject getProject() { @@ -40,10 +39,6 @@ public class CProject extends CResource implements ICProject { return null; } - public ICProject getCProject() { - return this; - } - public ICElement findElement(IPath path) throws CModelException { ICElement celem = null; if (path.isAbsolute()) { @@ -62,16 +57,13 @@ public class CProject extends CResource implements ICProject { return celem; } - synchronized protected boolean hasStartBinaryRunner() { - return runner; - } - - synchronized protected void setStartBinaryRunner(boolean done) { - runner = done; - } - - protected CProjectInfo getCProjectInfo() { - return (CProjectInfo)getElementInfo(); + public static boolean hasCNature (IProject p) { + try { + return p.hasNature(CProjectNature.C_NATURE_ID); + } catch (CoreException e) { + //throws exception if the project is not open. + } + return false; } protected CElementInfo createElementInfo() { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java index 0a0e1e3e62e..0d4fd35a39e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java @@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinaryContainer; @@ -13,35 +12,11 @@ import org.eclipse.cdt.core.model.IBinaryContainer; * Info for ICProject. */ -class CProjectInfo extends CResourceInfo { +class CProjectInfo extends CContainerInfo { private BinaryContainer vBin; private ArchiveContainer vLib; - public IBinaryContainer getBinaryContainer() { - if (vBin == null) { - vBin = new BinaryContainer((CProject)getElement()); - addChild(vBin); - } - return vBin; - } - - public IArchiveContainer getArchiveContainer() { - if (vLib == null) { - vLib = new ArchiveContainer((CProject)getElement()); - addChild(vLib); - } - return vLib; - } - - public ICElement[] getChildren() { - // ensure that BinaryContqainer and ArchiveContainer - // have been added as children. Side affect of get methods! - getBinaryContainer(); - getArchiveContainer(); - return super.getChildren(); - } - /** */ public CProjectInfo(CElement element) { @@ -49,4 +24,19 @@ class CProjectInfo extends CResourceInfo { vBin = null; vLib = null; } + + synchronized public IBinaryContainer getBinaryContainer() { + if (vBin == null) { + vBin = new BinaryContainer((CProject)getElement()); + } + return vBin; + } + + synchronized public IArchiveContainer getArchiveContainer() { + if (vLib == null) { + vLib = new ArchiveContainer((CProject)getElement()); + } + return vLib; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java deleted file mode 100644 index 7baefdef5c6..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * @see ICModel - */ -public class CRootInfo extends CResourceInfo { - - /** - * Constructs a new C Model Info - */ - protected CRootInfo(CElement element) { - super(element); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java index 42972a4f7a6..2efa2795c75 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.model; * Rational Software - Initial API and implementation ***********************************************************************/ +import org.eclipse.cdt.core.model.*; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModelStatus; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java index 80fe7b62e8c..b5d214fcc4d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java @@ -4,15 +4,11 @@ package org.eclipse.cdt.internal.core.model; * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ -import java.util.HashMap; -import java.util.Map; - - +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.IParent; /** * This operation copies/moves a collection of elements from their current @@ -49,7 +45,7 @@ import org.eclipse.cdt.core.model.CModelException; */ public class CopyElementsOperation extends MultiOperation { - private Map fSources = new HashMap(); + //private Map fSources = new HashMap(); /** * When executed, this operation will copy the given elements to the diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java index 07d046dd65f..e4b4a6cf1a2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java @@ -16,7 +16,6 @@ import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ICResource; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -126,9 +125,9 @@ public class CopyResourceElementsOperation extends MultiOperation { String destName = (newName != null) ? newName : source.getElementName(); // copy resource - IFile sourceResource = (IFile)((ICResource)source).getResource(); + IFile sourceResource = (IFile)source.getResource(); // can be an IFolder or an IProject - IContainer destFolder = (IContainer)((ICResource)dest).getResource(); + IContainer destFolder = (IContainer)dest.getResource(); IFile destFile = destFolder.getFile(new Path(destName)); if (!destFile.equals(sourceResource)) { try { @@ -185,7 +184,7 @@ public class CopyResourceElementsOperation extends MultiOperation { */ protected void processElement(ICElement element) throws CModelException { ICElement dest = getDestinationParent(element); - if (element instanceof ICResource) { + if (element.getElementType() <= ICElement.C_UNIT) { processResource(element, dest); //fCreatedElements.add(dest.getCompilationUnit(element.getElementName())); } else { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java index 454ea2efb06..e70af712749 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java @@ -5,23 +5,22 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import java.io.InputStream; -import java.io.IOException; -import java.io.InputStreamReader; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; - +import org.eclipse.cdt.core.model.*; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICResource; +import org.eclipse.cdt.core.model.ICModelStatus; +import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; /** *

This abstract class implements behavior common to CreateElementInCUOperations. @@ -140,30 +139,44 @@ public abstract class CreateElementInTUOperation extends CModelOperation { beginTask(getMainTaskName(), getMainAmountOfWork()); CElementDelta delta = newCElementDelta(); ITranslationUnit unit = getTranslationUnit(); + // generateNewTranslationUnitDOM(unit); insertElement(); if (fCreationOccurred) { //a change has really occurred - IFile file = (IFile)((ICResource)unit).getResource(); - StringBuffer buffer = getContent(file); + IBuffer buffer = unit.getBuffer(); + if (buffer == null) return; + char[] bufferContents = buffer.getCharacters(); + if (bufferContents == null) return; + //char[] elementContents = normalizeCRS(..); + char[] elementContents = fCreatedElement.getSource().toCharArray(); + //IFile file = (IFile)((ICResource)unit).getResource(); + //StringBuffer buffer = getContent(file); switch (fReplacementLength) { case -1 : // element is append at the end - buffer.append(fCreatedElement.getSource()); + //buffer.append(fCreatedElement.getSource()); + buffer.append(elementContents); break; case 0 : // element is inserted - buffer.insert(fInsertionPosition, fCreatedElement.getSource()); + //buffer.insert(fInsertionPosition, fCreatedElement.getSource()); + buffer.replace(fInsertionPosition, 0, elementContents); break; default : // element is replacing the previous one buffer.replace(fInsertionPosition, fReplacementLength, fCreatedElement.getSource()); } - save(buffer, file); + unit.save(null, false); + //save(buffer, file); + boolean isWorkingCopy = unit.isWorkingCopy(); + //if (isWorkingCopy) { + // this.setAttributes(...); + //} worked(1); fResultElements = generateResultHandles(); - //if (!isWorkingCopy) { // if unit is working copy, then save will have already fired the delta + if (!isWorkingCopy) { // if unit is working copy, then save will have already fired the delta if (unit.getParent().exists()) { for (int i = 0; i < fResultElements.length; i++) { delta.added(fResultElements[i]); @@ -171,7 +184,7 @@ public abstract class CreateElementInTUOperation extends CModelOperation { addDelta(delta); } // else unit is created outside classpath // non-java resource delta will be notified by delta processor - //} + } } done(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java index 29714ccdb80..858b6d790b3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java @@ -8,7 +8,6 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICResource; /** * This operation deletes a collection of resources and all of their children. @@ -37,7 +36,7 @@ public class DeleteResourceElementsOperation extends MultiOperation { * deletePackageFragment depending on the type of element. */ protected void processElement(ICElement element) throws CModelException { - deleteResource(((ICResource)element).getResource(), fForce); + deleteResource(element.getResource(), fForce); } /** 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 8e336fcb61c..ad044d90a21 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 @@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICRoot; +import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -100,6 +100,22 @@ public class DeltaProcessor { return CModelManager.getDefault().getCElement(path); } + /** + * Adds the given child handle to its parent's cache of children. + */ + protected void addToParentInfo(Openable child) { + + Openable parent = (Openable) child.getParent(); + if (parent != null && parent.isOpen()) { + //try { + CElementInfo info = (CElementInfo)parent.getElementInfo(); + info.addChild(child); + //} //catch (CModelException e) { + // do nothing - we already checked if open + //} + } + } + /** * Processing for an element that has been added: