void (PsiElement[] elements, PsiDirectory defaultTargetDirectory, Project project) { final List<PsiElement> files = new ArrayList<>(); for (PsiElement element : elements) { PsiFile containingFile = element.getContainingFile(); if (containingFile != null) { files.add(containingFile); } else if (element instanceof PsiDirectory) { files.add(element); } } CopyFilesOrDirectoriesHandler.copyAsFiles(files.toArray(PsiElement.EMPTY_ARRAY), defaultTargetDirectory, project); }