mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix tests, less garbage during index updates (IDEA-142179)
This commit is contained in:
@@ -27,13 +27,13 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.cache.CacheManager;
|
||||
import com.intellij.psi.impl.cache.TodoCacheManager;
|
||||
import com.intellij.psi.impl.cache.impl.id.IdIndex;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoIndex;
|
||||
import com.intellij.psi.search.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.TodoAttributesUtil;
|
||||
import com.intellij.psi.search.TodoPattern;
|
||||
import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -48,9 +48,6 @@ public class IdCacheTest extends CodeInsightTestCase{
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
|
||||
FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);
|
||||
|
||||
String root = JavaTestUtil.getJavaTestDataPath()+ "/psi/impl/cache/";
|
||||
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaPsiFacadeEx;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.psi.impl.cache.impl.id.IdIndex;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoIndex;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl;
|
||||
@@ -52,15 +51,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class UpdateCacheTest extends PsiTestCase{
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
|
||||
FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);
|
||||
}
|
||||
|
||||
public class UpdateCacheTest extends PsiTestCase {
|
||||
@Override
|
||||
protected void setUpProject() throws Exception {
|
||||
myProjectManager = ProjectManagerEx.getInstanceEx();
|
||||
|
||||
@@ -1716,9 +1716,11 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
fc.putUserData(IndexingDataKeys.PROJECT, project);
|
||||
}
|
||||
|
||||
static final Key<Boolean> ourPhysicalContentKey = Key.create("physical.content.flag");
|
||||
|
||||
private void updateSingleIndex(@NotNull ID<?, ?> indexId, final int inputId, @Nullable FileContent currentFC)
|
||||
throws StorageException {
|
||||
if (ourRebuildStatus.get(indexId).get() == REQUIRES_REBUILD) {
|
||||
if (ourRebuildStatus.get(indexId).get() == REQUIRES_REBUILD && !myIsUnitTestMode) {
|
||||
return; // the index is scheduled for rebuild, no need to update
|
||||
}
|
||||
myLocalModCount++;
|
||||
@@ -1726,7 +1728,8 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
final UpdatableIndex<?, ?, FileContent> index = getIndex(indexId);
|
||||
assert index != null;
|
||||
|
||||
if (currentFC != null && currentFC.getUserData(ourPhysicalContentKey) == null) {
|
||||
boolean hasContent = currentFC != null;
|
||||
if (hasContent && currentFC.getUserData(ourPhysicalContentKey) == null) {
|
||||
currentFC.putUserData(ourPhysicalContentKey, Boolean.TRUE);
|
||||
}
|
||||
|
||||
@@ -1735,10 +1738,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
final Computable<Boolean> update = index.update(inputId, currentFC);
|
||||
|
||||
try {
|
||||
scheduleUpdate(indexId,
|
||||
createUpdateComputableWithBufferingDisabled(update),
|
||||
createIndexedStampUpdateRunnable(indexId, inputId, currentFC != null)
|
||||
);
|
||||
scheduleUpdate(indexId, update, inputId, hasContent);
|
||||
} catch (RuntimeException exception) {
|
||||
Throwable causeToRebuildIndex = getCauseToRebuildIndex(exception);
|
||||
if (causeToRebuildIndex != null) {
|
||||
@@ -1750,51 +1750,51 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
}
|
||||
|
||||
static final Key<Boolean> ourPhysicalContentKey = Key.create("physical.content.flag");
|
||||
|
||||
@NotNull
|
||||
private Runnable createIndexedStampUpdateRunnable(@NotNull final ID<?, ?> indexId,
|
||||
final int fileId,
|
||||
final boolean hasContent) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (hasContent) {
|
||||
IndexingStamp.setFileIndexedStateCurrent(fileId, indexId);
|
||||
}
|
||||
else {
|
||||
IndexingStamp.setFileIndexedStateUnindexed(fileId, indexId);
|
||||
}
|
||||
if (myNotRequiringContentIndices.contains(indexId)) IndexingStamp.flushCache(fileId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Computable<Boolean> createUpdateComputableWithBufferingDisabled(@NotNull final Computable<Boolean> update) {
|
||||
return new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
Boolean result;
|
||||
final StorageGuard.StorageModeExitHandler lock = setDataBufferingEnabled(false);
|
||||
try {
|
||||
result = update.compute();
|
||||
}
|
||||
finally {
|
||||
lock.leave();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void scheduleUpdate(@NotNull ID<?, ?> indexId, @NotNull Computable<Boolean> update, @NotNull Runnable successRunnable) {
|
||||
private void scheduleUpdate(@NotNull final ID<?, ?> indexId, final Computable<Boolean> update, final int inputId, final boolean hasContent) {
|
||||
if (myNotRequiringContentIndices.contains(indexId) && !Registry.is("idea.concurrent.scanning.files.to.index")) {
|
||||
myContentlessIndicesUpdateQueue.submit(update, successRunnable);
|
||||
myContentlessIndicesUpdateQueue.submit(
|
||||
new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
return updateWithBufferingEnabled(update);
|
||||
}
|
||||
},
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
indexedStampUpdate(indexId, inputId, hasContent);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Boolean result = update.compute();
|
||||
if (result == Boolean.TRUE) ApplicationManager.getApplication().runReadAction(successRunnable);
|
||||
if (updateWithBufferingEnabled(update)) {
|
||||
AccessToken accessToken = ReadAction.start();
|
||||
try {
|
||||
indexedStampUpdate(indexId, inputId, hasContent);
|
||||
} finally {
|
||||
accessToken.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void indexedStampUpdate(@NotNull ID<?, ?> indexId, int fileId, boolean hasContent) {
|
||||
if (hasContent) {
|
||||
IndexingStamp.setFileIndexedStateCurrent(fileId, indexId);
|
||||
}
|
||||
else {
|
||||
IndexingStamp.setFileIndexedStateUnindexed(fileId, indexId);
|
||||
}
|
||||
if (myNotRequiringContentIndices.contains(indexId)) IndexingStamp.flushCache(fileId);
|
||||
}
|
||||
|
||||
protected boolean updateWithBufferingEnabled(@NotNull final Computable<Boolean> update) {
|
||||
final StorageGuard.StorageModeExitHandler lock = setDataBufferingEnabled(false);
|
||||
try {
|
||||
return update.compute();
|
||||
}
|
||||
finally {
|
||||
lock.leave();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user