private static @NotNull PsiFile copyFile(Project project, PsiFile origFile) {
    PsiFile file;
    var manager = InjectedLanguageManager.getInstance(project);
    boolean injectedFragment = manager.isInjectedFragment(origFile);
    if (!injectedFragment) {
      PsiElement navigationElement = origFile.getNavigationElement();
      if (navigationElement != origFile && navigationElement instanceof PsiFile) {
        file = (PsiFile)navigationElement.copy();
      }
      else {
        file = (PsiFile)origFile.copy();
      }
    }
    else {
      file = PsiFileFactory.getInstance(project).createFileFromText(
        origFile.getName(), origFile.getLanguage(), manager.getUnescapedText(origFile),
        false, true, true, origFile.getVirtualFile());
      file.putUserData(ORIGINAL_FILE_FOR_INJECTION, origFile);
    }
    file.putUserData(PsiFileFactory.ORIGINAL_FILE, origFile);
    return file;
  }
private static @NotNull PsiFile copyFile(Project project, PsiFile origFile)