stub index modification stamp, first iteration

This commit is contained in:
Maxim.Mossienko
2016-07-06 00:14:28 +02:00
parent 97a41b90d2
commit e226f3dad9
2 changed files with 34 additions and 0 deletions
@@ -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();
@@ -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;