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

Fix and testcase for updating headers with 'indexAllFiles=false'.

This commit is contained in:
Markus Schorn 2007-04-04 11:29:38 +00:00
parent 9bce2681b6
commit 625b82284d
2 changed files with 46 additions and 2 deletions

View file

@ -18,6 +18,8 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
@ -270,4 +272,46 @@ public class IndexIncludeTest extends IndexTestBase {
assertEquals(isSystem, include.isSystemInclude());
}
public void testUpdateOfIncluded() throws Exception {
String content1 = "int CONTEXT_20070404(x);\n";
String content2 = "int CONTEXT_20070404(y);\n";
String content3 = "#define CONTEXT_20070404(x) ctx_20070404##x\n #include \"included_20070404.h\"\n int source_20070404;\n";
TestSourceReader.createFile(fProject.getProject(), "included_20070404.h", content1);
TestSourceReader.createFile(fProject.getProject(), "notIncluded_20070404.h", "int notIncluded_20070404\n;");
TestSourceReader.createFile(fProject.getProject(), "includer_20070404.cpp", content3);
IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "false");
CCorePlugin.getIndexManager().reindex(fProject);
waitForIndexer();
fIndex.acquireReadLock();
try {
assertEquals(0, fIndex.findBindings("notIncluded_20070404".toCharArray(), IndexFilter.ALL, NPM).length);
assertEquals(1, fIndex.findBindings("source_20070404".toCharArray(), IndexFilter.ALL, NPM).length);
IBinding[] bindings= fIndex.findBindings("ctx_20070404x".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(1, bindings.length);
assertTrue(bindings[0] instanceof IVariable);
}
finally {
fIndex.releaseReadLock();
}
Thread.sleep(1000);
// now change the header and see whether it gets parsed
TestSourceReader.createFile(fProject.getProject(), "included_20070404.h", content2);
TestSourceReader.createFile(fProject.getProject(), "notIncluded_20070404.h", "int notIncluded_20070404\n;");
Thread.sleep(1000);
waitForIndexer();
fIndex.acquireReadLock();
try {
assertEquals(0, fIndex.findBindings("notIncluded_20070404".toCharArray(), IndexFilter.ALL, NPM).length);
IBinding[] bindings= fIndex.findBindings("ctx_20070404y".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(1, bindings.length);
assertTrue(bindings[0] instanceof IVariable);
}
finally {
fIndex.releaseReadLock();
}
}
}

View file

@ -97,13 +97,13 @@ public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
switch (delta.getKind()) {
case ICElementDelta.CHANGED:
if ((flags & ICElementDelta.F_CONTENT) != 0 &&
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()))) {
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) {
changed.add(tu);
}
break;
case ICElementDelta.ADDED:
if (!tu.isWorkingCopy() &&
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()))) {
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) {
added.add(tu);
}
break;