1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

BufferChangeEvent was refactor to be public

ICFolder was remvoed
IBuffer.java was refactor to be public
IBuferChangedListerner.java is not visible
Refactor of ICRoot to ICModel
Refactor of ICOpenable to IOpenable
all the C Resources now implement IOpenable
This commit is contained in:
Alain Magloire 2003-03-27 16:05:18 +00:00
parent 69a5d7386b
commit 57e8eb56ff
65 changed files with 1232 additions and 1159 deletions

View file

@ -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. * Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.model;
import java.util.EventObject; import java.util.EventObject;
/** /**
* A buffer changed event describes how a buffer has changed. These events are * A buffer changed event describes how a buffer has changed. These events are
* used in <code>IBufferChangedListener</code> notifications. * used in <code>IBufferChangedListener</code> notifications.

View file

@ -24,7 +24,7 @@ public class CoreModel {
* Creates an ICElement form and IPath. * Creates an ICElement form and IPath.
* Returns null if not found. * Returns null if not found.
*/ */
public ICResource create(IPath path) { public ICElement create(IPath path) {
return manager.create(path); return manager.create(path);
} }
@ -32,7 +32,7 @@ public class CoreModel {
* Creates an ICElement form and IFile. * Creates an ICElement form and IFile.
* Returns null if not found. * Returns null if not found.
*/ */
public ICFile create(IFile file) { public ICElement create(IFile file) {
return manager.create(file); return manager.create(file);
} }
@ -40,7 +40,7 @@ public class CoreModel {
* Creates an ICElement form and IFolder. * Creates an ICElement form and IFolder.
* Returns null if not found. * Returns null if not found.
*/ */
public ICFolder create(IFolder folder) { public ICContainer create(IFolder folder) {
return manager.create(folder); return manager.create(folder);
} }
@ -56,15 +56,15 @@ public class CoreModel {
* Creates an ICElement form and IResource. * Creates an ICElement form and IResource.
* Returns null if not found. * Returns null if not found.
*/ */
public ICResource create(IResource resource) { public ICElement create(IResource resource) {
return manager.create(resource); return manager.create(resource);
} }
/** /**
* Returns the default ICRoot. * Returns the default ICModel.
*/ */
public ICRoot getCRoot() { public ICModel getCModel() {
return manager.getCRoot(); return manager.getCModel();
} }
/** /**

View file

@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model;
* An IArchive represents a group of files combined into a * An IArchive represents a group of files combined into a
* single file(the Archive), for example libxx.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. * Return the binaries contain in the archive.
* It does not actually extract the files. * It does not actually extract the files.

View file

@ -9,6 +9,6 @@ package org.eclipse.cdt.core.model;
* Represents a container of all the IArchive's found in the project * Represents a container of all the IArchive's found in the project
* while inspecting the project. * while inspecting the project.
*/ */
public interface IArchiveContainer extends IParent, ICElement { public interface IArchiveContainer extends ICElement, IParent, IOpenable {
public IArchive[] getArchives(); public IArchive[] getArchives();
} }

View file

@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model;
* Represents a Binary file, for example an ELF excutable. * Represents a Binary file, for example an ELF excutable.
* An ELF parser will inspect the binary. * 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. * Return whether the file was compiling with debug symbols.
*/ */

View file

@ -9,7 +9,7 @@ package org.eclipse.cdt.core.model;
* Represents a container of all the IBinary's found in the project * Represents a container of all the IBinary's found in the project
* while inspecting the project. * while inspecting the project.
*/ */
public interface IBinaryContainer extends IParent, ICElement { public interface IBinaryContainer extends ICElement, IParent, IOpenable {
public IBinary[] getBinaries(); public IBinary[] getBinaries();
} }

View file

@ -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. * 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 * 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.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -119,7 +117,7 @@ public interface IBuffer {
* *
* @return the resource element owning this buffer * @return the resource element owning this buffer
*/ */
public ICOpenable getOwner(); public IOpenable getOwner();
/** /**
* Returns the given range of text in this buffer. * Returns the given range of text in this buffer.
* <p> * <p>

View file

@ -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. * Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials

View file

@ -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.
* <p>
* Non-C resources includes files, folders, projects not accounted for.
* </p>
*
* @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;
}

View file

@ -20,163 +20,160 @@ public interface ICElement extends IAdaptable {
/** /**
* Constant representing a C Root workspace (IWorkspaceRoot object). * Constant representing a C Root workspace (IWorkspaceRoot object).
* A C element with this type can be safely cast to <code>ICRoot</code>. * A C element with this type can be safely cast to <code>ICModel</code>.
*/ */
public static final int C_ROOT = 10; static final int C_MODEL = 10;
/** /**
* Constant representing a C project(IProject object). * Constant representing a C project(IProject object).
* A C element with this type can be safely cast to <code>ICProject</code>. * A C element with this type can be safely cast to <code>ICProject</code>.
*/ */
public static final int C_PROJECT = 11; static final int C_PROJECT = 11;
/** /**
* Constant representing a folder(ICFolder object). * Constant representing a folder(ICContainer object).
* A C element with this type can be safely cast to <code>ICFolder</code>. * A C element with this type can be safely cast to <code>ICContainer</code>.
*/ */
public static final int C_FOLDER = 12; static final int C_CCONTAINER = 12;
/** static final int C_BINARY = 14;
* Constant representing a file(ICFile object).
* A C element with this type can be safely cast to <code>ICFile</code>.
*/
public static final int C_FILE = 13;
static final int C_ARCHIVE = 18;
/** /**
* Virtual container serving as a place holder. * 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 * Constant representing a C/C++ children of a Translation Unit
*/ */
public static final int C_UNIT = 60; static final int C_UNIT = 60;
/** /**
* Namespace. * Namespace.
*/ */
public static final int C_NAMESPACE = 61; static final int C_NAMESPACE = 61;
/** /**
* Using. * Using.
*/ */
public static final int C_USING = 62; static final int C_USING = 62;
/** /**
* Enumeration. * Enumeration.
*/ */
public static final int C_ENUMERATION = 63; static final int C_ENUMERATION = 63;
/** /**
* Constant representing a class structure. * Constant representing a class structure.
*/ */
public static final int C_CLASS = 64; static final int C_CLASS = 64;
/** /**
* Constant representing a struct structure. * Constant representing a struct structure.
*/ */
public static final int C_STRUCT = 65; static final int C_STRUCT = 65;
/** /**
* Constant representing a union structure. * 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). * 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). * 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). * 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. * a C/C++ function prototype.
*/ */
public static final int C_FUNCTION_DECLARATION = 70; static final int C_FUNCTION_DECLARATION = 70;
/** /**
* a C/C++ function. * a C/C++ function.
*/ */
public static final int C_FUNCTION = 71; static final int C_FUNCTION = 71;
/** /**
* Preprocessor #include directive. * Preprocessor #include directive.
*/ */
public static final int C_INCLUDE = 72; static final int C_INCLUDE = 72;
/** /**
* C++ template class. * C++ template class.
*/ */
public static final int C_TEMPLATE = 73; static final int C_TEMPLATE = 73;
/** /**
* Global variable. * Global variable.
*/ */
public static final int C_VARIABLE = 74; static final int C_VARIABLE = 74;
/** /**
* variable Declaration. * variable Declaration.
*/ */
public static final int C_VARIABLE_DECLARATION = 75; static final int C_VARIABLE_DECLARATION = 75;
/** /**
* Local Variable. * Local Variable.
*/ */
public static final int C_VARIABLE_LOCAL = 76; static final int C_VARIABLE_LOCAL = 76;
/** /**
* A preprocessor macro. * A preprocessor macro.
*/ */
public static final int C_MACRO = 77; static final int C_MACRO = 77;
/** /**
* a Typedef. * a Typedef.
*/ */
public static final int C_TYPEDEF = 78; static final int C_TYPEDEF = 78;
/** /**
* Modifier indicating a class constructor * 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 * 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 * 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 * 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 * Modifier indicating a private class
*/ */
public static final int CPP_PRIVATE = 0x1000; static final int CPP_PRIVATE = 0x1000;
/** /**
* Modifier indicating a public class * Modifier indicating a public class
*/ */
public static final int CPP_PUBLIC = 0x2000; static final int CPP_PUBLIC = 0x2000;
/** /**
* Modifier indicating a friend class * 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. * Returns whether this C element exists in the model.
@ -200,14 +197,14 @@ public interface ICElement extends IAdaptable {
* <code>ICElement</code> * <code>ICElement</code>
* @see ICElement * @see ICElement
*/ */
public int getElementType(); int getElementType();
/** /**
* Returns the C model. * Returns the C model.
* *
* @return the C model * @return the C model
*/ */
ICRoot getCRoot(); ICModel getCModel();
/** /**
* Returns the C project this element is contained in, * Returns the C project this element is contained in,

View file

@ -5,18 +5,9 @@ package org.eclipse.cdt.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.core.resources.IFile;
/** /**
* A C File Resource. * A C File Resource.
*/ */
public interface ICFile extends IParent, ICResource { public interface ICFile extends ICElement {
public boolean isBinary();
public boolean isArchive();
public boolean isTranslationUnit();
public IFile getFile();
} }

View file

@ -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();
}

View file

@ -5,7 +5,6 @@ package org.eclipse.cdt.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
/** /**
@ -22,7 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
* *
* @see CCore#create(org.eclipse.core.resources.IWorkspaceRoot) * @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). * Copies the given elements to the specified container(s).
* If one container is specified, all elements are copied to that * If one container is specified, all elements are copied to that
@ -170,10 +169,24 @@ public interface ICRoot extends IParent, ICResource {
*/ */
ICProject[] getCProjects(); ICProject[] getCProjects();
/**
* Returns an array of non-C resources (i.e. non-C projects) in
* the workspace.
* <p>
* Non-C projects include all projects that are closed (even if they have the
* C nature).
* </p>
*
* @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. * Returns the workspace associated with this C model.
*/ */
IWorkspace getWorkspace(); IWorkspace getWorkspace();
IWorkspaceRoot getRoot();
} }

View file

@ -10,14 +10,14 @@ import org.eclipse.core.runtime.IPath;
/** /**
* A C project represents a view of a project resource in terms of C * A C project represents a view of a project resource in terms of C
* elements such as ICFile, ICFolder .... * elements such as , ICContainer, ITranslationUnit ....
* <code>CCore.create(project)</code>. * <code>CCore.create(project)</code>.
* </p> * </p>
* *
* @see CCore#create(org.eclipse.core.resources.IProject) * @see CCore#create(org.eclipse.core.resources.IProject)
* @see IBuildEntry * @see IBuildEntry
*/ */
public interface ICProject extends IParent, ICResource { public interface ICProject extends ICContainer {
/** /**
* Returns the <code>ICElement</code> corresponding to the given * Returns the <code>ICElement</code> corresponding to the given

View file

@ -6,5 +6,5 @@
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
public interface ICResource extends IParent, ICElement, ICOpenable { public interface ICResource extends IParent, ICElement, IOpenable {
} }

View file

@ -11,15 +11,13 @@ package org.eclipse.cdt.core.model;
* Rational Software - Initial API and implementation * 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; import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* An openable is an element that can be opened, saved, and closed. * An openable is an element that can be opened, saved, and closed.
* An openable might or might not have an associated buffer. * 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). * Closes this element and its buffer (if any).
*/ */

View file

@ -16,7 +16,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
* Use <code>ICElement.isStructureKnown</code> to determine whether this is * Use <code>ICElement.isStructureKnown</code> to determine whether this is
* the case. * 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 * Creates and returns an include declaration in this translation unit
* with the given name. * with the given name.

View file

@ -5,23 +5,31 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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.IArchive;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class Archive extends CFile implements IArchive { public class Archive extends Openable implements IArchive {
IResource archive;
public Archive(ICElement parent, IFile file) { public Archive(ICElement parent, IFile file) {
super(parent, file); this(parent, file.getLocation());
} }
public Archive(ICElement parent, IPath path) { public Archive(ICElement parent, IPath path) {
super (parent, path); super (parent, path, ICElement.C_ARCHIVE);
} }
public IBinary[] getBinaries() { public IBinary[] getBinaries() {
@ -38,4 +46,59 @@ public class Archive extends CFile implements IArchive {
protected ArchiveInfo getArchiveInfo() { protected ArchiveInfo getArchiveInfo() {
return (ArchiveInfo)getElementInfo(); 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;
}
} }

View file

@ -5,72 +5,41 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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.IArchive;
import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.resources.IProject;
public class ArchiveContainer extends Parent implements IArchiveContainer { public class ArchiveContainer extends Openable implements IArchiveContainer {
CProject cProject;
public ArchiveContainer (CProject cProject) { public ArchiveContainer (CProject cProject) {
super (cProject, null, "lib", CElement.C_CONTAINER); super (cProject, null, "libraries", CElement.C_VCONTAINER);
this.cProject = cProject;
IProject project = cProject.getProject();
IFolder folder = project.getFolder("Virtual.lib");
setUnderlyingResource(folder);
} }
public IArchive[] getArchives() { public IArchive[] getArchives() {
ICElement[] e = getChildren(true); ((ArchiveContainerInfo)getElementInfo()).sync();
ICElement[] e = getChildren();
IArchive[] a = new IArchive[e.length]; IArchive[] a = new IArchive[e.length];
System.arraycopy(e, 0, a, 0, e.length); System.arraycopy(e, 0, a, 0, e.length);
return a; 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() { 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;
}
} }

View file

@ -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();
}
}
}

View file

@ -5,25 +5,12 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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. * Info for ICProject.
*/ */
class ArchiveInfo extends CFileInfo { class ArchiveInfo extends OpenableInfo {
IBinaryArchive archive;
/** /**
*/ */
@ -31,58 +18,4 @@ class ArchiveInfo extends CFileInfo {
super(element); 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;
}
} }

View file

@ -5,28 +5,37 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.core.runtime.IPath; import java.io.IOException;
import org.eclipse.core.resources.IFile; 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.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) { public Binary(ICElement parent, IFile file) {
super(parent, file); this(parent, file.getLocation());
} }
public Binary(ICElement parent, IPath path) { public Binary(ICElement parent, IPath path) {
super (parent, path); super (parent, path, ICElement.C_BINARY);
} }
public Binary(ICElement parent, IFile file, String name) { public Binary(ICElement parent, IFile file, String name) {
super(parent, file, name); super(parent, file, name, ICElement.C_BINARY);
}
public boolean isBinary() {
return true;
} }
public boolean hasDebug () { public boolean hasDebug () {
@ -45,9 +54,6 @@ public class Binary extends CFile implements IBinary {
return ((BinaryInfo)getElementInfo()).isSharedLib(); return ((BinaryInfo)getElementInfo()).isSharedLib();
} }
/**
* @see org.eclipse.cdt.core.model.IBinary#isCore()
*/
public boolean isCore() { public boolean isCore() {
return ((BinaryInfo)getElementInfo()).isCore(); return ((BinaryInfo)getElementInfo()).isCore();
} }
@ -87,4 +93,150 @@ public class Binary extends CFile implements IBinary {
return new BinaryInfo(this); 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);
// }
//}
}
} }

View file

@ -5,101 +5,41 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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.IBinary;
import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement; 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.IResource;
import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.CoreException;
public class BinaryContainer extends Parent implements IBinaryContainer { public class BinaryContainer extends Openable implements IBinaryContainer {
CProject cProject;
public BinaryContainer (CProject cProject) { public BinaryContainer (CProject cProject) {
this (cProject, "bin"); super (cProject, null, "binaries", CElement.C_VCONTAINER);
}
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);
} }
public IBinary[] getBinaries() { public IBinary[] getBinaries() {
ICElement[] e = getChildren(true); ((BinaryContainerInfo)getElementInfo()).sync();
ICElement[] e = getChildren();
IBinary[] b = new IBinary[e.length]; IBinary[] b = new IBinary[e.length];
System.arraycopy(e, 0, b, 0, e.length); System.arraycopy(e, 0, b, 0, e.length);
return b; 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() { public CElementInfo createElementInfo() {
return new CElementInfo(this); return new BinaryContainerInfo(this);
} }
class Visitor implements IResourceVisitor { /* (non-Javadoc)
CoreModel factory = CoreModel.getDefault(); * @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)
BinaryContainer cbin; */
protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource)
public Visitor (BinaryContainer element) { throws CModelException {
cbin = element; // this will bootstrap/start the runner for the project.
} CModelManager.getDefault().getBinaryRunner(getCProject());
public boolean visit(IResource res) throws CoreException {
if (res instanceof IFile) {
cbin.addChildIfExec(factory, (IFile)res);
return false;
}
return true; return true;
} }
}
} }

View file

@ -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();
}
}
}

