private @NotNull PsiFile ensureValid(@NotNull PsiFile file) {
    if (!file.isValid()) {
      PsiFile fileToUse = PsiUtilCore.getPsiFile(myProject, file.getViewProvider().getVirtualFile());
      CodeFormattingData.copy(file, fileToUse);
      return fileToUse;
    }
    return file;
  }
private @NotNull PsiFile ensureValid(@NotNull PsiFile file)