push VFS event merger into IndexedFilesListener to simplify implementations: move id calculation

GitOrigin-RevId: 41228a3f1eca2a3b29389610034ac666e4e5af60
This commit is contained in:
peter
2019-06-11 18:16:54 +03:00
committed by intellij-monorepo-bot
parent bdaf714ff3
commit 086473d571
3 changed files with 11 additions and 17 deletions
@@ -2235,7 +2235,7 @@ public final class FileBasedIndexImpl extends FileBasedIndex implements Disposab
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile instanceof VirtualFileWithId) {
myChangedFilesCollector.getEventMerger().recordTransientStateChangeEvent(getFileId(virtualFile), virtualFile);
myChangedFilesCollector.getEventMerger().recordTransientStateChangeEvent(virtualFile);
}
}
}
@@ -49,14 +49,14 @@ public abstract class IndexedFilesListener implements BulkFileListener {
protected void buildIndicesForFileRecursively(@NotNull final VirtualFile file, final boolean contentChange) {
if (file.isDirectory()) {
final ContentIterator iterator = fileOrDir -> {
buildIndicesForFile(fileOrDir, contentChange);
myEventMerger.recordFileEvent(fileOrDir, contentChange);
return true;
};
iterateIndexableFiles(file, iterator);
}
else {
buildIndicesForFile(file, contentChange);
myEventMerger.recordFileEvent(file, contentChange);
}
}
@@ -64,18 +64,12 @@ public abstract class IndexedFilesListener implements BulkFileListener {
if (isUnderConfigOrSystem(file)) {
return false;
}
final int fileId = Math.abs(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file));
myEventMerger.recordBeforeFileEvent(fileId, file, contentChange);
myEventMerger.recordBeforeFileEvent(file, contentChange);
return !file.isDirectory() || FileBasedIndexImpl.isMock(file) || myManagingFS.wereChildrenAccessed(file);
}
protected abstract void iterateIndexableFiles(@NotNull VirtualFile file, @NotNull ContentIterator iterator);
private void buildIndicesForFile(@NotNull VirtualFile file, boolean contentChange) {
int fileId = FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file);
myEventMerger.recordFileEvent(fileId, file, contentChange);
}
void invalidateIndicesRecursively(@NotNull final VirtualFile file, final boolean contentChange) {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
@@ -32,20 +32,20 @@ import java.util.stream.Stream;
public class VfsEventsMerger {
static final boolean DEBUG = (false);
//static final boolean DEBUG = (true);
public void recordFileEvent(int fileId, @NotNull VirtualFile file, boolean contentChange) {
public void recordFileEvent(@NotNull VirtualFile file, boolean contentChange) {
if (DEBUG) System.out.println("Request build indices for file:" + file.getPath() + ", contentChange:" + contentChange);
updateChange(fileId, file, contentChange ? FILE_CONTENT_CHANGED : FILE_ADDED);
updateChange(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file), file, contentChange ? FILE_CONTENT_CHANGED : FILE_ADDED);
}
public void recordBeforeFileEvent(int fileId, @NotNull VirtualFile file, boolean contentChanged) {
public void recordBeforeFileEvent(@NotNull VirtualFile file, boolean contentChanged) {
if (DEBUG) System.out.println("Request invalidate indices for file:" + file.getPath() + ", contentChange:" + contentChanged);
updateChange(fileId, file, contentChanged ? BEFORE_FILE_CONTENT_CHANGED : FILE_REMOVED);
updateChange(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file), file, contentChanged ? BEFORE_FILE_CONTENT_CHANGED : FILE_REMOVED);
}
public void recordTransientStateChangeEvent(int fileId, @NotNull VirtualFile file) {
public void recordTransientStateChangeEvent(@NotNull VirtualFile file) {
if (DEBUG) System.out.println("Transient state changed for file:" + file.getPath());
updateChange(fileId, file, FILE_TRANSIENT_STATE_CHANGED);
updateChange(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file), file, FILE_TRANSIENT_STATE_CHANGED);
}
private final AtomicInteger myPublishedEventIndex = new AtomicInteger();