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

Fix for 215112: Source roots not updated if resources are added

This commit is contained in:
Anton Leherbauer 2008-02-05 14:34:46 +00:00
parent e8c725f636
commit 7a90025fb4
2 changed files with 49 additions and 12 deletions

View file

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

View file

@ -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 <code>true</code>, 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.