PsiDirectory (@Nullable Module module, @Nullable PsiElement target) { PsiDirectory targetDirectory = target instanceof PsiDirectory ? (PsiDirectory)target : null; if (targetDirectory == null && target instanceof PsiDirectoryContainer) { final PsiDirectory[] directories = module == null ? ((PsiDirectoryContainer)target).getDirectories() : ((PsiDirectoryContainer)target).getDirectories(GlobalSearchScope.moduleScope(module)); if (directories.length > 0) { targetDirectory = directories[0]; targetDirectory.putCopyableUserData(SHOW_CHOOSER_KEY, directories.length > 1); } } if (targetDirectory == null && target != null) { final PsiFile containingFile = target.getContainingFile(); if (containingFile != null) { targetDirectory = containingFile.getContainingDirectory(); } } return targetDirectory; }