View file

@ -6,162 +6,106 @@ package org.eclipse.cdt.internal.core.model;
*/ */
import java.io.IOException; 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;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; 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.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
class BinaryInfo extends CFileInfo { class BinaryInfo extends OpenableInfo {
IBinaryObject binary; int type;
Map hash; boolean debug;
String cpu = "";
String shared[] = new String[0];
long text;
long data;
long bss;
String soname = "";
boolean littleE;
public BinaryInfo(CElement element) { public BinaryInfo(CElement element) {
super(element); super(element);
} }
public boolean isBinary() {
return true;
}
public ICElement[] getChildren() {
if (hasChanged()) {
loadChildren();
}
return super.getChildren();
}
public String getCPU() { public String getCPU() {
IBinaryObject bin = getBinaryObject(); return cpu;
if (bin != null) {
return bin.getCPU();
}
return "";
} }
public boolean isSharedLib() { public boolean isSharedLib() {
IBinaryObject bin = getBinaryObject(); return type == IBinaryObject.SHARED;
if (bin != null) {
return bin.getType() == IBinaryObject.SHARED;
}
return false;
} }
public boolean isExecutable() { public boolean isExecutable() {
IBinaryObject bin = getBinaryObject(); return type == IBinaryObject.EXECUTABLE;
if (bin != null) {
return bin.getType() == IBinaryObject.EXECUTABLE;
}
return false;
} }
public boolean isObject() { public boolean isObject() {
IBinaryObject bin = getBinaryObject(); return type == IBinaryObject.OBJECT;
if (bin != null) {
return bin.getType() == IBinaryObject.OBJECT;
}
return false;
} }
public boolean isCore() { public boolean isCore() {
IBinaryObject bin = getBinaryObject(); return type == IBinaryObject.CORE;
if (bin != null) {
return bin.getType() == IBinaryObject.CORE;
}
return false;
} }
public boolean hasDebug() { public boolean hasDebug() {
IBinaryObject bin = getBinaryObject(); return debug;
if (bin != null) {
return bin.hasDebug();
}
return false;
} }
public String[] getNeededSharedLibs() { public String[] getNeededSharedLibs() {
if (isExecutable()) { return shared;
IBinaryExecutable exec = (IBinaryExecutable) getBinaryObject();
return exec.getNeededSharedLibs();
}
return new String[0];
} }
public long getText() { public long getText() {
IBinaryObject bin = getBinaryObject(); return text;
if (bin != null) {
return bin.getText();
}
return 0;
} }
public long getData() { public long getData() {
IBinaryObject bin = getBinaryObject(); return data;
if (bin != null) {
return bin.getData();
}
return 0;
} }
public long getBSS() { public long getBSS() {
IBinaryObject bin = getBinaryObject(); return bss;
if (bin != null) {
return bin.getBSS();
}
return 0;
} }
public String getSoname() { public String getSoname() {
if (isSharedLib()) { return soname;
IBinaryShared shared = (IBinaryShared) getBinaryObject();
return shared.getSoName();
}
return "";
} }
public boolean isLittleEndian() { public boolean isLittleEndian() {
IBinaryObject bin = getBinaryObject(); return littleE;
}
protected void loadInfo() {
loadInfo(getBinaryObject());
}
protected void loadInfo(IBinaryObject bin) {
if (bin != null) { if (bin != null) {
return bin.isLittleEndian(); type = bin.getType();
cpu = bin.getCPU();
debug = bin.hasDebug();
if (isExecutable()) {
IBinaryExecutable exec = (IBinaryExecutable) bin;
shared = exec.getNeededSharedLibs();
} }
return false; text = bin.getText();
} data = bin.getData();
bss = bin.getBSS();
void loadChildren() { if (isSharedLib()) {
if (hash == null) { IBinaryShared shared = (IBinaryShared) bin;
hash = new HashMap(); soname = shared.getSoName();
}
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;
} }
littleE = bin.isLittleEndian();
} }
} }
IBinaryObject getBinaryObject() { private IBinaryObject getBinaryObject() {
if (binary == null) { IBinaryObject binary = null;
IProject project = getElement().getCProject().getProject(); IProject project = getElement().getCProject().getProject();
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
if (parser != null) { if (parser != null) {
@ -175,76 +119,7 @@ class BinaryInfo extends CFileInfo {
} catch (IOException e) { } catch (IOException e) {
} }
} }
}
return binary; 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);
// }
//}
}
} }

