diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy index 32ab8e9cdbf7..d83526bd55c1 100644 --- a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy @@ -43,6 +43,7 @@ import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiSearchHelper import com.intellij.psi.stubs.SerializedStubTree import com.intellij.psi.stubs.StubIndex +import com.intellij.psi.stubs.StubIndexImpl import com.intellij.psi.stubs.StubUpdatingIndex import com.intellij.testFramework.IdeaTestUtil import com.intellij.testFramework.PlatformTestUtil @@ -431,6 +432,30 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase { assertTrue(stamp != ((FileBasedIndexImpl)FileBasedIndex.instance).getIndexModificationStamp(IdIndex.NAME, project)) } + public void "test no stub index stamp update when no change"() throws IOException { + final VirtualFile vFile = myFixture.addClass("class Foo {}").getContainingFile().getVirtualFile(); + def stamp = ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project) + + VfsUtil.saveText(vFile, "class Foo { int foo; }") + assertTrue(stamp == ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project)) + + VfsUtil.saveText(vFile, "class Foo2 { }") + assertTrue(stamp != ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project)) + + final Document document = FileDocumentManager.getInstance().getDocument(vFile); + document.setText("class Foo3 {}") + PsiDocumentManager.getInstance(project).commitAllDocuments(); + stamp = ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project) + + document.setText("class Foo3 { int foo; }") + PsiDocumentManager.getInstance(project).commitAllDocuments(); + assertTrue(stamp == ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project)) + + document.setText("class Foo2 { }") + PsiDocumentManager.getInstance(project).commitAllDocuments(); + assertTrue(stamp != ((StubIndexImpl)StubIndex.instance).getIndexModificationStamp(JavaStubIndexKeys.CLASS_SHORT_NAMES, project)) + } + public void "test do not collect stub tree while holding stub elements"() throws IOException { final VirtualFile vFile = myFixture.addClass("class Foo {}").getContainingFile().getVirtualFile(); diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java index 6941cc352c0c..4f2b2014fc2c 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java @@ -198,6 +198,15 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe IndexingStamp.rewriteVersion(versionFile, version); // todo snapshots indices } + public long getIndexModificationStamp(StubIndexKey indexId, @NotNull Project project) { + MyIndex index = getAsyncState().myIndices.get(indexId); + if (index != null) { + FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, GlobalSearchScope.allScope(project)); + return index.getModificationStamp(); + } + return -1; + } + public void flush() throws StorageException { if (!myInitialized) { return;