@Override
  public void fileDeleted(@NotNull final VirtualFileEvent event) {
    final VirtualFile vFile = event.getFile();

    VirtualFile parent = event.getParent();
    final PsiDirectory parentDir = getCachedDirectory(parent);

    final PsiFile psiFile = myFileManager.getCachedPsiFileInner(vFile);
    if (psiFile != null) {
      myFileManager.setViewProvider(vFile, null);

      if (parentDir != null) {
        ApplicationManager.getApplication()
            .runWriteAction(
                new ExternalChangeAction() {
                  @Override
                  public void run() {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    treeEvent.setChild(psiFile);
                    myManager.childRemoved(treeEvent);
                  }
                });
      } else if (parent != null) {
        handleVfsChangeWithoutPsi(parent);
      }
    } else {
      final PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
      if (psiDir != null) {
        myFileManager.removeInvalidFilesAndDirs(false);

        if (parentDir != null) {
          ApplicationManager.getApplication()
              .runWriteAction(
                  new ExternalChangeAction() {
                    @Override
                    public void run() {
                      PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                      treeEvent.setParent(parentDir);
                      treeEvent.setChild(psiDir);
                      myManager.childRemoved(treeEvent);
                    }
                  });
        }
      } else if (parent != null) {
        handleVfsChangeWithoutPsi(parent);
      }
    }
  }
  @Override
  public void beforeFileDeletion(@NotNull VirtualFileEvent event) {
    final VirtualFile vFile = event.getFile();

    VirtualFile parent = vFile.getParent();
    final PsiDirectory parentDir = getCachedDirectory(parent);
    if (parentDir == null)
      return; // do not notify listeners if parent directory was never accessed via PSI

    ApplicationManager.getApplication()
        .runWriteAction(
            new ExternalChangeAction() {
              @Override
              public void run() {
                if (!vFile.isDirectory()) {
                  PsiFile psiFile = myFileManager.getCachedPsiFile(vFile);
                  if (psiFile != null) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    treeEvent.setChild(psiFile);
                    myManager.beforeChildRemoval(treeEvent);
                  }
                } else {
                  PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                  if (psiDir != null) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    treeEvent.setChild(psiDir);
                    myManager.beforeChildRemoval(treeEvent);
                  }
                }
              }
            });
  }
  @Override
  public void fileCreated(@NotNull VirtualFileEvent event) {
    final VirtualFile vFile = event.getFile();

    ApplicationManager.getApplication()
        .runWriteAction(
            new ExternalChangeAction() {
              @Override
              public void run() {
                VirtualFile parent = vFile.getParent();
                PsiDirectory parentDir = getCachedDirectory(parent);
                if (parentDir == null) {
                  // parent directory was never accessed via PSI
                  handleVfsChangeWithoutPsi(vFile);
                  return;
                }

                if (!vFile.isDirectory()) {
                  PsiFile psiFile = myFileManager.findFile(vFile);
                  if (psiFile != null && psiFile.getProject() == myManager.getProject()) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    myManager.beforeChildAddition(treeEvent);
                    treeEvent.setChild(psiFile);
                    myManager.childAdded(treeEvent);
                  }
                } else {
                  PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                  if (psiDir != null && psiDir.getProject() == myManager.getProject()) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    myManager.beforeChildAddition(treeEvent);
                    treeEvent.setChild(psiDir);
                    myManager.childAdded(treeEvent);
                  }
                }
              }
            });
  }
 private void processEvent(VirtualFileEvent event) {
   if (event.isFromRefresh() && ANNOTATIONS_XML.equals(event.getFileName())) {
     dropCache();
     notifyChangedExternally();
   }
 }