View file

@ -5,39 +5,59 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.cdt.core.model.CoreModel; public class BinaryRunner extends Thread {
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 {
ArchiveContainer clib; ArchiveContainer clib;
BinaryContainer cbin; BinaryContainer cbin;
CProject cproject; ICProject cproject;
CModelManager factory;
public BinaryRunner(CProject cprj) { public BinaryRunner(ICProject cprj) {
super("Binary Search Thread");
cproject = cprj; cproject = cprj;
cbin = (BinaryContainer)cprj.getBinaryContainer(); cbin = (BinaryContainer)cprj.getBinaryContainer();
clib = (ArchiveContainer)cprj.getArchiveContainer(); clib = (ArchiveContainer)cprj.getArchiveContainer();
factory = CModelManager.getDefault();
start();
} }
public void run() { public void run() {
cproject.setStartBinaryRunner(true);
clib.removeChildren(); clib.removeChildren();
cbin.removeChildren(); cbin.removeChildren();
try { try {
cproject.getProject().accept(new Visitor(this)); cproject.getProject().accept(new Visitor(this));
} catch (CoreException e) { } catch (CoreException e) {
//e.printStackTrace(); //e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
} }
fireEvents(cbin); fireEvents(cbin);
fireEvents(clib); 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) { public void fireEvents(Parent container) {
@ -45,7 +65,7 @@ public class BinaryRunner implements Runnable {
ICElement[] children = container.getChildren(); ICElement[] children = container.getChildren();
if (children.length > 0) { if (children.length > 0) {
CModelManager factory = CModelManager.getDefault(); CModelManager factory = CModelManager.getDefault();
ICElement root = (ICRoot)factory.getCRoot(); ICElement root = (ICModel)factory.getCModel();
CElementDelta cdelta = new CElementDelta(root); CElementDelta cdelta = new CElementDelta(root);
cdelta.added(cproject); cdelta.added(cproject);
cdelta.added(container); 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 // Attempt to speed things up by rejecting up front
// Things we know should not be Binary files. // Things we know should not be Binary files.
if (!factory.isTranslationUnit(file)) { if (!factory.isTranslationUnit(file)) {
if (factory.isBinary(file)) { IBinaryFile bin = factory.createBinaryFile(file);
ICElement celement = factory.create(file); if (bin != null) {
if (celement != null) { IResource res = file.getParent();
if (celement instanceof IBinary) { ICElement parent = factory.create(res);
IBinary bin = (IBinary)celement; // By creating the element, it will be added to the correct (bin/archive)container.
if (bin.isExecutable() || bin.isSharedLib()) { factory.create(parent, file, bin);
cbin.addChild(bin);
}
}
}
} else if (factory.isArchive(file)) {
ICElement celement = factory.create(file);
if (celement instanceof IArchive) {
clib.addChild(celement);
}
} }
} }
} }
class Visitor implements IResourceVisitor { class Visitor implements IResourceVisitor {
CoreModel factory = CoreModel.getDefault();
BinaryRunner runner; BinaryRunner runner;
public Visitor (BinaryRunner r) { public Visitor (BinaryRunner r) {
@ -90,7 +100,7 @@ public class BinaryRunner implements Runnable {
public boolean visit(IResource res) throws CoreException { public boolean visit(IResource res) throws CoreException {
if (res instanceof IFile) { if (res instanceof IFile) {
runner.addChildIfBinary(factory, (IFile)res); runner.addChildIfBinary((IFile)res);
return false; return false;
} }
return true; return true;

View file

@ -14,8 +14,9 @@ package org.eclipse.cdt.internal.core.model;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; 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.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -32,7 +33,7 @@ public class Buffer implements IBuffer {
protected int flags; protected int flags;
protected char[] contents; protected char[] contents;
protected ArrayList changeListeners; protected ArrayList changeListeners;
protected ICOpenable owner; protected IOpenable owner;
protected int gapStart= -1; protected int gapStart= -1;
protected int gapEnd= -1; protected int gapEnd= -1;
@ -44,7 +45,7 @@ public class Buffer implements IBuffer {
/** /**
* Creates a new buffer on an underlying resource. * 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.file = file;
this.owner = owner; this.owner = owner;
if (file == null) { if (file == null) {
@ -157,7 +158,7 @@ public class Buffer implements IBuffer {
/** /**
* @see org.eclipse.cdt.internal.core.model.IBuffer#getOwner() * @see org.eclipse.cdt.internal.core.model.IBuffer#getOwner()
*/ */
public ICOpenable getOwner() { public IOpenable getOwner() {
return this.owner; return this.owner;
} }

View file

@ -13,9 +13,10 @@ package org.eclipse.cdt.internal.core.model;
import java.util.Enumeration; import java.util.Enumeration;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.internal.core.util.LRUCache; import org.eclipse.cdt.internal.core.util.LRUCache;
import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; import org.eclipse.cdt.internal.core.util.OverflowingLRUCache;
import org.eclipse.core.resources.IFile; 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) * @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; ICElement element = (ICElement)owner;
try{ try{
IResource resource = element.getResource(); IResource resource = element.getResource();
@ -112,7 +113,7 @@ public class BufferManager implements IBufferFactory {
* or <code>null</code> if the owner does not have an open * or <code>null</code> if the owner does not have an open
* buffer associated with it. * buffer associated with it.
*/ */
public IBuffer getBuffer(ICOpenable owner) { public IBuffer getBuffer(IOpenable owner) {
return (IBuffer)openBuffers.get(owner); return (IBuffer)openBuffers.get(owner);
} }
/** /**

View file

@ -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;
}
}

View file

@ -1,38 +1,48 @@
package org.eclipse.cdt.internal.core.model; 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. * (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved. * 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 * Constructs a new C Model Info
*/ */
protected CResourceInfo(CElement element) { protected CContainerInfo(CElement element) {
super(element); super(element);
} }
// Always return true, save the unnecessary probing from the Treeviewer. /**
protected boolean hasChildren () { * @param container
return true; * @return
} */
public Object[] getNonCResources(IResource res) {
if (nonCResources != null)
return nonCResources;
protected ICElement [] getChildren () { ArrayList notChildren = new ArrayList();
ICElement parent = getElement();
try { try {
IResource[] resources = null; IResource[] resources = null;
IResource res = getElement().getUnderlyingResource();
if (res != null) { if (res != null) {
//System.out.println (" Resource: " + res.getFullPath().toOSString());
switch(res.getType()) { switch(res.getType()) {
case IResource.ROOT: case IResource.ROOT:
case IResource.PROJECT: case IResource.PROJECT:
@ -50,20 +60,26 @@ public class CResourceInfo extends CElementInfo {
CModelManager factory = CModelManager.getDefault(); CModelManager factory = CModelManager.getDefault();
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
// Check for Valid C projects only. // Check for Valid C projects only.
if(resources[i].getType() == IResource.PROJECT) { ICElement celement = factory.create(parent, resources[i]);
IProject proj = (IProject)resources[i]; if (celement == null) {
if (!factory.hasCNature(proj)) { notChildren.add(resources[i]);
continue;
} }
} }
addChild(factory.create(getElement(), resources[i]));
}
} }
} catch (CoreException e) { } catch (CoreException e) {
//System.out.println (e); //System.out.println (e);
//CPlugin.log (e); //CPlugin.log (e);
e.printStackTrace(); e.printStackTrace();
} }
return super.getChildren(); setNonCResources(notChildren.toArray());
return nonCResources;
}
/**
* @param container
* @return
*/
public void setNonCResources(Object[] resources) {
nonCResources = resources;
} }
} }

View file

@ -7,9 +7,9 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; 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.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.cdt.core.model.IParent;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -102,12 +102,20 @@ public abstract class CElement extends PlatformObject implements ICElement {
return getElementInfo().isStructureKnown(); return getElementInfo().isStructureKnown();
} }
public ICRoot getCRoot () { public ICModel getCModel () {
return getParent().getCRoot(); ICElement current = this;
do {
if (current instanceof ICModel) return (ICModel) current;
} while ((current = current.getParent()) != null);
return null;
} }
public ICProject getCProject() { 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) { protected void addChild(ICElement e) {
@ -159,28 +167,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
protected abstract CElementInfo createElementInfo(); 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. * 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; return true;
if (o instanceof CElement) { if (o instanceof CElement) {
CElement other = (CElement) o; 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) if (fType != other.fType)
return false; return false;
if (other.fName != null && fName.equals(other.fName)) { if (other.fName != null && fName.equals(other.fName)) {
@ -241,14 +218,14 @@ public abstract class CElement extends PlatformObject implements ICElement {
// util // util
public static String getTypeString(int type) { public static String getTypeString(int type) {
switch (type) { switch (type) {
case C_ROOT: case C_MODEL:
return "CROOT"; return "CMODEL";
case C_PROJECT: case C_PROJECT:
return "CPROJECT"; return "CPROJECT";
case C_FOLDER: case C_CCONTAINER:
return "CFOLDER"; return "CCONTAINER";
case C_FILE: case C_UNIT:
return "CFILE"; return "TRANSLATION_UNIT";
case C_FUNCTION: case C_FUNCTION:
return "C_FUNCTION"; return "C_FUNCTION";
case C_FUNCTION_DECLARATION: case C_FUNCTION_DECLARATION:
@ -319,9 +296,9 @@ public abstract class CElement extends PlatformObject implements ICElement {
* *
* <p>Subclasses that are not IOpenable's must override this method. * <p>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 * @exception CModelException this element is not present or accessible
*/ */
protected void openHierarchy() throws CModelException { protected void openHierarchy() throws CModelException {
if (this instanceof ICOpenable) { if (this instanceof IOpenable) {
((CResource) this).openWhenClosed(null); ((Openable) this).openWhenClosed(null);
} else { } else {
CResource openableParent = (CResource)getOpenableParent(); Openable openableParent = (Openable)getOpenableParent();
if (openableParent != null) { if (openableParent != null) {
CElementInfo openableParentInfo = (CElementInfo) CModelManager.getDefault().getInfo((ICElement) openableParent); CElementInfo openableParentInfo = (CElementInfo) CModelManager.getDefault().getInfo((ICElement) openableParent);
if (openableParentInfo == null) { if (openableParentInfo == null) {
openableParent.openWhenClosed(null); openableParent.openWhenClosed(null);
} else {
CModelManager.getDefault().putInfo( this, createElementInfo());
} }
//else {
CModelManager.getDefault().putInfo( this, createElementInfo());
//}
} }
} }
} }

View file

@ -6,11 +6,8 @@ package org.eclipse.cdt.internal.core.model;
*/ */
import java.util.ArrayList; 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.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICResource;
import org.eclipse.core.resources.IResourceDelta; 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, // if a child delta is added to a translation unit delta or below,
// it's a fine grained delta // it's a fine grained delta
if (!(fChangedElement instanceof ICResource)) { if (!(fChangedElement.getElementType() >= ICElement.C_UNIT)) {
fineGrained(); fineGrained();
} }
@ -203,18 +200,6 @@ public class CElementDelta implements ICElementDelta {
CElementDelta addedDelta = new CElementDelta(element); CElementDelta addedDelta = new CElementDelta(element);
addedDelta.fKind = ADDED; addedDelta.fKind = ADDED;
insertDeltaTree(element, addedDelta); 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);
}
}
} }
/** /**

View file

@ -10,19 +10,6 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -252,7 +239,7 @@ private void initialize() {
// if building a delta on a translation unit or below, // if building a delta on a translation unit or below,
// it's a fine grained delta // it's a fine grained delta
if (cElement.getElementType() >= ICElement.C_FILE) { if (cElement.getElementType() >= ICElement.C_UNIT) {
this.delta.fineGrained(); this.delta.fineGrained();
} }

View file

@ -31,6 +31,7 @@ class CElementInfo {
* Shared empty collection used for efficiency. * Shared empty collection used for efficiency.
*/ */
protected static ICElement[] fgEmptyChildren = new ICElement[]{}; protected static ICElement[] fgEmptyChildren = new ICElement[]{};
/** /**
* Is the structure of this element known * Is the structure of this element known
* @see ICElement.isStructureKnown() * @see ICElement.isStructureKnown()

View file

@ -12,29 +12,36 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
public class CFile extends CResource implements ICFile { public class CFile extends CElement implements ICFile {
IFile file;
IPath location; IPath location;
public CFile(ICElement parent, IFile file){ public CFile(ICElement parent, IFile file){
this(parent, file, file.getLocation(), file.getName()); //this (parent, file, ICElement.C_FILE);
this(parent, file, 0);
} }
public CFile(ICElement parent, IFile file, String name) { public CFile(ICElement parent, IFile file, int type) {
this(parent, file, file.getLocation(), name); 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), this(parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location),
location, location.lastSegment()); location, location.lastSegment(), type);
} }
public CFile(ICElement parent, IResource res, IPath location, String name) { public CFile(ICElement parent, IFile res, IPath location, String name, int type) {
super(parent, res, name, CElement.C_FILE); super(parent, name, type);
this.location = location; this.location = location;
file = res;
} }
public IPath getLocation () { public IPath getLocation () {
return location; return location;
} }
@ -44,24 +51,7 @@ public class CFile extends CResource implements ICFile {
} }
public IFile getFile () { public IFile getFile () {
try { return file;
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();
} }
protected CFileInfo getCFileInfo() { protected CFileInfo getCFileInfo() {
@ -71,4 +61,18 @@ public class CFile extends CResource implements ICFile {
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo () {
return new CFileInfo(this); 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;
}
} }

View file

@ -5,7 +5,7 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
public class CFileInfo extends CResourceInfo { public class CFileInfo extends CElementInfo {
/** /**
* Constructs a new C Model Info * Constructs a new C Model Info
@ -13,20 +13,4 @@ public class CFileInfo extends CResourceInfo {
protected CFileInfo(CElement element) { protected CFileInfo(CElement element) {
super(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);
}
} }

View file

@ -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();
}
}

View file

@ -9,25 +9,27 @@ import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ICResource; import org.eclipse.core.resources.IProject;
import org.eclipse.cdt.core.model.ICRoot;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
public class CRoot extends CResource implements ICRoot { public class CModel extends CContainer implements ICModel {
public CRoot(IWorkspaceRoot root) { public CModel () {
super (null, root, root.getName(), ICElement.C_ROOT); this(ResourcesPlugin.getWorkspace().getRoot());
} }
public ICRoot getCModel() { public CModel(IWorkspaceRoot root) {
return this; super (null, root, ICElement.C_MODEL);
} }
public ICProject getCProject(String name) { public ICProject getCProject(String name) {
CModelManager factory = CModelManager.getDefault(); IProject project = getWorkspace().getRoot().getProject(name);
return (ICProject)factory.create(getWorkspace().getRoot().getProject(name)); return CModelManager.getDefault().create(project);
} }
public ICProject[] getCProjects() { public ICProject[] getCProjects() {
@ -46,17 +48,9 @@ public class CRoot extends CResource implements ICRoot {
return null; return null;
} }
public IWorkspaceRoot getRoot() {
try {
return (IWorkspaceRoot)getUnderlyingResource();
} catch (CModelException e) {
}
return null;
}
public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings, public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings,
String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { 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); runOperation(new CopyResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor);
} else { } else {
throw new CModelException (new CModelStatus()); 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) public void delete(ICElement[] elements, boolean force, IProgressMonitor monitor)
throws CModelException { 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); runOperation(new DeleteResourceElementsOperation(elements, force), monitor);
} else { } else {
throw new CModelException (new CModelStatus()); 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, public void move(ICElement[] elements, ICElement[] containers, ICElement[] siblings,
String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { 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); runOperation(new MoveResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor);
} else { } else {
throw new CModelException (new CModelStatus()); 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, public void rename(ICElement[] elements, ICElement[] destinations, String[] renamings,
boolean force, IProgressMonitor monitor) throws CModelException { 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, runOperation(new RenameResourceElementsOperation(elements, destinations,
renamings, force), monitor); renamings, force), monitor);
} else { } else {
@ -109,7 +103,7 @@ public class CRoot extends CResource implements ICRoot {
} }
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo () {
return new CRootInfo(this); return new CModelInfo(this);
} }
// CHECKPOINT: Roots will return the hashcode of their resource // CHECKPOINT: Roots will return the hashcode of their resource

View file

@ -66,12 +66,12 @@ public double openableFillingRatio() {
*/ */
public Object getInfo(ICElement element) { public Object getInfo(ICElement element) {
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_MODEL:
case ICElement.C_PROJECT: case ICElement.C_PROJECT:
case ICElement.C_ROOT:
return this.projectAndRootCache.get(element); return this.projectAndRootCache.get(element);
case ICElement.C_FOLDER: case ICElement.C_CCONTAINER:
return this.folderCache.get(element); return this.folderCache.get(element);
case ICElement.C_FILE: case ICElement.C_UNIT:
return this.fileCache.get(element); return this.fileCache.get(element);
default: default:
return this.childrenCache.get(element); return this.childrenCache.get(element);
@ -84,12 +84,12 @@ public Object getInfo(ICElement element) {
*/ */
protected Object peekAtInfo(ICElement element) { protected Object peekAtInfo(ICElement element) {
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_MODEL:
case ICElement.C_PROJECT: case ICElement.C_PROJECT:
case ICElement.C_ROOT:
return this.projectAndRootCache.get(element); return this.projectAndRootCache.get(element);
case ICElement.C_FOLDER: case ICElement.C_CCONTAINER:
return this.folderCache.get(element); return this.folderCache.get(element);
case ICElement.C_FILE: case ICElement.C_UNIT:
return this.fileCache.peek(element); return this.fileCache.peek(element);
default: default:
return this.childrenCache.get(element); return this.childrenCache.get(element);
@ -101,14 +101,14 @@ protected Object peekAtInfo(ICElement element) {
*/ */
protected void putInfo(ICElement element, Object info) { protected void putInfo(ICElement element, Object info) {
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_MODEL:
case ICElement.C_PROJECT: case ICElement.C_PROJECT:
case ICElement.C_ROOT:
this.projectAndRootCache.put(element, info); this.projectAndRootCache.put(element, info);
break; break;
case ICElement.C_FOLDER: case ICElement.C_CCONTAINER:
this.folderCache.put(element, info); this.folderCache.put(element, info);
break; break;
case ICElement.C_FILE: case ICElement.C_UNIT:
this.fileCache.put(element, info); this.fileCache.put(element, info);
break; break;
default: default:
@ -120,14 +120,14 @@ protected void putInfo(ICElement element, Object info) {
*/ */
protected void removeInfo(ICElement element) { protected void removeInfo(ICElement element) {
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_MODEL:
case ICElement.C_PROJECT: case ICElement.C_PROJECT:
case ICElement.C_ROOT:
this.projectAndRootCache.remove(element); this.projectAndRootCache.remove(element);
break; break;
case ICElement.C_FOLDER: case ICElement.C_CCONTAINER:
this.folderCache.remove(element); this.folderCache.remove(element);
break; break;
case ICElement.C_FILE: case ICElement.C_UNIT:
this.fileCache.remove(element); this.fileCache.remove(element);
break; break;
default: default:

View file

@ -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;
}
}

View file

@ -7,12 +7,9 @@ package org.eclipse.cdt.internal.core.model;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; 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.ElementChangedEvent;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICFile; import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICFolder;
import org.eclipse.cdt.core.model.ICProject; 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.cdt.core.model.IElementChangedListener;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@ -48,9 +43,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class CModelManager implements IResourceChangeListener { public class CModelManager implements IResourceChangeListener {
private Map fParsedResources = Collections.synchronizedMap(new HashMap()); /**
* Unique handle onto the CModel
//private static HashMap fParsers = new HashMap(); */
final CModel cModel = new CModel();
/** /**
* Used to convert <code>IResourceDelta</code>s into <code>ICElementDelta</code>s. * Used to convert <code>IResourceDelta</code>s into <code>ICElementDelta</code>s.
@ -92,6 +88,11 @@ public class CModelManager implements IResourceChangeListener {
*/ */
public ICProject[] cProjectsCache; 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 [] sourceExtensions = {"c", "cxx", "cc", "C", "cpp"};
public static final String [] headerExtensions = {"h", "hh", "hpp"}; public static final String [] headerExtensions = {"h", "hh", "hpp"};
@ -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. * it if it does not yet exist.
*/ */
public ICRoot getCRoot(IWorkspaceRoot root) { public ICModel getCModel(IWorkspaceRoot root) {
return create(root); return getCModel();
//return create(root);
} }
public ICRoot getCRoot () { public ICModel getCModel() {
return create(ResourcesPlugin.getWorkspace().getRoot()); return cModel;
} }
public ICResource create (IPath path) { public ICElement create (IPath path) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// Assume it is fullpath relative to workspace // Assume it is fullpath relative to workspace
IResource res = root.findMember(path); IResource res = root.findMember(path);
if (res == null) { if (res == null) {
IPath rootPath = root.getLocation(); IPath rootPath = root.getLocation();
if (path.equals(rootPath)) if (path.equals(rootPath))
return getCRoot(root); return getCModel(root);
res = root.getContainerForLocation(path); res = root.getContainerForLocation(path);
if (res == null || !res.exists()) if (res == null || !res.exists())
res = root.getFileForLocation(path); res = root.getFileForLocation(path);
if (res != null && !res.exists()) if (res != null && !res.exists())
res = null; res = null;
} }
// TODO: for extenal resources ??
return create(res); return create(res);
} }
public ICResource create (IResource resource) { public ICElement create (IResource resource) {
if (resource == null) { if (resource == null) {
return 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(); int type = resource.getType();
switch (type) { switch (type) {
case IResource.PROJECT : case IResource.PROJECT :
@ -179,7 +182,7 @@ public class CModelManager implements IResourceChangeListener {
} }
} }
public ICFile create(IFile file) { public ICElement create(IFile file) {
IResource parent = file.getParent(); IResource parent = file.getParent();
ICElement cparent = null; ICElement cparent = null;
if (parent instanceof IFolder) { if (parent instanceof IFolder) {
@ -188,45 +191,70 @@ public class CModelManager implements IResourceChangeListener {
cparent = create((IProject)parent); cparent = create((IProject)parent);
} }
if (cparent != null) if (cparent != null)
return (ICFile) create (cparent, file); return create(cparent, file);
return null; return null;
} }
public synchronized ICFile create(ICElement parent, IFile file) { public ICElement create(ICElement parent, IFile file) {
ICFile cfile = (ICFile)fParsedResources.get(file); return create(parent, file, null);
if (cfile == null) { }
public synchronized ICElement create(ICElement parent, IFile file, IBinaryFile bin) {
ICElement cfile = null;
if (file.exists()) { if (file.exists()) {
if (isArchive(file)) { // 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); cfile = new Archive(parent, file);
} else if (isBinary(file)) { } else {
cfile = new Binary(parent, file); cfile = new Binary(parent, file);
}
} else if (isTranslationUnit(file)) { } else if (isTranslationUnit(file)) {
cfile = new TranslationUnit(parent, file); cfile = new TranslationUnit(parent, file);
} else {
cfile = new CFile(parent, file);
} }
fParsedResources.put(file, cfile); //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) {
}
}
} }
} }
// Added also to the Containers // Added also to the Containers
if (cfile != null) { if (cfile != null && (cfile instanceof IBinary || cfile instanceof IArchive)) {
if (cfile instanceof IArchive) { if (bin == null) {
bin = createBinaryFile(file);
}
if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
CProject cproj = (CProject)cfile.getCProject(); CProject cproj = (CProject)cfile.getCProject();
ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer();
container.addChild(cfile); container.addChild(cfile);
} else if (cfile instanceof IBinary) { } else if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
IBinary bin = (IBinary)cfile;
if (bin.isExecutable() || bin.isSharedLib()) {
CProject cproj = (CProject)cfile.getCProject(); CProject cproj = (CProject)cfile.getCProject();
BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
container.addChild(bin); container.addChild(cfile);
} }
} }
} }
return cfile; return cfile;
} }
public ICFolder create(IFolder folder) { public ICContainer create(IFolder folder) {
IResource parent = folder.getParent(); IResource parent = folder.getParent();
ICElement cparent = null; ICElement cparent = null;
if (parent instanceof IFolder) { if (parent instanceof IFolder) {
@ -235,17 +263,12 @@ public class CModelManager implements IResourceChangeListener {
cparent = create ((IProject)parent); cparent = create ((IProject)parent);
} }
if (cparent != null) if (cparent != null)
return (ICFolder) create (cparent, folder); return (ICContainer) create (cparent, folder);
return null; return null;
} }
public synchronized ICFolder create(ICElement parent, IFolder folder) { public ICContainer create(ICElement parent, IFolder folder) {
ICFolder cfolder = (ICFolder)fParsedResources.get(folder); return new CContainer(parent, folder);
if (cfolder == null) {
cfolder = new CFolder(parent, folder);
fParsedResources.put(folder, cfolder);
}
return cfolder;
} }
public ICProject create(IProject project) { public ICProject create(IProject project) {
@ -257,24 +280,16 @@ public class CModelManager implements IResourceChangeListener {
return create(celement, project); return create(celement, project);
} }
public synchronized ICProject create(ICElement parent, IProject project) { public ICProject create(ICElement parent, IProject project) {
ICProject cproject = (ICProject)fParsedResources.get(project);
if (cproject == null) {
if (hasCNature(project)) { if (hasCNature(project)) {
cproject = new CProject(parent, project); return new CProject(parent, project);
fParsedResources.put(project, cproject);
} }
} return null;
return cproject;
} }
public ICRoot create(IWorkspaceRoot root) { public ICModel create(IWorkspaceRoot root) {
ICRoot croot = (ICRoot)fParsedResources.get(root); return getCModel();
if (croot == null) { //return new CModel(root);
croot = new CRoot(root);
fParsedResources.put(root, croot);
}
return croot;
} }
private void removeChildrenContainer(Parent container, IResource resource) { private void removeChildrenContainer(Parent container, IResource resource) {
@ -322,70 +337,43 @@ public class CModelManager implements IResourceChangeListener {
//System.out.println("RELEASE " + celement.getElementName()); //System.out.println("RELEASE " + celement.getElementName());
// Remove from the containers. // Remove from the containers.
if (celement.getElementType() == ICElement.C_FILE) { int type = celement.getElementType();
CFile cfile = (CFile)celement; if (type == ICElement.C_ARCHIVE) {
if (cfile.isArchive()) {
//System.out.println("RELEASE Archive " + cfile.getElementName()); //System.out.println("RELEASE Archive " + cfile.getElementName());
CProject cproj = (CProject)cfile.getCProject(); CProject cproj = (CProject)celement.getCProject();
ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer(); ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer();
container.removeChild(cfile); container.removeChild(celement);
} else if (cfile.isBinary()) { } else if (type == ICElement.C_BINARY) {
if (! ((IBinary)celement).isObject()) { if (! ((IBinary)celement).isObject()) {
//System.out.println("RELEASE Binary " + cfile.getElementName()); //System.out.println("RELEASE Binary " + cfile.getElementName());
CProject cproj = (CProject)cfile.getCProject(); CProject cproj = (CProject)celement.getCProject();
BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer(); BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
container.removeChild(cfile); container.removeChild(celement);
}
} }
} }
// Remove the child from the parent list.
Parent parent = (Parent)celement.getParent(); Parent parent = (Parent)celement.getParent();
if (parent != null) { if (parent != null) {
parent.removeChild(celement); parent.removeChild(celement);
} }
try {
// Remove in the hashMap all the prefixOf the resource, this if (celement instanceof CElement) {
// will catch things when it is a container to remove the entire hierarchy CElementInfo info = ((CElement)celement).getElementInfo();
IResource res = celement.getUnderlyingResource(); ICElement[] children = info.getChildren();
if (res != null) { for (int i = 0; i < children.length; i++) {
IPath resPath = res.getFullPath(); releaseCElement(children[i]);
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);
} }
} }
} removeInfo(celement);
for (int i = 0; i < list.size(); i++) {
fParsedResources.remove((IResource)list.get(i));
}
}
fParsedResources.remove(res);
}
} catch (CModelException e) {
}
} }
public ICElement getCElement(IResource res) { public ICElement getCElement(IResource res) {
return (ICElement)fParsedResources.get(res); return create(res);
} }
public ICElement getCElement(IPath path) { public ICElement getCElement(IPath path) {
Iterator iterator = fParsedResources.keySet().iterator(); return create(path);
while (iterator.hasNext()) {
IResource res = (IResource)iterator.next();
if (res.getFullPath().equals(path)) {
return (ICElement)fParsedResources.get(res);
}
}
return null;
} }
public IBinaryParser getBinaryParser(IProject project) { public IBinaryParser getBinaryParser(IProject project) {
@ -396,85 +384,14 @@ public class CModelManager implements IResourceChangeListener {
return new NullBinaryParser(); return new NullBinaryParser();
} }
// public IBinaryParser getBinaryParser(IProject project) { public IBinaryFile createBinaryFile(IFile file) {
// // It is in the property of the project of the cdtproject try {
// // For now the default is Elf. IBinaryParser parser = getBinaryParser(file.getProject());
// IBinaryParser parser = (IBinaryParser)fParsers.get(project); return parser.getBinary(file.getLocation());
// if (parser == null) { } catch (IOException e) {
// String format = getBinaryParserFormat(project); }
// if (format == null || format.length() == 0) { return null;
// 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) {
// }
// }
/** /**
* TODO: this is a temporary hack until, the CDescriptor manager is * 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) { public void resetBinaryParser(IProject project) {
if (project != null) { if (project != null) {
IPath projPath = project.getFullPath(); releaseCElement(project);
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 // Fired and ICElementDelta.PARSER_CHANGED
CElementDelta delta = new CElementDelta(getCRoot()); CElementDelta delta = new CElementDelta(getCModel());
delta.binaryParserChanged(create(project)); delta.binaryParserChanged(create(project));
registerCModelDelta(delta); registerCModelDelta(delta);
fire(); fire();
@ -628,6 +526,17 @@ public class CModelManager implements IResourceChangeListener {
return ok; 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. * 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. * Fire C Model deltas, flushing them after the fact.
* If the firing mode has been turned off, this has no effect. * If the firing mode has been turned off, this has no effect.
@ -759,7 +655,7 @@ public class CModelManager implements IResourceChangeListener {
return; return;
Iterator deltas = fCModelDeltas.iterator(); Iterator deltas = fCModelDeltas.iterator();
ICElement cRoot = getCRoot(); ICElement cRoot = getCModel();
CElementDelta rootDelta = new CElementDelta(cRoot); CElementDelta rootDelta = new CElementDelta(cRoot);
boolean insertedTree = false; boolean insertedTree = false;
while (deltas.hasNext()) { while (deltas.hasNext()) {
@ -795,7 +691,7 @@ public class CModelManager implements IResourceChangeListener {
operation.run(monitor); operation.run(monitor);
} else { } else {
// use IWorkspace.run(...) to ensure that a build will be done in autobuild mode // 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) { } catch (CoreException ce) {
if (ce instanceof CModelException) { if (ce instanceof CModelException) {
@ -827,7 +723,7 @@ public class CModelManager implements IResourceChangeListener {
switch (resource.getType()) { switch (resource.getType()) {
case IResource.ROOT : case IResource.ROOT :
if (this.cProjectsCache == null) { if (this.cProjectsCache == null) {
this.cProjectsCache = this.getCRoot().getCProjects(); this.cProjectsCache = this.getCModel().getCProjects();
} }
IResourceDelta[] children = delta.getAffectedChildren(); IResourceDelta[] children = delta.getAffectedChildren();

View file

@ -22,7 +22,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; 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.ICModelStatus;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICElementDelta; 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. * Returns the C Model this operation is operating in.
*/ */
public ICRoot getCRoot() { public ICModel getCModel() {
if (fElementsToProcess == null || fElementsToProcess.length == 0) { if (fElementsToProcess == null || fElementsToProcess.length == 0) {
return getParentElement().getCRoot(); return getParentElement().getCModel();
} else { } 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) { if (fElementsToProcess != null && fElementsToProcess.length > 0) {
ICProject project = fElementsToProcess[0].getCProject(); ICProject project = fElementsToProcess[0].getCProject();
if (project != null) { if (project != null) {
return project.getCRoot().getWorkspace(); return project.getCModel().getWorkspace();
} }
} }
return null; return null;
@ -459,7 +459,7 @@ public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMo
* on the C Model. * on the C Model.
*/ */
public CElementDelta newCElementDelta() { public CElementDelta newCElementDelta() {
return new CElementDelta(getCRoot()); return new CElementDelta(getCModel());
} }
/** /**

View file

@ -5,30 +5,29 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * 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.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.ICElement; public class CProject extends CContainer implements ICProject {
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 CProject (ICElement parent, IProject project) { public CProject (ICElement parent, IProject project) {
super (parent, project, CElement.C_PROJECT); super (parent, project, CElement.C_PROJECT);
} }
public IBinaryContainer getBinaryContainer() { public IBinaryContainer getBinaryContainer() {
return getCProjectInfo().getBinaryContainer(); return ((CProjectInfo)getElementInfo()).getBinaryContainer();
} }
public IArchiveContainer getArchiveContainer() { public IArchiveContainer getArchiveContainer() {
return getCProjectInfo().getArchiveContainer(); return ((CProjectInfo)getElementInfo()).getArchiveContainer();
} }
public IProject getProject() { public IProject getProject() {
@ -40,10 +39,6 @@ public class CProject extends CResource implements ICProject {
return null; return null;
} }
public ICProject getCProject() {
return this;
}
public ICElement findElement(IPath path) throws CModelException { public ICElement findElement(IPath path) throws CModelException {
ICElement celem = null; ICElement celem = null;
if (path.isAbsolute()) { if (path.isAbsolute()) {
@ -62,16 +57,13 @@ public class CProject extends CResource implements ICProject {
return celem; return celem;
} }
synchronized protected boolean hasStartBinaryRunner() { public static boolean hasCNature (IProject p) {
return runner; try {
return p.hasNature(CProjectNature.C_NATURE_ID);
} catch (CoreException e) {
//throws exception if the project is not open.
} }
return false;
synchronized protected void setStartBinaryRunner(boolean done) {
runner = done;
}
protected CProjectInfo getCProjectInfo() {
return (CProjectInfo)getElementInfo();
} }
protected CElementInfo createElementInfo() { protected CElementInfo createElementInfo() {

View file

@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.IBinaryContainer;
@ -13,35 +12,11 @@ import org.eclipse.cdt.core.model.IBinaryContainer;
* Info for ICProject. * Info for ICProject.
*/ */
class CProjectInfo extends CResourceInfo { class CProjectInfo extends CContainerInfo {
private BinaryContainer vBin; private BinaryContainer vBin;
private ArchiveContainer vLib; 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) { public CProjectInfo(CElement element) {
@ -49,4 +24,19 @@ class CProjectInfo extends CResourceInfo {
vBin = null; vBin = null;
vLib = 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;
}
} }

View file

@ -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);
}
}

View file

@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatus;

View file

@ -4,15 +4,11 @@ package org.eclipse.cdt.internal.core.model;
* (c) Copyright IBM Corp. 2000, 2001. * (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.util.HashMap; import org.eclipse.cdt.core.model.CModelException;
import java.util.Map;
import org.eclipse.cdt.core.model.ICElement; 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.ICModelStatus;
import org.eclipse.cdt.core.model.ICModelStatusConstants; 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 * 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 { 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 * When executed, this operation will copy the given elements to the

View file

@ -16,7 +16,6 @@ import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatus;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICProject; 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.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -126,9 +125,9 @@ public class CopyResourceElementsOperation extends MultiOperation {
String destName = (newName != null) ? newName : source.getElementName(); String destName = (newName != null) ? newName : source.getElementName();
// copy resource // copy resource
IFile sourceResource = (IFile)((ICResource)source).getResource(); IFile sourceResource = (IFile)source.getResource();
// can be an IFolder or an IProject // 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)); IFile destFile = destFolder.getFile(new Path(destName));
if (!destFile.equals(sourceResource)) { if (!destFile.equals(sourceResource)) {
try { try {
@ -185,7 +184,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
*/ */
protected void processElement(ICElement element) throws CModelException { protected void processElement(ICElement element) throws CModelException {
ICElement dest = getDestinationParent(element); ICElement dest = getDestinationParent(element);
if (element instanceof ICResource) { if (element.getElementType() <= ICElement.C_UNIT) {
processResource(element, dest); processResource(element, dest);
//fCreatedElements.add(dest.getCompilationUnit(element.getElementName())); //fCreatedElements.add(dest.getCompilationUnit(element.getElementName()));
} else { } else {

View file

@ -5,23 +5,22 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; 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.cdt.core.model.*;
import org.eclipse.core.runtime.CoreException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.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.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.core.resources.IFile;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.core.runtime.CoreException;
import org.eclipse.cdt.core.model.CModelException;
/** /**
* <p>This abstract class implements behavior common to <code>CreateElementInCUOperations</code>. * <p>This abstract class implements behavior common to <code>CreateElementInCUOperations</code>.
@ -140,30 +139,44 @@ public abstract class CreateElementInTUOperation extends CModelOperation {
beginTask(getMainTaskName(), getMainAmountOfWork()); beginTask(getMainTaskName(), getMainAmountOfWork());
CElementDelta delta = newCElementDelta(); CElementDelta delta = newCElementDelta();
ITranslationUnit unit = getTranslationUnit(); ITranslationUnit unit = getTranslationUnit();
// generateNewTranslationUnitDOM(unit);
insertElement(); insertElement();
if (fCreationOccurred) { if (fCreationOccurred) {
//a change has really occurred //a change has really occurred
IFile file = (IFile)((ICResource)unit).getResource(); IBuffer buffer = unit.getBuffer();
StringBuffer buffer = getContent(file); 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) { switch (fReplacementLength) {
case -1 : case -1 :
// element is append at the end // element is append at the end
buffer.append(fCreatedElement.getSource()); //buffer.append(fCreatedElement.getSource());
buffer.append(elementContents);
break; break;
case 0 : case 0 :
// element is inserted // element is inserted
buffer.insert(fInsertionPosition, fCreatedElement.getSource()); //buffer.insert(fInsertionPosition, fCreatedElement.getSource());
buffer.replace(fInsertionPosition, 0, elementContents);
break; break;
default : default :
// element is replacing the previous one // element is replacing the previous one
buffer.replace(fInsertionPosition, fReplacementLength, fCreatedElement.getSource()); 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); worked(1);
fResultElements = generateResultHandles(); 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()) { if (unit.getParent().exists()) {
for (int i = 0; i < fResultElements.length; i++) { for (int i = 0; i < fResultElements.length; i++) {
delta.added(fResultElements[i]); delta.added(fResultElements[i]);
@ -171,7 +184,7 @@ public abstract class CreateElementInTUOperation extends CModelOperation {
addDelta(delta); addDelta(delta);
} // else unit is created outside classpath } // else unit is created outside classpath
// non-java resource delta will be notified by delta processor // non-java resource delta will be notified by delta processor
//} }
} }
done(); done();
} }

View file

@ -8,7 +8,6 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICResource;
/** /**
* This operation deletes a collection of resources and all of their children. * This operation deletes a collection of resources and all of their children.
@ -37,7 +36,7 @@ public class DeleteResourceElementsOperation extends MultiOperation {
* <code>deletePackageFragment</code> depending on the type of <code>element</code>. * <code>deletePackageFragment</code> depending on the type of <code>element</code>.
*/ */
protected void processElement(ICElement element) throws CModelException { protected void processElement(ICElement element) throws CModelException {
deleteResource(((ICResource)element).getResource(), fForce); deleteResource(element.getResource(), fForce);
} }
/** /**

View file

@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta; 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.ICModelStatusConstants;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -100,6 +100,22 @@ public class DeltaProcessor {
return CModelManager.getDefault().getCElement(path); 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:<ul> * Processing for an element that has been added:<ul>
* <li>If the element is a project, do nothing, and do not process * <li>If the element is a project, do nothing, and do not process
@ -111,6 +127,9 @@ public class DeltaProcessor {
*/ */
protected void elementAdded(ICElement element, IResourceDelta delta) { protected void elementAdded(ICElement element, IResourceDelta delta) {
if (element instanceof Openable) {
addToParentInfo((Openable)element);
}
if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) { if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
//ICElement movedFromElement = createElement(delta.getMovedFromPath()); //ICElement movedFromElement = createElement(delta.getMovedFromPath());
if (movedFromElement == null) if (movedFromElement == null)
@ -125,8 +144,8 @@ public class DeltaProcessor {
/** /**
* Processing for the closing of an element - there are two cases:<ul> * Processing for the closing of an element - there are two cases:<ul>
* <li>when a project is closed (in the platform sense), the * <li>when a project is closed (in the platform sense), the
* CRoot reports this as if the CProject has been removed. * CModel reports this as if the CProject has been removed.
* <li>otherwise, the CRoot reports this * <li>otherwise, the CModel reports this
* as a the element being closed (CHANGED + F_CLOSED). * as a the element being closed (CHANGED + F_CLOSED).
* </ul> * </ul>
* <p>In both cases, the children of the element are not processed. When * <p>In both cases, the children of the element are not processed. When
@ -146,8 +165,8 @@ public class DeltaProcessor {
/** /**
* Processing for the opening of an element - there are two cases:<ul> * Processing for the opening of an element - there are two cases:<ul>
* <li>when a project is opened (in the platform sense), the * <li>when a project is opened (in the platform sense), the
* CRoot reports this as if the CProject has been added. * CModel reports this as if the CProject has been added.
* <li>otherwise, the CRoot reports this * <li>otherwise, the CModel reports this
* as a the element being opened (CHANGED + F_CLOSED). * as a the element being opened (CHANGED + F_CLOSED).
* </ul> * </ul>
*/ */
@ -246,12 +265,12 @@ public class DeltaProcessor {
/** /**
* Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code> into * Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code> into
* the corresponding set of <code>ICElementDelta</code>, rooted in the * the corresponding set of <code>ICElementDelta</code>, rooted in the
* relevant <code>CRoot</code>s. * relevant <code>CModel</code>s.
*/ */
public ICElementDelta[] processResourceDelta(IResourceDelta changes) { public ICElementDelta[] processResourceDelta(IResourceDelta changes) {
try { try {
ICElement root = (ICRoot)CModelManager.getDefault().getCRoot(); ICElement root = (ICModel)CModelManager.getDefault().getCModel();
currentElement = null; currentElement = null;
/* /*

View file

@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.model;
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.internal.core.util.LRUCache; import org.eclipse.cdt.internal.core.util.LRUCache;
import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; import org.eclipse.cdt.internal.core.util.OverflowingLRUCache;
@ -43,7 +43,7 @@ public class ElementCache extends OverflowingLRUCache {
* by closing the element. * by closing the element.
*/ */
protected boolean close(LRUCacheEntry entry) { protected boolean close(LRUCacheEntry entry) {
ICOpenable element = (ICOpenable) entry._fKey; IOpenable element = (IOpenable) entry._fKey;
try { try {
if (element.hasUnsavedChanges()) { if (element.hasUnsavedChanges()) {
return false; return false;

View file

@ -16,7 +16,7 @@ import org.eclipse.cdt.core.model.IMember;
public class FieldInfo extends SourceManipulationInfo { public class FieldInfo extends SourceManipulationInfo {
int flags = 0; int flags = 0;
String typeStr; String typeStr = "";
boolean isConst = false; boolean isConst = false;
boolean isVolatile = false; boolean isVolatile = false;
boolean isMutable = false; boolean isMutable = false;

View file

@ -8,7 +8,7 @@ package org.eclipse.cdt.internal.core.model;
class FunctionInfo extends SourceManipulationInfo { class FunctionInfo extends SourceManipulationInfo {
protected int flags; protected int flags;
protected String returnType; protected String returnType = "";
protected int numOfParams; protected int numOfParams;
protected FunctionInfo (CElement element) { protected FunctionInfo (CElement element) {

View file

@ -11,7 +11,8 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.ICOpenable; import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.IOpenable;
/** /**
* A factory that creates <code>IBuffer</code>s for CFiles. * A factory that creates <code>IBuffer</code>s for CFiles.
* <p> * <p>
@ -31,5 +32,5 @@ public interface IBufferFactory {
* @param owner the owner of the buffer * @param owner the owner of the buffer
* @see IBuffer * @see IBuffer
*/ */
IBuffer createBuffer(ICOpenable owner); IBuffer createBuffer(IOpenable owner);
} }

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;

View file

@ -10,33 +10,43 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.model.BufferChangedEvent;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.IBufferChangedListener;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICResource; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
public abstract class CResource extends Parent implements ICResource { public abstract class Openable extends Parent implements IOpenable, IBufferChangedListener {
public CResource (ICElement parent, IPath path, int type) { public Openable (ICElement parent, IPath path, int type) {
// Check if the file is under the workspace. // Check if the file is under the workspace.
this (parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation (path), this (parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation (path),
path.lastSegment(), type); path.lastSegment(), type);
} }
public CResource (ICElement parent, IResource resource, int type) { public Openable (ICElement parent, IResource resource, int type) {
this (parent, resource, resource.getName(), type); this (parent, resource, resource.getName(), type);
} }
public CResource (ICElement parent, IResource resource, String name, int type) { public Openable (ICElement parent, IResource resource, String name, int type) {
super (parent, resource, name, type); super (parent, resource, name, type);
} }
public IResource getUnderlyingResource() throws CModelException { public IResource getUnderlyingResource() throws CModelException {
return resource; IResource res = getResource();
if (res == null) {
ICElement p = getParent();
if (p != null) {
res = p.getUnderlyingResource();
}
}
return res;
} }
public IResource getResource() throws CModelException { public IResource getResource() throws CModelException {
@ -44,6 +54,7 @@ public abstract class CResource extends Parent implements ICResource {
} }
protected abstract CElementInfo createElementInfo (); protected abstract CElementInfo createElementInfo ();
/** /**
* The buffer associated with this element has changed. Registers * The buffer associated with this element has changed. Registers
* this element as being out of synch with its buffer's contents. * this element as being out of synch with its buffer's contents.
@ -65,7 +76,7 @@ public abstract class CResource extends Parent implements ICResource {
* removing the current infos, generating new infos, and then placing * removing the current infos, generating new infos, and then placing
* the new infos into the C Model cache tables. * the new infos into the C Model cache tables.
*/ */
protected void buildStructure(CResourceInfo info, IProgressMonitor monitor) throws CModelException { protected void buildStructure(OpenableInfo info, IProgressMonitor monitor) throws CModelException {
if (monitor != null && monitor.isCanceled()) return; if (monitor != null && monitor.isCanceled()) return;
@ -88,7 +99,7 @@ public abstract class CResource extends Parent implements ICResource {
/** /**
* Close the buffer associated with this element, if any. * Close the buffer associated with this element, if any.
*/ */
protected void closeBuffer(CFileInfo info) { protected void closeBuffer(OpenableInfo info) {
if (!hasBuffer()) return; // nothing to do if (!hasBuffer()) return; // nothing to do
IBuffer buffer = null; IBuffer buffer = null;
buffer = getBufferManager().getBuffer(this); buffer = getBufferManager().getBuffer(this);
@ -97,14 +108,24 @@ public abstract class CResource extends Parent implements ICResource {
buffer.removeBufferChangedListener(this); buffer.removeBufferChangedListener(this);
} }
} }
/** /**
* Derived classes may override. * Builds this element's structure and properties in the given
* info object, based on this element's current contents (i.e. buffer
* contents if this element has an open buffer, or resource contents
* if this element does not have an open buffer). Children
* are placed in the given newElements table (note, this element
* has already been placed in the newElements table). Returns true
* if successful, or false if an error is encountered while determining
* the structure of this element.
*/ */
protected boolean generateInfos(CResourceInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException{ protected abstract boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException;
return false; //protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException {
} // return false;
//}
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#getBuffer() * @see org.eclipse.cdt.core.model.IOpenable#getBuffer()
*/ */
public IBuffer getBuffer() throws CModelException { public IBuffer getBuffer() throws CModelException {
if (hasBuffer()) { if (hasBuffer()) {
@ -145,7 +166,7 @@ public abstract class CResource extends Parent implements ICResource {
return false; return false;
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#hasUnsavedChanges() * @see org.eclipse.cdt.core.model.IOpenable#hasUnsavedChanges()
*/ */
public boolean hasUnsavedChanges() throws CModelException{ public boolean hasUnsavedChanges() throws CModelException{
@ -158,7 +179,7 @@ public abstract class CResource extends Parent implements ICResource {
} }
// for roots and projects must check open buffers // for roots and projects must check open buffers
// to see if they have an child with unsaved changes // to see if they have an child with unsaved changes
if (fType == C_ROOT || if (fType == C_MODEL ||
fType == C_PROJECT) { fType == C_PROJECT) {
Enumeration openBuffers= getBufferManager().getOpenBuffers(); Enumeration openBuffers= getBufferManager().getOpenBuffers();
while (openBuffers.hasMoreElements()) { while (openBuffers.hasMoreElements()) {
@ -177,14 +198,14 @@ public abstract class CResource extends Parent implements ICResource {
/** /**
* Subclasses must override as required. * Subclasses must override as required.
* *
* @see org.eclipse.cdt.core.model.ICOpenable#isConsistent() * @see org.eclipse.cdt.core.model.IOpenable#isConsistent()
*/ */
public boolean isConsistent() throws CModelException { public boolean isConsistent() throws CModelException {
return true; return true;
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#isOpen() * @see org.eclipse.cdt.core.model.IOpenable#isOpen()
*/ */
public boolean isOpen() { public boolean isOpen() {
synchronized(CModelManager.getDefault()){ synchronized(CModelManager.getDefault()){
@ -202,16 +223,16 @@ public abstract class CResource extends Parent implements ICResource {
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#makeConsistent(IProgressMonitor) * @see org.eclipse.cdt.core.model.IOpenable#makeConsistent(IProgressMonitor)
*/ */
public void makeConsistent(IProgressMonitor pm) throws CModelException { public void makeConsistent(IProgressMonitor pm) throws CModelException {
if (!isConsistent()) { if (!isConsistent()) {
buildStructure((CFileInfo)getElementInfo(), pm); buildStructure((OpenableInfo)getElementInfo(), pm);
} }
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#open(IProgressMonitor) * @see org.eclipse.cdt.core.model.IOpenable#open(IProgressMonitor)
*/ */
public void open(IProgressMonitor pm) throws CModelException { public void open(IProgressMonitor pm) throws CModelException {
if (!isOpen()) { if (!isOpen()) {
@ -235,7 +256,7 @@ public abstract class CResource extends Parent implements ICResource {
*/ */
protected void openParent(IProgressMonitor pm) throws CModelException { protected void openParent(IProgressMonitor pm) throws CModelException {
CResource openableParent = (CResource)getOpenableParent(); Openable openableParent = (Openable)getOpenableParent();
if (openableParent != null) { if (openableParent != null) {
if (!openableParent.isOpen()){ if (!openableParent.isOpen()){
openableParent.openWhenClosed(pm); openableParent.openWhenClosed(pm);
@ -254,7 +275,7 @@ public abstract class CResource extends Parent implements ICResource {
openParent(pm); openParent(pm);
// 2) create the new element info and open a buffer if needed // 2) create the new element info and open a buffer if needed
CResourceInfo info = (CResourceInfo) createElementInfo(); OpenableInfo info = (OpenableInfo) createElementInfo();
IResource resource = getResource(); IResource resource = getResource();
if (resource != null && isSourceElement()) { if (resource != null && isSourceElement()) {
this.openBuffer(pm); this.openBuffer(pm);
@ -273,7 +294,7 @@ public abstract class CResource extends Parent implements ICResource {
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#save(IProgressMonitor, boolean) * @see org.eclipse.cdt.core.model.IOpenable#save(IProgressMonitor, boolean)
*/ */
public void save(IProgressMonitor pm, boolean force) throws CModelException { public void save(IProgressMonitor pm, boolean force) throws CModelException {
if (isReadOnly() || this.getResource().isReadOnly()) { if (isReadOnly() || this.getResource().isReadOnly()) {

View file

@ -5,14 +5,16 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
/** /**
*/ */
public class CFolderInfo extends CResourceInfo { public class OpenableInfo extends CElementInfo {
/** /**
* Constructs a new C Model Info * Constructs a new C Model Info
*/ */
protected CFolderInfo(CElement element) { protected OpenableInfo(CElement element) {
super(element); super(element);
} }
} }

View file

@ -101,7 +101,7 @@ public abstract class Parent extends CElement implements IParent {
} }
public IResource getResource() throws CModelException { public IResource getResource() throws CModelException {
return null; return resource;
} }
protected void setChanged () { protected void setChanged () {

View file

@ -7,7 +7,7 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ISourceManipulation; import org.eclipse.cdt.core.model.ISourceManipulation;
import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
@ -43,7 +43,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
if (rename != null) { if (rename != null) {
renamings= new String[] {rename}; renamings= new String[] {rename};
} }
getCRoot().copy(elements, containers, siblings, renamings, force, monitor); getCModel().copy(elements, containers, siblings, renamings, force, monitor);
} }
/** /**
@ -51,7 +51,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
*/ */
public void delete(boolean force, IProgressMonitor monitor) throws CModelException { public void delete(boolean force, IProgressMonitor monitor) throws CModelException {
ICElement[] elements = new ICElement[] {this}; ICElement[] elements = new ICElement[] {this};
getCRoot().delete(elements, force, monitor); getCModel().delete(elements, force, monitor);
} }
/** /**
@ -72,7 +72,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
if (rename != null) { if (rename != null) {
renamings= new String[] {rename}; renamings= new String[] {rename};
} }
getCRoot().move(elements, containers, siblings, renamings, force, monitor); getCModel().move(elements, containers, siblings, renamings, force, monitor);
} }
/** /**
@ -85,7 +85,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
ICElement[] elements= new ICElement[] {this}; ICElement[] elements= new ICElement[] {this};
ICElement[] dests= new ICElement[] {this.getParent()}; ICElement[] dests= new ICElement[] {this.getParent()};
String[] renamings= new String[] {name}; String[] renamings= new String[] {name};
getCRoot().rename(elements, dests, renamings, force, monitor); getCModel().rename(elements, dests, renamings, force, monitor);
} }
/** /**
@ -107,13 +107,13 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
/** /**
* Returns the first parent of the element that is an instance of * Returns the first parent of the element that is an instance of
* ICOpenable. * IOpenable.
*/ */
public ICOpenable getOpenableParent() { public IOpenable getOpenableParent() {
ICElement current = getParent(); ICElement current = getParent();
while (current != null){ while (current != null){
if (current instanceof ICOpenable){ if (current instanceof IOpenable){
return (ICOpenable) current; return (IOpenable) current;
} }
current = current.getParent(); current = current.getParent();
} }

View file

@ -87,7 +87,7 @@ class SourceManipulationInfo extends CElementInfo {
if (rename != null) { if (rename != null) {
renamings= new String[] {rename}; renamings= new String[] {rename};
} }
getElement().getCRoot().copy(elements, containers, siblings, renamings, force, monitor); getElement().getCModel().copy(elements, containers, siblings, renamings, force, monitor);
} }
/** /**
@ -95,7 +95,7 @@ class SourceManipulationInfo extends CElementInfo {
*/ */
public void delete(boolean force, IProgressMonitor monitor) throws CModelException { public void delete(boolean force, IProgressMonitor monitor) throws CModelException {
ICElement[] elements = new ICElement[] {getElement()}; ICElement[] elements = new ICElement[] {getElement()};
getElement().getCRoot().delete(elements, force, monitor); getElement().getCModel().delete(elements, force, monitor);
} }
/** /**
@ -116,7 +116,7 @@ class SourceManipulationInfo extends CElementInfo {
if (rename != null) { if (rename != null) {
renamings= new String[] {rename}; renamings= new String[] {rename};
} }
getElement().getCRoot().move(elements, containers, siblings, renamings, force, monitor); getElement().getCModel().move(elements, containers, siblings, renamings, force, monitor);
} }
/** /**
@ -129,7 +129,7 @@ class SourceManipulationInfo extends CElementInfo {
ICElement[] elements= new ICElement[] {getElement()}; ICElement[] elements= new ICElement[] {getElement()};
ICElement[] dests= new ICElement[] {getElement().getParent()}; ICElement[] dests= new ICElement[] {getElement().getParent()};
String[] renamings= new String[] {name}; String[] renamings= new String[] {name};
getElement().getCRoot().rename(elements, dests, renamings, force, monitor); getElement().getCModel().rename(elements, dests, renamings, force, monitor);
} }
/** /**

View file

@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IInclude; import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
@ -27,16 +28,18 @@ import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* @see ITranslationUnit * @see ITranslationUnit
*/ */
public class TranslationUnit extends CFile implements ITranslationUnit { public class TranslationUnit extends Openable implements ITranslationUnit {
IPath location = null;
SourceManipulationInfo sourceManipulationInfo = null; SourceManipulationInfo sourceManipulationInfo = null;
public TranslationUnit(ICElement parent, IFile file) { public TranslationUnit(ICElement parent, IFile file) {
super(parent, file); super(parent, file, ICElement.C_UNIT);
} }
public TranslationUnit(ICElement parent, IPath path) { public TranslationUnit(ICElement parent, IPath path) {
super(parent, path); super(parent, path, ICElement.C_UNIT);
} }
public ITranslationUnit getTranslationUnit () { public ITranslationUnit getTranslationUnit () {
@ -121,6 +124,32 @@ public class TranslationUnit extends CFile implements ITranslationUnit {
return (IUsing[])aList.toArray(new IUsing[0]); return (IUsing[])aList.toArray(new IUsing[0]);
} }
public void setLocation(IPath loc) {
location = loc;
}
public IPath getLocation() {
if (location == null) {
IFile file = getFile();
if (file != null) {
location = file.getLocation();
} else {
return getPath();
}
}
return location;
}
protected IFile getFile() {
try {
IResource res = getResource();
if (res instanceof IFile) {
return (IFile)res;
}
} catch (CModelException e) {
}
return null;
}
/** /**
* @see ISourceManipulation * @see ISourceManipulation
@ -188,7 +217,7 @@ public class TranslationUnit extends CFile implements ITranslationUnit {
/** /**
* @see org.eclipse.cdt.internal.core.model.CFile#buildStructure(CFileInfo, IProgressMonitor) * @see org.eclipse.cdt.internal.core.model.CFile#buildStructure(CFileInfo, IProgressMonitor)
*/ */
protected void buildStructure(CFileInfo info, IProgressMonitor monitor) throws CModelException { protected void buildStructure(OpenableInfo info, IProgressMonitor monitor) throws CModelException {
if (monitor != null && monitor.isCanceled()) return; if (monitor != null && monitor.isCanceled()) return;
// remove existing (old) infos // remove existing (old) infos
@ -268,9 +297,9 @@ public class TranslationUnit extends CFile implements ITranslationUnit {
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.CResource#generateInfos(CResourceInfo, IProgressMonitor, Map, IResource) * @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(OpenableInfo, IProgressMonitor, Map, IResource)
*/ */
protected boolean generateInfos(CResourceInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException {
// put the info now, because getting the contents requires it // put the info now, because getting the contents requires it
CModelManager.getDefault().putInfo(this, info); CModelManager.getDefault().putInfo(this, info);
TranslationUnitInfo unitInfo = (TranslationUnitInfo) info; TranslationUnitInfo unitInfo = (TranslationUnitInfo) info;
@ -368,14 +397,14 @@ public class TranslationUnit extends CFile implements ITranslationUnit {
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#isConsistent() * @see org.eclipse.cdt.core.model.IOpenable#isConsistent()
*/ */
public boolean isConsistent() throws CModelException { public boolean isConsistent() throws CModelException {
return CModelManager.getDefault().getElementsOutOfSynchWithBuffers().get(this) == null; return CModelManager.getDefault().getElementsOutOfSynchWithBuffers().get(this) == null;
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.CResource#isSourceElement() * @see org.eclipse.cdt.internal.core.model.Openable#isSourceElement()
*/ */
protected boolean isSourceElement() { protected boolean isSourceElement() {
return true; return true;
@ -388,18 +417,18 @@ public class TranslationUnit extends CFile implements ITranslationUnit {
} }
/** /**
* @see org.eclipse.cdt.core.model.ICOpenable#makeConsistent(IProgressMonitor) * @see org.eclipse.cdt.core.model.IOpenable#makeConsistent(IProgressMonitor)
*/ */
public void makeConsistent(IProgressMonitor pm) throws CModelException { public void makeConsistent(IProgressMonitor pm) throws CModelException {
if (!isConsistent()) { if (!isConsistent()) {
// create a new info and make it the current info // create a new info and make it the current info
CFileInfo info = (CFileInfo) createElementInfo(); OpenableInfo info = (OpenableInfo) createElementInfo();
buildStructure(info, pm); buildStructure(info, pm);
} }
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.CResource#openBuffer(IProgressMonitor) * @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(IProgressMonitor)
*/ */
protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException {

View file

@ -18,7 +18,7 @@ import org.eclipse.core.runtime.IPath;
/** /**
* The Element Info of a Translation Unit. * The Element Info of a Translation Unit.
*/ */
class TranslationUnitInfo extends CFileInfo { class TranslationUnitInfo extends OpenableInfo {
/** /**
* Timestamp of original resource at the time this element * Timestamp of original resource at the time this element

View file

@ -8,7 +8,7 @@ package org.eclipse.cdt.internal.core.model;
class VariableInfo extends SourceManipulationInfo { class VariableInfo extends SourceManipulationInfo {
protected int flags; protected int flags;
String typeStr; String typeStr = "";
protected VariableInfo (CElement element) { protected VariableInfo (CElement element) {
super(element); super(element);

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.model;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;