com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent Java Examples

The following examples show how to use com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeneratedFilesListener.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public void after(List<? extends VFileEvent> events) {
  IntervalLogger logger = new IntervalLogger(LOG);

  final boolean found =
      events.stream()
          .filter(VFileCreateEvent.class::isInstance)
          .map(VFileEvent::getFile)
          .filter(file -> file != null && file.isValid())
          .map(file -> FileUtil.toSystemIndependentName(file.getPath()))
          .anyMatch(GeneratedFilesListener::isOutput);
  logger.logStep("finding created paths: " + found);
  if (!found) return;

  // Wait for indexing
  final Runnable job =
      () -> {
        logger.logStep("start of removing files");
        ComponentsCacheService.getInstance(project).invalidate();
      };
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    job.run();
  } else {
    DumbService.getInstance(project).smartInvokeLater(job);
  }
}
 
Example #2
Source File: VirtualFilePointerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testManyPointersUpdatePerformance() throws IOException {
  LoggingListener listener = new LoggingListener();
  final List<VFileEvent> events = new ArrayList<VFileEvent>();
  final File ioTempDir = createTempDirectory();
  final VirtualFile temp = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioTempDir);
  for (int i=0; i<100000; i++) {
    myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/" + i), disposable, listener);
    String name = "xxx" + (i % 20);
    events.add(new VFileCreateEvent(this, temp, name, true, null, null, true, null));
  }
  PlatformTestUtil.startPerformanceTest("vfp update", 10000, new ThrowableRunnable() {
    @Override
    public void run() throws Throwable {
      for (int i=0; i<100; i++) {
        // simulate VFS refresh events since launching the actual refresh is too slow
        AsyncFileListener.ChangeApplier applier = myVirtualFilePointerManager.prepareChange(events);
        applier.beforeVfsChange();
        applier.afterVfsChange();
      }
    }
  }).assertTiming();
}
 
Example #3
Source File: RefreshQueueImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void tryProcessingEvents(@Nonnull RefreshSessionImpl session, @Nullable TransactionId transaction) {
  List<? extends VFileEvent> events = ContainerUtil.filter(session.getEvents(), e -> {
    VirtualFile file = e instanceof VFileCreateEvent ? ((VFileCreateEvent)e).getParent() : e.getFile();
    return file == null || file.isValid();
  });

  List<AsyncFileListener.ChangeApplier> appliers = AsyncEventSupport.runAsyncListeners(events);

  long stamp = myWriteActionCounter.get();
  TransactionGuard.getInstance().submitTransaction(ApplicationManager.getApplication(), transaction, () -> {
    if (stamp == myWriteActionCounter.get()) {
      session.fireEvents(events, appliers);
    }
    else {
      scheduleAsynchronousPreprocessing(session, transaction);
    }
  });
}
 
Example #4
Source File: QuarkusLanguageClient.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void filter(VFileEvent event, Set<String> uris) {
  VirtualFile file = event.getFile();
  if (file != null && file.exists() && "java".equalsIgnoreCase(file.getExtension())) {
    Module module = ProjectFileIndex.getInstance(getProject()).getModuleForFile(file);
    if (module != null && (event instanceof VFileCreateEvent || event instanceof VFileContentChangeEvent || event instanceof VFileDeleteEvent)) {
      uris.add(PsiUtilsImpl.getProjectURI(module));
    }
  }
}
 
Example #5
Source File: GeneratedFilesListenerTest.java    From litho with Apache License 2.0 5 votes vote down vote up
private VFileEvent mockEvent() {
  final VFileEvent event = Mockito.mock(VFileCreateEvent.class);
  VirtualFile mockFile = Mockito.mock(VirtualFile.class);
  when(mockFile.isValid()).thenReturn(true);
  when(mockFile.getPath()).thenReturn(GeneratedFilesListener.BUCK_OUT_BASE);
  when(event.getFile()).thenReturn(mockFile);
  return event;
}
 
Example #6
Source File: BulkSymbolTableBuildingChangeListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void after(List<? extends VFileEvent> events) {
  if (!enabled) {
    return;
  }
  for (VFileEvent event : events) {
    VirtualFile modifiedFile = null;
    // Skip delete events.
    if (event instanceof VFileContentChangeEvent || event instanceof VFileCreateEvent) {
      modifiedFile = event.getFile();
    } else if (event instanceof VFileCopyEvent) {
      VFileCopyEvent copyEvent = (VFileCopyEvent) event;
      modifiedFile = copyEvent.getNewParent();
    } else if (event instanceof VFileMoveEvent) {
      VFileMoveEvent moveEvent = (VFileMoveEvent) event;
      modifiedFile = moveEvent.getNewParent();
    } else if (event instanceof VFilePropertyChangeEvent) {
      VFilePropertyChangeEvent propEvent = (VFilePropertyChangeEvent) event;
      // Check for file renames (sometimes we get property change events without the name
      // actually changing though)
      if (propEvent.getPropertyName().equals(VirtualFile.PROP_NAME)
          && !propEvent.getOldValue().equals(propEvent.getNewValue())) {
        modifiedFile = propEvent.getFile();
      }
    }
    if (SymbolTableProvider.isSourceFile(project, modifiedFile)) {
      queueChange(modifiedFile);
    }
  }
}
 
