private void initFileChooser(
            @Nullable KtFile targetFile,
            @Nullable PsiDirectory targetDirectory,
            @NotNull Set<KtNamedDeclaration> elementsToMove,
            @NotNull List<KtFile> sourceFiles
    ) {
        PsiDirectory sourceDir = sourceFiles.get(0).getParent();
        if (sourceDir == null) {
            throw new AssertionError("File chooser initialization failed");
        }

        Module targetModule = (targetDirectory != null)? ModuleUtilCore.findModuleForPsiElement(targetDirectory) : null;
        GlobalSearchScope targetModuleScope = targetModule == null ? null
                : GlobalSearchScope.getScopeRestrictedByFileTypes(targetModule.getModuleScope(), KotlinFileType.INSTANCE);

        fileChooser.addActionListener(e -> {
                    KotlinFileChooserDialog dialog = new KotlinFileChooserDialog(
                            KotlinBundle.message("text.choose.containing.file"),
                            myProject,
                            targetModuleScope, freezeTargets ? null : getTargetPackage());

                    File targetFile1 = new File(fileChooser.getText());
                    PsiFile targetPsiFile = PhysicalFileSystemUtilsKt.toPsiFile(targetFile1, myProject);

                    if (targetPsiFile != null) {
                        if (targetPsiFile instanceof KtFile) {
                            dialog.select((KtFile) targetPsiFile);
                        }
                        else {
                            PsiDirectory targetDir = PhysicalFileSystemUtilsKt.toPsiDirectory(targetFile1.getParentFile(), myProject);
                            if (targetDir != null) {
                                dialog.selectDirectory(targetDir);
                            } else {
                                dialog.selectDirectory(sourceDir);
                            }
                        }
                    } else {
                        dialog.selectDirectory(sourceDir);
                    }

                    dialog.showDialog();
                    KtFile selectedFile = dialog.isOK() ? dialog.getSelected() : null;
                    if (selectedFile != null) {
                        fileChooser.setText(selectedFile.getVirtualFile().getPath());
                    }
                }
        );

        String initialTargetPath = targetFile != null
                ? targetFile.getVirtualFile().getPath()
                : sourceFiles.get(0).getVirtualFile().getParent().getPath() + "/" + MoveUtilKt.guessNewFileName(elementsToMove);
        fileChooser.setText(initialTargetPath);
    }
private void initFileChooser(
            @Nullable KtFile targetFile,
            @Nullable PsiDirectory targetDirectory,
            @NotNull Set<KtNamedDeclaration> elementsToMove,
            @NotNull List<KtFile> sourceFiles
    )