mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup: extracted code related to vfs event filtering from FileBasedIndexImpl to IndexedFilesListener
This commit is contained in:
@@ -565,15 +565,13 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
recordFileScheduledForIndexing(((VirtualFileWithId)file).id, file, contentChange)
|
||||
protected void doInvalidateIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
recordFileScheduledForInvalidation(((VirtualFileWithId)file).id, file, contentChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean invalidateIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
recordFileScheduledForInvalidation(((VirtualFileWithId)file).id, file, contentChange);
|
||||
return true
|
||||
protected void buildIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
recordFileScheduledForIndexing(((VirtualFileWithId)file).id, file, contentChange)
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()).subscribe(
|
||||
|
||||
@@ -126,8 +126,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
private final Set<ID<?, ?>> myUpToDateIndicesForUnsavedOrTransactedDocuments = ContainerUtil.newConcurrentSet();
|
||||
private volatile SmartFMap<Document, PsiFile> myTransactionMap = SmartFMap.emptyMap();
|
||||
|
||||
@Nullable private final String myConfigPath;
|
||||
@Nullable private final String myLogPath;
|
||||
private final boolean myIsUnitTestMode;
|
||||
@Nullable private ScheduledFuture<?> myFlushingFuture;
|
||||
private volatile int myLocalModCount;
|
||||
@@ -166,8 +164,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
myFileDocumentManager = fdm;
|
||||
myFileTypeManager = fileTypeManager;
|
||||
myIsUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
|
||||
myConfigPath = calcConfigPath(PathManager.getConfigPath());
|
||||
myLogPath = calcConfigPath(PathManager.getLogPath());
|
||||
|
||||
final MessageBusConnection connection = bus.connect();
|
||||
connection.subscribe(PsiDocumentTransactionListener.TOPIC, new PsiDocumentTransactionListener() {
|
||||
@@ -313,18 +309,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String calcConfigPath(@NotNull String path) {
|
||||
try {
|
||||
final String _path = FileUtil.toSystemIndependentName(new File(path).getCanonicalPath());
|
||||
return _path.endsWith("/") ? _path : _path + "/";
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if registered index requires full rebuild for some reason, e.g. is just created or corrupted
|
||||
*/
|
||||
@@ -1823,9 +1807,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
|
||||
private final class ChangedFilesCollector extends IndexedFilesListener {
|
||||
private final ConcurrentIntObjectMap<VirtualFile> myFilesToUpdate = ContainerUtil.createConcurrentIntObjectMap();
|
||||
|
||||
private final ManagingFS myManagingFS = ManagingFS.getInstance();
|
||||
|
||||
@Override
|
||||
protected void buildIndicesForFileRecursively(@NotNull VirtualFile file, boolean contentChange) {
|
||||
cleanProcessedFlag(file);
|
||||
@@ -1858,20 +1839,8 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean invalidateIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
if (isUnderConfigOrSystem(file)) {
|
||||
return false;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
doInvalidateIndicesForFile(file, contentChange);
|
||||
if (!isMock(file) && !myManagingFS.wereChildrenAccessed(file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
doInvalidateIndicesForFile(file, contentChange);
|
||||
}
|
||||
return true;
|
||||
protected void doInvalidateIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
FileBasedIndexImpl.this.doInvalidateIndicesForFile(file, contentChange);
|
||||
}
|
||||
|
||||
void scheduleForUpdate(VirtualFile file) {
|
||||
@@ -2071,13 +2040,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
(isMock(file) || !getIndex(indexId).isIndexedStateForFile(((NewVirtualFile)file).getId(), file));
|
||||
}
|
||||
|
||||
private boolean isUnderConfigOrSystem(@NotNull VirtualFile file) {
|
||||
final String filePath = file.getPath();
|
||||
return myConfigPath != null && FileUtil.startsWith(filePath, myConfigPath) ||
|
||||
myLogPath != null && FileUtil.startsWith(filePath, myLogPath);
|
||||
}
|
||||
|
||||
private static boolean isMock(final VirtualFile file) {
|
||||
static boolean isMock(final VirtualFile file) {
|
||||
return !(file instanceof NewVirtualFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,21 +16,36 @@
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.roots.ContentIterator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.ManagingFS;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ConcurrentIntObjectMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class IndexedFilesListener extends VirtualFileAdapter implements BulkFileListener {
|
||||
private final ManagingFS myManagingFS = ManagingFS.getInstance();
|
||||
@Nullable private final String myConfigPath;
|
||||
@Nullable private final String myLogPath;
|
||||
|
||||
public IndexedFilesListener() {
|
||||
myConfigPath = calcConfigPath(PathManager.getConfigPath());
|
||||
myLogPath = calcConfigPath(PathManager.getLogPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileMoved(@NotNull VirtualFileMoveEvent event) {
|
||||
buildIndicesForFileRecursively(event.getFile(), false);
|
||||
@@ -100,9 +115,25 @@ public abstract class IndexedFilesListener extends VirtualFileAdapter implements
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean invalidateIndicesForFile(VirtualFile file, boolean contentChange) {
|
||||
if (isUnderConfigOrSystem(file)) {
|
||||
return false;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
doInvalidateIndicesForFile(file, contentChange);
|
||||
if (!FileBasedIndexImpl.isMock(file) && !myManagingFS.wereChildrenAccessed(file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
doInvalidateIndicesForFile(file, contentChange);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void iterateIndexableFiles(VirtualFile file, ContentIterator iterator);
|
||||
protected abstract void buildIndicesForFile(VirtualFile file, boolean contentChange);
|
||||
protected abstract boolean invalidateIndicesForFile(VirtualFile file, boolean contentChange);
|
||||
protected abstract void doInvalidateIndicesForFile(VirtualFile file, boolean contentChange);
|
||||
|
||||
protected void invalidateIndicesRecursively(@NotNull final VirtualFile file, final boolean contentChange) {
|
||||
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
|
||||
@@ -132,6 +163,24 @@ public abstract class IndexedFilesListener extends VirtualFileAdapter implements
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String calcConfigPath(@NotNull String path) {
|
||||
try {
|
||||
final String _path = FileUtil.toSystemIndependentName(new File(path).getCanonicalPath());
|
||||
return _path.endsWith("/") ? _path : _path + "/";
|
||||
}
|
||||
catch (IOException e) {
|
||||
FileBasedIndexImpl.LOG.info(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUnderConfigOrSystem(@NotNull VirtualFile file) {
|
||||
final String filePath = file.getPath();
|
||||
return myConfigPath != null && FileUtil.startsWith(filePath, myConfigPath) ||
|
||||
myLogPath != null && FileUtil.startsWith(filePath, myLogPath);
|
||||
}
|
||||
|
||||
static final short ADD_TO_INDICES = 1;
|
||||
static final short REMOVE_FROM_INDICES = 2;
|
||||
static final short UPDATE_INDICES_CONTENT_CHANGED = 4;
|
||||
@@ -191,7 +240,7 @@ public abstract class IndexedFilesListener extends VirtualFileAdapter implements
|
||||
}
|
||||
|
||||
private void updateChange(int fileId, VirtualFile file, short mask) {
|
||||
if (DebugAssertions.DEBUG) assert ApplicationManager.getApplication().isWriteAccessAllowed();
|
||||
if (DebugAssertions.DEBUG) assert ApplicationManager.getApplication().isDispatchThread();
|
||||
ChangeInfo changeInfo = myChangeInfos.get(fileId);
|
||||
if (changeInfo == null) myChangeInfos.put(fileId, new ChangeInfo(file, mask));
|
||||
else changeInfo.changeOperation(mask);
|
||||
|
||||
Reference in New Issue
Block a user