mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
stub index modification stamp, first iteration
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user