Java 类com.intellij.openapi.vfs.newvfs.BulkFileListener 实例源码

项目:intellij-ce-playground    文件:FileContentUtilCore.java   
/**
 * Forces a reparse of the specified collection of files.
 *
 * @param files the files to reparse.
 */
public static void reparseFiles(@NotNull final Collection<VirtualFile> files) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      // files must be processed under one write action to prevent firing event for invalid files.
      final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>();
      for (VirtualFile file : files) {
        saveOrReload(file, events);
      }

      BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
      List<VFileEvent> eventList = new ArrayList<VFileEvent>(events);
      publisher.before(eventList);
      publisher.after(eventList);
    }
  });
}
项目:intellij-ce-playground    文件:VirtualFileManagerImpl.java   
@Override
public void notifyPropertyChanged(@NotNull final VirtualFile virtualFile, @NotNull final String property, final Object oldValue, final Object newValue) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      if (virtualFile.isValid() && !application.isDisposed()) {
        application.runWriteAction(new Runnable() {
          @Override
          public void run() {
            List<VFilePropertyChangeEvent> events = Collections
              .singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
            BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
            listener.before(events);
            listener.after(events);
          }
        });
      }
    }
  };
  application.invokeLater(runnable, ModalityState.NON_MODAL);
}
项目:intellij-ce-playground    文件:AndroidProjectTreeBuilder.java   
public AndroidProjectTreeBuilder(@NotNull Project project,
                                 @NotNull JTree tree,
                                 @NotNull DefaultTreeModel treeModel,
                                 @Nullable Comparator<NodeDescriptor> comparator,
                                 @NotNull ProjectAbstractTreeStructureBase treeStructure) {
  super(project, tree, treeModel, comparator, treeStructure);

  MessageBusConnection connection = project.getMessageBus().connect(project);
  connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
      for (VFileEvent e : events) {
        if (e instanceof VFileDeleteEvent) {
          removeMapping(e.getFile());
        }
      }
    }
  });
}
项目:tools-idea    文件:DelayedDocumentWatcher.java   
public void activate() {
  if (messageBusConnection != null) {
    return;
  }

  messageBusConnection = project.getMessageBus().connect();
  messageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
      for (VFileEvent event : events) {
        if (event instanceof VFileDeleteEvent) {
          synchronized (changedFiles) {
            changedFiles.remove(event.getFile());
          }
        }
      }
    }
  });

  EditorFactory.getInstance().getEventMulticaster().addDocumentListener(listener, project);
}
项目:tools-idea    文件:VirtualFileManagerImpl.java   
@Override
public void notifyPropertyChanged(final VirtualFile virtualFile, final String property, final Object oldValue, final Object newValue) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      if (virtualFile.isValid() && !application.isDisposed()) {
        application.runWriteAction(new Runnable() {
          @Override
          public void run() {
            List<VFilePropertyChangeEvent> events = Collections
              .singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
            BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
            listener.before(events);
            listener.after(events);
          }
        });
      }
    }
  };
  application.invokeLater(runnable, ModalityState.NON_MODAL);
}
项目:consulo    文件:FileContentUtilCore.java   
@RequiredDispatchThread
public static void reparseFiles(@Nonnull final Collection<VirtualFile> files) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      // files must be processed under one write action to prevent firing event for invalid files.
      final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>();
      for (VirtualFile file : files) {
        saveOrReload(file, events);
      }

      BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
      List<VFileEvent> eventList = new ArrayList<VFileEvent>(events);
      publisher.before(eventList);
      publisher.after(eventList);
    }
  });
}
项目:consulo    文件:VirtualFileManagerImpl.java   
@Override
public void notifyPropertyChanged(@Nonnull final VirtualFile virtualFile, @Nonnull final String property, final Object oldValue, final Object newValue) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      if (virtualFile.isValid() && !application.isDisposed()) {
        application.runWriteAction(new Runnable() {
          @Override
          public void run() {
            List<VFilePropertyChangeEvent> events = Collections
                    .singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
            BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
            listener.before(events);
            listener.after(events);
          }
        });
      }
    }
  };
  application.invokeLater(runnable, ModalityState.NON_MODAL);
}
项目:consulo    文件:GistManagerImpl.java   
public GistManagerImpl() {
  ApplicationManager.getApplication().getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@Nonnull List<? extends VFileEvent> events) {
      if (events.stream().anyMatch(this::shouldDropCache)) {
        invalidateData();
      }
    }

    private boolean shouldDropCache(VFileEvent e) {
      if (!(e instanceof VFilePropertyChangeEvent)) return false;

      String propertyName = ((VFilePropertyChangeEvent)e).getPropertyName();
      return propertyName.equals(VirtualFile.PROP_NAME) || propertyName.equals(VirtualFile.PROP_ENCODING);
    }
  });
}
项目:consulo-java    文件:NonClasspathClassFinder.java   
public NonClasspathClassFinder(@NotNull Project project, @NotNull String... fileExtensions)
{
    myProject = project;
    myPackageManager = PsiPackageManager.getInstance(myProject);
    myManager = PsiManager.getInstance(myProject);
    myFileExtensions = ArrayUtil.append(fileExtensions, "class");
    final MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener()
    {
        @Override
        public void after(@NotNull List<? extends VFileEvent> events)
        {
            clearCache();
        }
    });
    LowMemoryWatcher.register(this::clearCache, project);
}
项目:intellij-ce-playground    文件:NonClasspathClassFinder.java   
public NonClasspathClassFinder(Project project, String... fileExtensions) {
  myProject = project;
  myManager = PsiManager.getInstance(myProject);
  myFileExtensions = ArrayUtil.append(fileExtensions, "class");
  final MessageBusConnection connection = project.getMessageBus().connect(project);
  connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
      clearCache();
    }
  });
}
项目:intellij-ce-playground    文件:JarFileSystemTest.java   
public void testJarRefresh() throws IOException {
  File jar = IoTestUtil.createTestJar();
  assertTrue(jar.setLastModified(jar.lastModified() - 1000));
  VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
  assertNotNull(vFile);

  VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR);
  assertEquals(1, jarRoot.getChildren().length);

  final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME);
  assertContent(entry, "");

  final Ref<Boolean> updated = Ref.create(false);
  ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(
    VirtualFileManager.VFS_CHANGES,
    new BulkFileListener.Adapter() {
      @Override
      public void before(@NotNull List<? extends VFileEvent> events) {
        for (VFileEvent event : events) {
          if (event instanceof VFileContentChangeEvent && entry.equals(event.getFile())) {
            updated.set(true);
            break;
          }
        }
      }
    }
  );

  IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text");
  vFile.refresh(false, false);

  assertTrue(updated.get());
  assertTrue(entry.isValid());
  assertContent(entry, "update");
  assertEquals(2, jarRoot.getChildren().length);
  VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt");
  assertContent(newEntry, "some text");
}
项目:intellij-ce-playground    文件:VFSTestFrameworkListener.java   
public VFSTestFrameworkListener() {
  myService = PyTestFrameworkService.getInstance();
  MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
  messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
      for (VFileEvent event : events) {
        if (!(event.getFileSystem() instanceof LocalFileSystem) || event instanceof VFileContentChangeEvent)
          continue;
        final String path = event.getPath();
        boolean containsNose = path.contains(PyNames.NOSE_TEST);
        boolean containsPy = path.contains("py-1") || path.contains(PyNames.PY_TEST);
        boolean containsAt = path.contains(PyNames.AT_TEST);
        if (!containsAt && !containsNose && !containsPy) continue;
        for (Sdk sdk : PythonSdkType.getAllSdks()) {
          if (PySdkUtil.isRemote(sdk)) {
            continue;
          }
          for (VirtualFile virtualFile : sdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
            String root = virtualFile.getCanonicalPath();
            if (root != null && path.contains(root)) {
              if (containsNose) {
                updateTestFrameworks(sdk, PyNames.NOSE_TEST);
                return;
              }
              else if (containsPy) {
                updateTestFrameworks(sdk, PyNames.PY_TEST);
                return;
              }
              else {
                updateTestFrameworks(sdk, PyNames.AT_TEST);
                return;
              }
            }
          }
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:SvnTestCase.java   
public static void imitateEvent(VirtualFile dir) {
  final VirtualFile child = dir.findChild(".svn");
  assertNotNull(child);
  final VirtualFile wcdb = child.findChild("wc.db");
  assertNotNull(wcdb);

  final BulkFileListener listener = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
  final VFileContentChangeEvent event =
    new VFileContentChangeEvent(null, wcdb, wcdb.getModificationStamp() - 1, wcdb.getModificationStamp(), true);
  final List<VFileContentChangeEvent> events = Collections.singletonList(event);
  listener.before(events);
  listener.after(events);
}
项目:tools-idea    文件:FileWatcherTest.java   
@Override
protected void setUp() throws Exception {
  LOG.debug("================== setting up " + getName() + " ==================");

  super.setUp();

  myFileSystem = LocalFileSystem.getInstance();
  assertNotNull(myFileSystem);

  myWatcher = ((LocalFileSystemImpl)myFileSystem).getFileWatcher();
  assertNotNull(myWatcher);
  assertFalse(myWatcher.isOperational());
  myWatcher.startup(myNotifier);
  assertTrue(myWatcher.isOperational());

  myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getProject());
  myTimeout = NATIVE_PROCESS_DELAY;

  myConnection = ApplicationManager.getApplication().getMessageBus().connect();
  myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
      synchronized (myEvents) {
        myEvents.addAll(events);
      }
    }
  });

  ((LocalFileSystemImpl)myFileSystem).cleanupForNextTest();

  LOG = FileWatcher.getLog();
  LOG.debug("================== setting up " + getName() + " ==================");
}
项目:tools-idea    文件:IgnoredFilesComponent.java   
public IgnoredFilesComponent(final Project project, final boolean registerListener) {
  myFilesToIgnore = new LinkedHashSet<IgnoredFileBean>();
  myFilesMap = new HashMap<String, IgnoredFileBean>();

  if (registerListener) {
    project.getMessageBus().connect(project).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
      @Override
      public void after(@NotNull List<? extends VFileEvent> events) {
        resetCaches();
      }
    });
  }
}
项目:tools-idea    文件:SvnTestCase.java   
public static void imitateEvent(VirtualFile dir) {
  final VirtualFile child = dir.findChild(".svn");
  assertNotNull(child);
  final VirtualFile wcdb = child.findChild("wc.db");
  assertNotNull(wcdb);

  final BulkFileListener listener = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
  final VFileContentChangeEvent event =
    new VFileContentChangeEvent(null, wcdb, wcdb.getModificationStamp() - 1, wcdb.getModificationStamp(), true);
  final List<VFileContentChangeEvent> events = Collections.singletonList(event);
  listener.before(events);
  listener.after(events);
}
项目:consulo-dotnet    文件:MsilFileRepresentationManagerImpl.java   
public MsilFileRepresentationManagerImpl(Project project)
{
    super(project);
    project.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener()
    {
        @Override
        public void before(@NotNull List<? extends VFileEvent> events)
        {
            for(VFileEvent event : events)
            {
                myFiles.remove(event.getFile());
            }
        }
    });
}
项目:consulo    文件:ContentEntryFileListener.java   
public ContentEntryFileListener(Application application, ProjectManager projectManager) {
  application.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
    @Override
    public void before(@Nonnull List<? extends VFileEvent> events) {
      for (Project project : projectManager.getOpenProjects()) {
        new BulkVirtualFileListenerAdapter(new Listener(project), LocalFileSystem.getInstance()).before(events);
      }
    }
  });
}