isUpToDate() method

This commit is contained in:
Alexey Kudravtsev
2014-10-02 13:04:38 +04:00
parent 33921f0c99
commit 5eeef1819d
4 changed files with 21 additions and 16 deletions
@@ -17,7 +17,6 @@ package com.intellij.psi;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.impl.file.impl.ResolveScopeManagerImpl;
import com.intellij.util.indexing.*;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
@@ -45,7 +44,7 @@ public class RefQueueIndex extends FileBasedIndexExtension<Void,Void> {
@NotNull
@Override
public Map<Void, Void> map(@NotNull FileContent inputData) {
if (ResolveScopeManagerImpl.ENABLED_REF_BACK) {
if (RefResolveService.ENABLED) {
Project project = inputData.getProject();
RefResolveService.getInstance(project).queue(Collections.singletonList(inputData.getFile()), "Cache updater");
}
@@ -102,7 +101,7 @@ public class RefQueueIndex extends FileBasedIndexExtension<Void,Void> {
return new FileBasedIndex.InputFilter() {
@Override
public boolean acceptInput(@NotNull VirtualFile file) {
return ResolveScopeManagerImpl.ENABLED_REF_BACK && !file.isDirectory() && RefResolveServiceImpl.isSupportedFileType(file);
return RefResolveService.ENABLED && !file.isDirectory() && RefResolveServiceImpl.isSupportedFileType(file);
}
};
}
@@ -114,6 +113,6 @@ public class RefQueueIndex extends FileBasedIndexExtension<Void,Void> {
@Override
public int getVersion() {
return ResolveScopeManagerImpl.ENABLED_REF_BACK ? 0xFF : 0;
return RefResolveService.ENABLED ? 0xFF : 0;
}
}
@@ -50,7 +50,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.psi.impl.PersistentIntList;
import com.intellij.psi.impl.file.impl.ResolveScopeManagerImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ArrayUtil;
@@ -105,7 +104,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
((FutureTask)resolveProcess).run();
myApplication = application;
myProjectFileIndex = projectFileIndex;
if (ResolveScopeManagerImpl.ENABLED_REF_BACK) {
if (ENABLED) {
File indexFile = new File(getStorageDirectory(), "index");
File dataFile = new File(getStorageDirectory(), "data");
fileIsResolved = ConcurrentBitSet.readFrom(new File(getStorageDirectory(), "bitSet"));
@@ -392,8 +391,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
}
private volatile Future<?> resolveProcess = new FutureTask<Object>(EmptyRunnable.getInstance(), null); // write from EDT only
private volatile ProgressIndicator resolveIndicator = new EmptyProgressIndicator();
@Override
public void run() {
while (!myDisposed) {
@@ -443,7 +441,6 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
else {
indicator = new MyProgress();
}
resolveIndicator = indicator;
resolveProcess = ProgressManagerImpl.runProcessWithProgressAsynchronously(backgroundable, indicator, null);
}
}, myProject.getDisposed());
@@ -809,7 +806,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
@Override
@Nullable
public int[] getBackwardIds(@NotNull VirtualFileWithId file) {
if (!upToDate) return null;
if (!isUpToDate()) return null;
int fileId = getAbsId((VirtualFile)file);
return storage.get(fileId);
}
@@ -879,6 +876,11 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
return queued;
}
@Override
public boolean isUpToDate() {
return ENABLED && !myDisposed && upToDate;
}
private static class MyProgress extends ProgressIndicatorBase implements Disposable{
@Override
public void dispose() {
@@ -26,6 +26,11 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public abstract class RefResolveService extends AbstractProjectComponent {
/**
* if true then getUseScope() returns scope restricted to only relevant files which are stored in {@link com.intellij.psi.RefResolveService}
*/
public static final boolean ENABLED = /*ApplicationManager.getApplication().isUnitTestMode() ||*/ Boolean.getBoolean("ref.back");
public RefResolveService(Project project) {
super(project);
}
@@ -47,4 +52,6 @@ public abstract class RefResolveService extends AbstractProjectComponent {
* @return add files to the resolve queue. until all files from there are resolved, the service is in incomplete state and returns null from getBackwardIds()
*/
public abstract boolean queue(@NotNull Collection<VirtualFile> files, Object reason);
public abstract boolean isUpToDate();
}
@@ -38,10 +38,6 @@ import java.util.List;
import java.util.Map;
public class ResolveScopeManagerImpl extends ResolveScopeManager {
/**
* if true then getUseScope() returns scope restricted to only relevant files which are stored in {@link RefResolveService}
*/
public static final boolean ENABLED_REF_BACK = /*ApplicationManager.getApplication().isUnitTestMode() ||*/ Boolean.getBoolean("ref.back");
private final Project myProject;
private final ProjectRootManager myProjectRootManager;
private final PsiManager myManager;
@@ -212,8 +208,9 @@ public class ResolveScopeManagerImpl extends ResolveScopeManager {
GlobalSearchScope scope = isTest
? GlobalSearchScope.moduleTestsWithDependentsScope(module)
: GlobalSearchScope.moduleWithDependentsScope(module);
if (virtualFile instanceof VirtualFileWithId && ENABLED_REF_BACK) {
return RefResolveService.getInstance(myProject).restrictByBackwardIds(virtualFile, scope);
RefResolveService resolveService = RefResolveService.getInstance(myProject);
if (virtualFile instanceof VirtualFileWithId && resolveService.isUpToDate()) {
return resolveService.restrictByBackwardIds(virtualFile, scope);
}
return scope;
}