Example #7
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private VirtualFileSystemEntry createAndFindChildWithEventFire(@Nonnull String name, @Nonnull NewVirtualFileSystem delegate) {
  final VirtualFile fake = new FakeVirtualFile(this, name);
  final FileAttributes attributes = delegate.getAttributes(fake);
  if (attributes == null) return null;
  final String realName = delegate.getCanonicallyCasedName(fake);
  boolean isDirectory = attributes.isDirectory();
  boolean isEmptyDirectory = isDirectory && !delegate.hasChildren(fake);
  String symlinkTarget = attributes.isSymLink() ? delegate.resolveSymLink(fake) : null;
  ChildInfo[] children = isEmptyDirectory ? ChildInfo.EMPTY_ARRAY : null;
  VFileCreateEvent event = new VFileCreateEvent(null, this, realName, isDirectory, attributes, symlinkTarget, true, children);
  RefreshQueue.getInstance().processSingleEvent(event);
  return findChild(realName);
}
 
Example #8
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void validateAgainst(@Nonnull List<? extends VFileCreateEvent> childrenToCreate, @Nonnull Set<CharSequence> existingNames) {
  for (int i = childrenToCreate.size() - 1; i >= 0; i--) {
    VFileCreateEvent event = childrenToCreate.get(i);
    String childName = event.getChildName();
    // assume there is no need to canonicalize names in VFileCreateEvent
    boolean childExists = !myData.isAdoptedName(childName) && existingNames.contains(childName);
    if (childExists) {
      childrenToCreate.remove(i);
    }
  }
}
 
Example #9
Source File: ScratchTreeStructureProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile getNewParent(@Nonnull VFileEvent e) {
  if (e instanceof VFileMoveEvent) {
    return ((VFileMoveEvent)e).getNewParent();
  }
  else if (e instanceof VFileCopyEvent) {
    return ((VFileCopyEvent)e).getNewParent();
  }
  else if (e instanceof VFileCreateEvent) {
    return ((VFileCreateEvent)e).getParent();
  }
  else {
    return Objects.requireNonNull(e.getFile()).getParent();
  }
}
 
Example #10
Source File: ScratchTreeStructureProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isDirectory(@Nonnull VFileEvent e) {
  if (e instanceof VFileCreateEvent) {
    return ((VFileCreateEvent)e).isDirectory();
  }
  else {
    return Objects.requireNonNull(e.getFile()).isDirectory();
  }
}
 
Example #11
Source File: VfsImplUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void checkSubscription() {
  if (ourSubscribed.getAndSet(true)) return;

  Application app = ApplicationManager.getApplication();
  app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@Nonnull List<? extends VFileEvent> events) {
      InvalidationState state = null;

      synchronized (ourLock) {
        for (VFileEvent event : events) {
          if (!(event.getFileSystem() instanceof LocalFileSystem)) continue;

          if (event instanceof VFileCreateEvent) continue; // created file should not invalidate + getFile is costly

          if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent)event).getPropertyName())) {
            continue;
          }

          String path = event.getPath();
          if (event instanceof VFilePropertyChangeEvent) {
            path = ((VFilePropertyChangeEvent)event).getOldPath();
          }
          else if (event instanceof VFileMoveEvent) {
            path = ((VFileMoveEvent)event).getOldPath();
          }

          VirtualFile file = event.getFile();
          if (file == null || !file.isDirectory()) {
            state = InvalidationState.invalidate(state, path);
          }
          else {
            Collection<String> affectedPaths = ourDominatorsMap.get(path);
            if (affectedPaths != null) {
              affectedPaths = ContainerUtil.newArrayList(affectedPaths);  // defensive copying; original may be updated on invalidation
              for (String affectedPath : affectedPaths) {
                state = InvalidationState.invalidate(state, affectedPath);
              }
            }
          }
        }
      }

      if (state != null) state.scheduleRefresh();
    }
  });
}
 
Example #12
Source File: VcsDirtyScopeVfsListener.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ChangeApplier prepareChange(@Nonnull List<? extends VFileEvent> events) {
  if (myForbid || !myVcsManager.hasAnyMappings()) return null;
  final FilesAndDirs dirtyFilesAndDirs = new FilesAndDirs();
  // collect files and directories - sources of events
  for (VFileEvent event : events) {
    ProgressManager.checkCanceled();

    final boolean isDirectory;
    if (event instanceof VFileCreateEvent) {
      if (!((VFileCreateEvent)event).getParent().isInLocalFileSystem()) {
        continue;
      }
      isDirectory = ((VFileCreateEvent)event).isDirectory();
    }
    else {
      final VirtualFile file = Objects.requireNonNull(event.getFile(), "All events but VFileCreateEvent have @NotNull getFile()");
      if (!file.isInLocalFileSystem()) {
        continue;
      }
      isDirectory = file.isDirectory();
    }

    if (event instanceof VFileMoveEvent) {
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(((VFileMoveEvent)event).getOldPath(), isDirectory));
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(((VFileMoveEvent)event).getNewPath(), isDirectory));
    }
    else if (event instanceof VFilePropertyChangeEvent && ((VFilePropertyChangeEvent)event).isRename()) {
      // if a file was renamed, then the file is dirty and its parent directory is dirty too;
      // if a directory was renamed, all its children are recursively dirty, the parent dir is also dirty but not recursively.
      FilePath oldPath = VcsUtil.getFilePath(((VFilePropertyChangeEvent)event).getOldPath(), isDirectory);
      FilePath newPath = VcsUtil.getFilePath(((VFilePropertyChangeEvent)event).getNewPath(), isDirectory);
      // the file is dirty recursively
      add(myVcsManager, dirtyFilesAndDirs, oldPath);
      add(myVcsManager, dirtyFilesAndDirs, newPath);
      FilePath parentPath = oldPath.getParentPath();
      if (parentPath != null) {
        addAsFiles(myVcsManager, dirtyFilesAndDirs, parentPath); // directory is dirty alone
      }
    }
    else {
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(event.getPath(), isDirectory));
    }
  }

  return new ChangeApplier() {
    @Override
    public void afterVfsChange() {
      markDirtyOnPooled(dirtyFilesAndDirs);
    }
  };
}