private static void copyImpl(final VirtualFile @NotNull [] files,
                               @Nullable final String newName,
                               @NotNull final PsiDirectory targetDirectory,
                               final boolean doClone,
                               final boolean openInEditor) {
    if (doClone && files.length != 1) {
      throw new IllegalArgumentException("invalid number of elements to clone:" + files.length);
    }

    if (newName != null && files.length != 1) {
      throw new IllegalArgumentException("no new name should be set; number of elements is: " + files.length);
    }

    final Project project = targetDirectory.getProject();
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, Collections.singleton(targetDirectory), true)) {
      return;
    }

    String title = RefactoringBundle.message(doClone ? "copy.handler.clone.files.directories" : "copy.handler.copy.files.directories");
    try {
      final int[] choice = files.length > 1 || files[0].isDirectory() ? new int[]{-1} : null;
      List<PsiFile> added = new ArrayList<>();
      List<PsiFile> originals = new ArrayList<>();
      PsiManager manager = PsiManager.getInstance(project);
      List<PsiFileSystemItem> items = new ArrayList<>(files.length);
      for (VirtualFile file : files) {
        PsiFileSystemItem item = file.isDirectory() ? manager.findDirectory(file) : manager.findFile(file);
        if (item == null) {
          LOG.info("invalid file: " + file.getExtension());
          continue;
        }
        items.add(item);
      }
      copyToDirectory(items, newName, targetDirectory, choice, title, added, originals);


      if (!added.isEmpty()) {
        DumbService.getInstance(project).completeJustSubmittedTasks();
        updateAddedFiles(added, originals);
        if (openInEditor) {
          PsiFile firstFile = added.get(0);
          CopyHandler.updateSelectionInActiveProjectView(firstFile, project, doClone);
          if (!(firstFile instanceof PsiBinaryFile)) {
            EditorHelper.openInEditor(firstFile, true, true);
          }
        }
      }
    }
    catch (final IncorrectOperationException | IOException ex) {
      Messages.showErrorDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"));
    }
  }
private static void copyImpl(final VirtualFile @NotNull [] files,
                               @Nullable final String newName,
                               @NotNull final PsiDirectory targetDirectory,
                               final boolean doClone,
                               final boolean openInEditor)