private static PsiFile copy(@NotNull PsiDirectory directory, @NotNull PsiFile file, String name) {
    final String fileName = getNewFileName(file, name);
    final PsiFile existingFile = directory.findFile(fileName);
    return WriteAction.compute(() -> {
      if (existingFile != null) existingFile.delete();
      return directory.copyFileFrom(fileName, file);
    });
  }
private static PsiFile copy(@NotNull PsiDirectory directory, @NotNull PsiFile file, String name)