diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index a7ec8c4fddd..9988f47fdfc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -488,4 +489,53 @@ public class IndexBugsTests extends BaseTestCase { fIndex.releaseReadLock(); } } + + // typedef int T20070213; + public void _test173997() throws Exception { + waitForIndexer(); + String content= getContentsForTest(1)[0].toString(); + + IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + + fIndex.acquireReadLock(); + try { + IBinding[] bindings= fIndex.findBindings("T20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM); + assertEquals(1, bindings.length); + assertTrue(bindings[0] instanceof ITypedef); + ITypedef td= (ITypedef) bindings[0]; + IType type= td.getType(); + assertTrue(type instanceof IBasicType); + IBasicType btype= (IBasicType) type; + assertEquals(IBasicType.t_int, btype.getType()); + } + finally { + fIndex.releaseReadLock(); + } + + long timestamp= file.getLocalTimeStamp(); + content= "int UPDATED20070213;\n" + content.replaceFirst("int", "float"); + file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + + fIndex.acquireReadLock(); + try { + // double check if file was indexed + IBinding[] bindings= fIndex.findBindings("UPDATED20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM); + assertEquals(1, bindings.length); + + bindings= fIndex.findBindings("T20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM); + assertEquals(1, bindings.length); + assertTrue(bindings[0] instanceof ITypedef); + ITypedef td= (ITypedef) bindings[0]; + IType type= td.getType(); + assertTrue(type instanceof IBasicType); + IBasicType btype= (IBasicType) type; + assertTrue(IBasicType.t_int != btype.getType()); + assertEquals(IBasicType.t_float, btype.getType()); + } + finally { + fIndex.releaseReadLock(); + } + } } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index 2f07868efe9..2764ba0b062 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -220,8 +220,12 @@ public class TestSourceReader { InputStream stream = new ByteArrayInputStream(contents.getBytes()); //Create file input stream if (file.exists()) { + long timestamp= file.getLocalTimeStamp(); file.setContents(stream, false, false, new NullProgressMonitor()); - } + if (file.getLocalTimeStamp() == timestamp) { + file.setLocalTimeStamp(timestamp+1000); + } + } else { file.create(stream, false, new NullProgressMonitor()); }