1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 283080: Updating headers in non-source folders.

This commit is contained in:
Markus Schorn 2010-04-08 11:49:24 +00:00
parent 7824e2e314
commit df81d1f40e
5 changed files with 153 additions and 21 deletions

View file

@ -71,6 +71,10 @@ import org.eclipse.cdt.core.model.CoreModel;
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.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.settings.model.CSourceEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.core.testplugin.TestScannerProvider;
@ -79,10 +83,12 @@ import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
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.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -2209,4 +2215,65 @@ public class IndexBugsTests extends BaseTestCase {
} }
} }
public void testUpdateNonSrcFolderHeader_283080() throws Exception {
IIndexBinding[] r;
final IProject prj = fCProject.getProject();
final IFolder src= prj.getFolder("src");
final IFolder h= prj.getFolder("h");
src.create(true, false, null);
h.create(true, false, null);
assertTrue(src.exists());
assertTrue(h.exists());
ICProjectDescription desc= CCorePlugin.getDefault().getProjectDescription(prj);
assertNotNull(desc);
desc.getActiveConfiguration().setSourceEntries(new ICSourceEntry[] {
new CSourceEntry(src, new IPath[0], ICSettingEntry.SOURCE_PATH)
});
CCorePlugin.getDefault().setProjectDescription(prj, desc);
TestSourceReader.createFile(h, "a.h", "int version1;");
waitForIndexer(fCProject);
final IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
index.acquireReadLock();
try {
r = index.findBindings("version1".toCharArray(), IndexFilter.ALL_DECLARED, null);
assertEquals(0, r.length);
} finally {
index.releaseReadLock();
}
IFile s= TestSourceReader.createFile(h, "a.h", "int version2;");
waitForIndexer(fCProject);
index.acquireReadLock();
try {
r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null);
assertEquals(0, r.length);
} finally {
index.releaseReadLock();
}
s= TestSourceReader.createFile(src, "source.cpp", "#include \"../h/a.h\"");
waitUntilFileIsIndexed(s, INDEX_WAIT_TIME);
index.acquireReadLock();
try {
r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null);
assertEquals(1, r.length);
} finally {
index.releaseReadLock();
}
s= TestSourceReader.createFile(h, "a.h", "int version3;");
waitUntilFileIsIndexed(s, INDEX_WAIT_TIME);
index.acquireReadLock();
try {
r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null);
assertEquals(0, r.length);
r = index.findBindings("version3".toCharArray(), IndexFilter.ALL_DECLARED, null);
assertEquals(1, r.length);
} finally {
index.releaseReadLock();
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Symbian Software Systems and others. * Copyright (c) 2007, 2010 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -54,6 +54,7 @@ import org.eclipse.cdt.internal.core.index.provider.IIndexFragmentProvider;
import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.cdt.internal.core.pdom.indexer.DeltaAnalyzer;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -100,8 +101,8 @@ public class IndexProviderManagerTest extends IndexTestBase {
} }
public void testProvider_SimpleLifeCycle_200958() throws Exception { public void testProvider_SimpleLifeCycle_200958() throws Exception {
for(int i=0; i<DPS.length; i++) for (Class element : DPS)
DPT.reset(DPS[i]); DPT.reset(element);
List cprojects = new ArrayList(), expectedTrace = new ArrayList(); List cprojects = new ArrayList(), expectedTrace = new ArrayList();
try { try {
@ -111,14 +112,14 @@ public class IndexProviderManagerTest extends IndexTestBase {
cprojects.add(cproject); cprojects.add(cproject);
expectedTrace.add(cproject); expectedTrace.add(cproject);
} }
for(int i=0; i<DPS.length; i++) for (Class element : DPS)
assertEquals(expectedTrace, DPT.getProjectsTrace(DPS[i])); assertEquals(expectedTrace, DPT.getProjectsTrace(element));
for(int i=0; i<expectedTrace.size(); i++) { for(int i=0; i<expectedTrace.size(); i++) {
ICProject cproject = (ICProject) expectedTrace.get(i); ICProject cproject = (ICProject) expectedTrace.get(i);
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
} }
for(int i=0; i<DPS.length; i++) for (Class element : DPS)
assertEquals(expectedTrace, DPT.getProjectsTrace(DPS[i])); assertEquals(expectedTrace, DPT.getProjectsTrace(element));
} finally { } finally {
for(int i=0; i<cprojects.size(); i++) { for(int i=0; i<cprojects.size(); i++) {
ICProject cproject = (ICProject) expectedTrace.get(i); ICProject cproject = (ICProject) expectedTrace.get(i);
@ -297,8 +298,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
} }
private void assertFragmentPresent(String id, String version, IIndexFragment[] fragments) throws Exception { private void assertFragmentPresent(String id, String version, IIndexFragment[] fragments) throws Exception {
for(int i=0; i<fragments.length; i++) { for (IIndexFragment candidate : fragments) {
IIndexFragment candidate= fragments[i];
String cid= null, csver= null; String cid= null, csver= null;
try { try {
candidate.acquireReadLock(); candidate.acquireReadLock();
@ -317,6 +317,8 @@ public class IndexProviderManagerTest extends IndexTestBase {
IIndex index; IIndex index;
ICProject cproject = null; ICProject cproject = null;
// Modifying the .project file triggers an indexer job, suppress that:
DeltaAnalyzer.sSuppressPotentialTUs= true;
try { try {
cproject = CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); cproject = CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER);
IProject project= cproject.getProject(); IProject project= cproject.getProject();
@ -369,6 +371,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
// there should be no change from the previous state (also config2) // there should be no change from the previous state (also config2)
assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId());
} finally { } finally {
DeltaAnalyzer.sSuppressPotentialTUs= false;
if (cproject != null) { if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
} }

View file

@ -12,38 +12,45 @@ package org.eclipse.cdt.internal.core.pdom.indexer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.model.ICContainer; 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.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
public class DeltaAnalyzer { public class DeltaAnalyzer {
private List<ITranslationUnit> fForce= new ArrayList<ITranslationUnit>(); private final List<ITranslationUnit> fForce= new ArrayList<ITranslationUnit>();
private List<ITranslationUnit> fChanged= new ArrayList<ITranslationUnit>(); private final List<ITranslationUnit> fChanged= new ArrayList<ITranslationUnit>();
private List<ITranslationUnit> fRemoved= new ArrayList<ITranslationUnit>(); private final List<ITranslationUnit> fRemoved= new ArrayList<ITranslationUnit>();
// For testing purposes, only.
public static boolean sSuppressPotentialTUs= false;
public DeltaAnalyzer() { public DeltaAnalyzer() {
} }
public void analyzeDelta(ICElementDelta delta) throws CoreException { public void analyzeDelta(ICElementDelta delta) throws CoreException {
processDelta(delta); processDelta(delta, new HashSet<IResource>());
} }
private void processDelta(ICElementDelta delta) throws CoreException { private void processDelta(ICElementDelta delta, Set<IResource> handled) throws CoreException {
int flags = delta.getFlags(); final int flags = delta.getFlags();
if ((flags & ICElementDelta.F_CHILDREN) != 0) { if ((flags & ICElementDelta.F_CHILDREN) != 0) {
ICElementDelta[] children = delta.getAffectedChildren(); for (ICElementDelta child : delta.getAffectedChildren()) {
for (int i = 0; i < children.length; ++i) { processDelta(child, handled);
processDelta(children[i]);
} }
} }
ICElement element = delta.getElement(); final ICElement element = delta.getElement();
handled.add(element.getResource());
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_UNIT: case ICElement.C_UNIT:
ITranslationUnit tu = (ITranslationUnit)element; ITranslationUnit tu = (ITranslationUnit)element;
@ -70,6 +77,28 @@ public class DeltaAnalyzer {
} }
break; break;
} }
final IResourceDelta[] rDeltas= delta.getResourceDeltas();
if (rDeltas != null && !sSuppressPotentialTUs) {
for (IResourceDelta rd: rDeltas) {
final int rdkind = rd.getKind();
if (rdkind != IResourceDelta.ADDED) {
IResource res= rd.getResource();
if (res instanceof IFile && handled.add(res)) {
switch (rdkind) {
case IResourceDelta.CHANGED:
if ((rd.getFlags() & IResourceDelta.CONTENT) != 0) {
fChanged.add(new PotentialTranslationUnit(element, (IFile) res));
}
break;
case IResourceDelta.REMOVED:
fRemoved.add(new PotentialTranslationUnit(element, (IFile) res));
break;
}
}
}
}
}
} }
private void collectSources(ICContainer container, Collection<ITranslationUnit> sources) throws CoreException { private void collectSources(ICContainer container, Collection<ITranslationUnit> sources) throws CoreException {

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2010 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.core.resources.IFile;
/**
* Used for modified files that are not below a source root. In case such a file
* is part of the index it needs to be updated, otherwise it shall be ignored.
*/
public class PotentialTranslationUnit extends TranslationUnit {
public PotentialTranslationUnit(ICElement parent, IFile file) {
super(parent, file, CCorePlugin.CONTENT_TYPE_CHEADER);
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -42,6 +42,10 @@ import org.eclipse.core.runtime.content.IContentType;
* @since 5.0 * @since 5.0
*/ */
public class ProjectIndexerInputAdapter extends IndexerInputAdapter { public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
/**
* mstodo
*/
private static final AbstractLanguage[] NO_LANGUAGE = new AbstractLanguage[0];
private final ICProject fCProject; private final ICProject fCProject;
private final HashMap<String, IIndexFileLocation> fIflCache; private final HashMap<String, IIndexFileLocation> fIflCache;
private final FileExistsCache fExistsCache; private final FileExistsCache fExistsCache;
@ -163,6 +167,9 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
@Override @Override
public AbstractLanguage[] getLanguages(Object tuo, boolean bothForHeaders) { public AbstractLanguage[] getLanguages(Object tuo, boolean bothForHeaders) {
if (tuo instanceof PotentialTranslationUnit)
return NO_LANGUAGE;
ITranslationUnit tu= (ITranslationUnit) tuo; ITranslationUnit tu= (ITranslationUnit) tuo;
try { try {
ILanguage lang= tu.getLanguage(); ILanguage lang= tu.getLanguage();
@ -184,7 +191,7 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
catch (CoreException e) { catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return new AbstractLanguage[0]; return NO_LANGUAGE;
} }
@Override @Override