Search in sources :

Example 41 with VirtualFilePointer

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();
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) SmartList(com.intellij.util.SmartList)

Example 42 with VirtualFilePointer

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));
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ExternalSystemAutoImportAware(com.intellij.openapi.externalSystem.ExternalSystemAutoImportAware) SmartList(com.intellij.util.SmartList) File(java.io.File)

Example 43 with VirtualFilePointer

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;
}
Also used : FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) LightFilePointer(com.intellij.openapi.vfs.impl.LightFilePointer) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with VirtualFilePointer

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());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 45 with VirtualFilePointer

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();
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2