@Override
  public void beforeDocumentChange(@NotNull DocumentEvent event) {
    if (myStopTrackingDocuments) return;

    final Document document = event.getDocument();
    if (!(document instanceof DocumentWindow) && !myLastCommittedTexts.containsKey(document)) {
      myLastCommittedTexts.put(
          document,
          Pair.create(document.getImmutableCharSequence(), document.getModificationStamp()));
    }

    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    boolean isRelevant = virtualFile != null && isRelevant(virtualFile);

    final FileViewProvider viewProvider = getCachedViewProvider(document);
    boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
    if (!isRelevant || !inMyProject) {
      return;
    }

    final List<PsiFile> files = viewProvider.getAllFiles();
    PsiFile psiCause = null;
    for (PsiFile file : files) {
      if (file == null) {
        throw new AssertionError(
            "View provider "
                + viewProvider
                + " ("
                + viewProvider.getClass()
                + ") returned null in its files array: "
                + files
                + " for file "
                + viewProvider.getVirtualFile());
      }

      if (mySynchronizer.isInsideAtomicChange(file)) {
        psiCause = file;
      }
    }

    if (psiCause == null) {
      beforeDocumentChangeOnUnlockedDocument(viewProvider);
    }

    ((SingleRootFileViewProvider) viewProvider).beforeDocumentChanged(psiCause);
  }
 public void setSubstAnnotation(@Nullable String substAnnotation) {
   if (substAnnotation == null) return;
   mySubstAnnotation = substAnnotation;
   mySubstAnnotationPair = Pair.create(substAnnotation, Collections.singleton(substAnnotation));
 }
 public void setPatternAnnotation(@Nullable String patternAnnotation) {
   if (patternAnnotation == null) return;
   myPatternAnnotation = patternAnnotation;
   myPatternAnnotationPair =
       Pair.create(patternAnnotation, Collections.singleton(patternAnnotation));
 }
 public void setLanguageAnnotation(@Nullable String languageAnnotation) {
   if (languageAnnotation == null) return;
   myLanguageAnnotation = languageAnnotation;
   myLanguageAnnotationPair =
       Pair.create(languageAnnotation, Collections.singleton(languageAnnotation));
 }