diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index bf32bd91a41..edb133e8101 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 QNX Software Systems and others. + * Copyright (c) 2000, 2008 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -661,6 +662,7 @@ public class CProject extends Openable implements ICProject { info.setChildren(children); if (info instanceof CProjectInfo) { CProjectInfo pinfo = (CProjectInfo)info; + pinfo.sourceRoots= (ISourceRoot[])sourceRoots.toArray(new ISourceRoot[sourceRoots.size()]); pinfo.setNonCResources(null); } return true; 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 75065c953af..3cadc6eb82c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.core.model; +import java.util.Arrays; + import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchive; @@ -492,17 +494,31 @@ final class DeltaProcessor { fCurrentDelta.addResourceDelta(delta); return; case ICElement.C_PROJECT: { - ((CProjectInfo)info).setNonCResources(null); - // deal with project == sourceroot. For that case the parent could have been the sourceroot - // so we must update the sourceroot nonCResource array also. - ICProject cproject = (ICProject)parent; - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; i++) { - IResource r = roots[i].getResource(); - if (r instanceof IProject) { - CElementInfo cinfo = (CElementInfo) CModelManager.getDefault().peekAtInfo(roots[i]); - if (cinfo instanceof CContainerInfo) { - ((CContainerInfo)cinfo).setNonCResources(null); + final CProjectInfo pInfo= (CProjectInfo)info; + pInfo.setNonCResources(null); + + ISourceRoot[] roots= pInfo.sourceRoots; + if (roots != null) { + ICProject cproject = (ICProject)parent; + if (isFolderAddition(delta)) { + // if source roots changed - refresh from scratch + // see http://bugs.eclipse.org/215112 + pInfo.sourceRoots= null; + ISourceRoot[] newRoots= cproject.getAllSourceRoots(); + if (!Arrays.equals(roots, newRoots)) { + cproject.close(); + break; + } + } + // deal with project == sourceroot. For that case the parent could have been the sourceroot + // so we must update the sourceroot nonCResource array also. + for (int i = 0; i < roots.length; i++) { + IResource r = roots[i].getResource(); + if (r instanceof IProject) { + CElementInfo cinfo = (CElementInfo) CModelManager.getDefault().peekAtInfo(roots[i]); + if (cinfo instanceof CContainerInfo) { + ((CContainerInfo)cinfo).setNonCResources(null); + } } } } @@ -525,6 +541,25 @@ final class DeltaProcessor { } } + /** + * Test whether this delta or any of its children represents a folder addition. + * @param delta + * @return true, if the delta contains at least one new folder + */ + private static boolean isFolderAddition(IResourceDelta delta) { + if (delta.getResource().getType() != IResource.FOLDER) + return false; + if (delta.getKind() == IResourceDelta.ADDED) + return true; + IResourceDelta[] children= delta.getAffectedChildren(); + for (int i = 0; i < children.length; i++) { + if (isFolderAddition(children[i])) { + return true; + } + } + return false; + } + /* * Update the current delta (ie. add/remove/change the given element) and update the * correponding index.