use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerManagerImpl method before.
@Override
public void before(@NotNull final List<? extends VFileEvent> events) {
List<FilePointerPartNode> toFireEvents = new ArrayList<>();
List<FilePointerPartNode> toUpdateUrl = new ArrayList<>();
VirtualFilePointer[] toFirePointers;
synchronized (this) {
incModificationCount();
for (VFileEvent event : events) {
if (event instanceof VFileDeleteEvent) {
final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
addPointersUnder(deleteEvent.getFile(), false, "", toFireEvents);
} else if (event instanceof VFileCreateEvent) {
final VFileCreateEvent createEvent = (VFileCreateEvent) event;
addPointersUnder(createEvent.getParent(), true, createEvent.getChildName(), toFireEvents);
} else if (event instanceof VFileCopyEvent) {
final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
addPointersUnder(copyEvent.getNewParent(), true, copyEvent.getFile().getName(), toFireEvents);
} else if (event instanceof VFileMoveEvent) {
final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
VirtualFile eventFile = moveEvent.getFile();
addPointersUnder(moveEvent.getNewParent(), true, eventFile.getName(), toFireEvents);
List<FilePointerPartNode> nodes = new ArrayList<>();
addPointersUnder(eventFile, false, "", nodes);
// files deleted from eventFile and created in moveEvent.getNewParent()
toFireEvents.addAll(nodes);
for (FilePointerPartNode node : nodes) {
VirtualFilePointerImpl pointer = node.getAnyPointer();
VirtualFile file = pointer == null ? null : pointer.getFile();
if (file != null) {
toUpdateUrl.add(node);
}
}
} else if (event instanceof VFilePropertyChangeEvent) {
final VFilePropertyChangeEvent change = (VFilePropertyChangeEvent) event;
if (VirtualFile.PROP_NAME.equals(change.getPropertyName()) && !Comparing.equal(change.getOldValue(), change.getNewValue())) {
VirtualFile eventFile = change.getFile();
// e.g. for LightVirtualFiles
VirtualFile parent = eventFile.getParent();
addPointersUnder(parent, true, change.getNewValue().toString(), toFireEvents);
List<FilePointerPartNode> nodes = new ArrayList<>();
addPointersUnder(eventFile, false, "", nodes);
for (FilePointerPartNode node : nodes) {
VirtualFilePointerImpl pointer = node.getAnyPointer();
VirtualFile file = pointer == null ? null : pointer.getFile();
if (file != null) {
toUpdateUrl.add(node);
}
}
}
}
}
myEvents = new ArrayList<>();
toFirePointers = toPointers(toFireEvents);
for (final VirtualFilePointerListener listener : myPointers.keySet()) {
if (listener == null)
continue;
List<VirtualFilePointer> filtered = ContainerUtil.filter(toFirePointers, pointer -> ((VirtualFilePointerImpl) pointer).getListener() == listener);
if (!filtered.isEmpty()) {
EventDescriptor event = new EventDescriptor(listener, filtered.toArray(new VirtualFilePointer[filtered.size()]));
myEvents.add(event);
}
}
}
for (EventDescriptor descriptor : myEvents) {
descriptor.fireBefore();
}
if (!toFireEvents.isEmpty()) {
myBus.syncPublisher(VirtualFilePointerListener.TOPIC).beforeValidityChanged(toFirePointers);
}
myNodesToFire = toFireEvents;
myNodesToUpdateUrl = toUpdateUrl;
assertConsistency();
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class ExternalSystemProjectsWatcher method updateWatchedRoots.
private void updateWatchedRoots(boolean isProjectOpen) {
List<String> pathsToWatch = new SmartList<>();
myFilesPointers.clear();
LocalFileSystem.getInstance().removeWatchedRoots(myWatchedRoots);
Map<String, VirtualFilePointer> pointerMap = ContainerUtil.newHashMap();
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
if (!(manager instanceof ExternalSystemAutoImportAware))
continue;
ExternalSystemAutoImportAware importAware = (ExternalSystemAutoImportAware) manager;
for (ExternalProjectSettings settings : manager.getSettingsProvider().fun(myProject).getLinkedProjectsSettings()) {
List<File> files = importAware.getAffectedExternalProjectFiles(settings.getExternalProjectPath(), myProject);
long timeStamp = 0;
for (File file : files) {
timeStamp += file.lastModified();
}
Map<String, Long> modificationStamps = manager.getLocalSettingsProvider().fun(myProject).getExternalConfigModificationStamps();
if (isProjectOpen && myProject.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) != Boolean.TRUE) {
Long affectedFilesTimestamp = modificationStamps.get(settings.getExternalProjectPath());
affectedFilesTimestamp = affectedFilesTimestamp == null ? -1L : affectedFilesTimestamp;
if (timeStamp != affectedFilesTimestamp.longValue()) {
scheduleUpdate(settings.getExternalProjectPath());
}
} else {
modificationStamps.put(settings.getExternalProjectPath(), timeStamp);
}
for (File file : files) {
if (file == null)
continue;
String path = getNormalizedPath(file);
if (path == null)
continue;
pathsToWatch.add(path);
String url = VfsUtilCore.pathToUrl(path);
VirtualFilePointer pointer = pointerMap.get(url);
if (pointer == null) {
pointer = VirtualFilePointerManager.getInstance().create(url, myChangedDocumentsQueue, null);
pointerMap.put(url, pointer);
// update timestamps based on file crc and local settings
final VirtualFile virtualFile = pointer.getFile();
if (virtualFile != null) {
Long crc = virtualFile.getUserData(CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT);
if (crc != null) {
modificationStamps.put(path, crc);
}
}
}
myFilesPointers.putValue(pointer, settings.getExternalProjectPath());
}
}
}
myWatchedRoots.addAll(LocalFileSystem.getInstance().addRootsToWatch(pathsToWatch, false));
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class HistoryEntry method createLight.
@NotNull
static HistoryEntry createLight(@NotNull Project project, @NotNull Element e) throws InvalidDataException {
EntryData entryData = parseEntry(project, e);
VirtualFilePointer pointer = new LightFilePointer(entryData.url);
HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, null);
for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) {
entry.putState(state.first, state.second);
}
return entry;
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testDelete.
public void testDelete() throws Exception {
File tempDirectory = createTempDirectory();
final File fileToDelete = new File(tempDirectory, "toDelete.txt");
assertTrue(fileToDelete.createNewFile());
final LoggingListener fileToDeleteListener = new LoggingListener();
final VirtualFilePointer fileToDeletePointer = createPointerByFile(fileToDelete, fileToDeleteListener);
assertTrue(fileToDeletePointer.isValid());
VfsTestUtil.deleteFile(getVirtualFile(fileToDelete));
assertFalse(fileToDeletePointer.isValid());
assertEquals("[before:true, after:false]", fileToDeleteListener.getLog().toString());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testMultipleCreationOfTheSamePointerPerformance.
public void testMultipleCreationOfTheSamePointerPerformance() throws IOException {
final LoggingListener listener = new LoggingListener();
final String url = VfsUtilCore.pathToUrl("/a/b/c/d/e");
final VirtualFilePointer thePointer = myVirtualFilePointerManager.create(url, disposable, listener);
TempFileSystem.getInstance();
PlatformTestUtil.startPerformanceTest("same url vfp create", 5000, () -> {
for (int i = 0; i < 10000000; i++) {
VirtualFilePointer pointer = myVirtualFilePointerManager.create(url, disposable, listener);
assertSame(pointer, thePointer);
}
}).useLegacyScaling().assertTiming();
}
Aggregations