diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java index d703488b305..7d346ab4e78 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java @@ -44,7 +44,7 @@ public class ArchiveContainer extends Openable implements IArchiveContainer { protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { // this will bootstrap/start the runner for the project. - CModelManager.getDefault().getBinaryRunner(getCProject()); + CModelManager.getDefault().getBinaryRunner(getCProject(), true); return true; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java index b4c5fc8dd28..1ef8a5713cc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java @@ -20,7 +20,7 @@ public class ArchiveContainerInfo extends OpenableInfo { } synchronized void sync() { - BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject()); + BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject(), true); if (runner != null) { runner.waitIfRunning(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java index cb3f1abb7cc..631ab2133a2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java @@ -54,7 +54,7 @@ public class BinaryContainer extends Openable implements IBinaryContainer { protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { // this will bootstrap/start the runner for the project. - CModelManager.getDefault().getBinaryRunner(getCProject()); + CModelManager.getDefault().getBinaryRunner(getCProject(), true); return true; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java index d0bae743b10..26716fcc18c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java @@ -20,7 +20,7 @@ public class BinaryContainerInfo extends OpenableInfo { } synchronized void sync() { - BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject()); + BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject(), true); if (runner != null) { runner.waitIfRunning(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index e80e9c64c78..a2c6a4d5b9a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -152,8 +152,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe // Register to the workspace; ResourcesPlugin.getWorkspace().addResourceChangeListener(factory, - IResourceChangeEvent.PRE_BUILD - | IResourceChangeEvent.POST_CHANGE + IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE); @@ -585,14 +584,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } } - public BinaryRunner getBinaryRunner(ICProject project) { + public BinaryRunner getBinaryRunner(ICProject project, boolean start) { BinaryRunner runner = null; synchronized(binaryRunners) { runner = (BinaryRunner)binaryRunners.get(project.getProject()); if (runner == null) { runner = new BinaryRunner(project.getProject()); binaryRunners.put(project.getProject(), runner); - runner.start(); + if (start) { + runner.start(); + } } } return runner; @@ -601,6 +602,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe public void removeBinaryRunner(ICProject cproject) { removeBinaryRunner(cproject.getProject()); } + public void removeBinaryRunner(IProject project) { BinaryRunner runner = (BinaryRunner) binaryRunners.remove(project); if (runner != null) { @@ -677,13 +679,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } break; - case IResourceChangeEvent.PRE_BUILD : - // No need now. - if(delta != null) { - this.checkProjectsBeingAddedOrRemoved(delta); - } - break; - case IResourceChangeEvent.POST_CHANGE : try { if (delta != null) { @@ -928,52 +923,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } } - /** - * Process the given delta and look for projects being added, opened, - * or closed - */ - public void checkProjectsBeingAddedOrRemoved(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - if (this.cProjectsCache == null) { - try { - this.cProjectsCache = this.getCModel().getCProjects(); - } catch (CModelException e) { - } - } - - IResourceDelta[] children = delta.getAffectedChildren(); - for (int i = 0, length = children.length; i < length; i++) { - this.checkProjectsBeingAddedOrRemoved(children[i]); - } - break; - case IResource.PROJECT : - if (0 != (delta.getFlags() & IResourceDelta.OPEN)) { - IProject project = (IProject) resource; - if (!project.isOpen()) { - // project closing... stop the runner. - BinaryRunner runner = (BinaryRunner)binaryRunners.get(project); - if (runner != null ) { - runner.stop(); - } - } else { - if ( binaryRunners.get(project) == null ) { - // project opening... lets add the runner to the - // map but no need to start it since the deltas - // will populate containers - binaryRunners.put(project, new BinaryRunner(project)); - } - } - } else if (0 != (delta.getFlags() & IResourceDelta.REMOVED)) { - IProject project = (IProject) resource; - removeBinaryRunner(project); - binaryParsersMap.remove(project); - } - break; - } - } - /** * Returns the set of elements which are out of synch with their buffers. */ @@ -1125,6 +1074,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe public void deleting(IProject project){ // discard all indexing jobs for this project this.getIndexManager().discardJobs(project.getName()); + removeBinaryRunner(project); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 724da96dc9d..7733a65940d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -428,7 +428,7 @@ public class DeltaProcessor { try { IResource resource = delta.getResource(); ICElement current = createElement(resource); - updateChildren = updateCurrentDeltaAndIndex(delta); + updateChildren = updateCurrentDeltaAndIndex(current, delta); if (current == null || current instanceof ISourceRoot) { nonCResourcesChanged(parent, delta); } else if (current instanceof ICProject) { @@ -437,7 +437,8 @@ public class DeltaProcessor { if (!cprj.getProject().isOpen() || cModel.findCProject(cprj.getProject()) == null) { nonCResourcesChanged(parent, delta); } - } else { + } + if (current != null) { parent = current; } } catch (CModelException e) { @@ -489,10 +490,9 @@ public class DeltaProcessor { * Returns whether the children of the given delta must be processed. * @throws a CModelException if the delta doesn't correspond to a c element of the given type. */ - private boolean updateCurrentDeltaAndIndex(IResourceDelta delta) throws CModelException { + private boolean updateCurrentDeltaAndIndex(ICElement element, IResourceDelta delta) throws CModelException { IResource resource = delta.getResource(); - ICElement element = createElement(resource); switch (delta.getKind()) { case IResourceDelta.ADDED : @@ -500,7 +500,7 @@ public class DeltaProcessor { updateIndexAddResource(element, delta); elementAdded(element, delta); } - return false; + return true; case IResourceDelta.REMOVED : if (element != null) { @@ -523,15 +523,21 @@ public class DeltaProcessor { } else if (resource.getType() == IResource.PROJECT) { if ((flags & IResourceDelta.OPEN) != 0) { // project has been opened or closed - IProject res = (IProject)resource; + IProject project = (IProject)resource; if (element != null) { - if (res.isOpen()) { + if (project.isOpen()) { + if ( CoreModel.hasCNature(project) ) { + // project opening... lets add the runner to the + // map but no need to start it since the deltas + // will populate containers + CModelManager.getDefault().getBinaryRunner((ICProject)element, false); + } elementOpened(element, delta); updateIndexAddResource(element, delta); - } else { - elementClosed(element, delta); - updateIndexRemoveResource(element, delta); + return true; } + elementClosed(element, delta); + updateIndexRemoveResource(element, delta); //Don't process children return false; } @@ -552,7 +558,7 @@ public class DeltaProcessor { elementRemoved(element, delta); updateIndexRemoveResource(element, delta); } - return false; + return true; } } }