void (Map<VirtualFile, TargetDirectoryWrapper> files2Move, Map<PsiDirectory, TargetDirectoryWrapper> nestedDirsToMove, PsiDirectory directory, PsiDirectory rootDirectory, @NotNull TargetDirectoryWrapper targetDirectory) { final PsiElement[] children = directory.getChildren(); final String relativePath = VfsUtilCore.getRelativePath(directory.getVirtualFile(), rootDirectory.getVirtualFile(), '/'); final TargetDirectoryWrapper newTargetDirectory = relativePath.length() == 0 ? targetDirectory : targetDirectory.findOrCreateChild(relativePath); nestedDirsToMove.put(directory, newTargetDirectory); for (PsiElement child : children) { if (child instanceof PsiFile) { files2Move.put(PsiUtilCore.getVirtualFile(child), newTargetDirectory); } else if (child instanceof PsiDirectory){ collectFiles2Move(files2Move, nestedDirsToMove, (PsiDirectory)child, directory, newTargetDirectory); } } }