TreeClassChooser (ClassFilter.ClassFilterWithScope classFilter) { Project project = getProject(); return new TreeJavaClassChooserDialog(myTitle, project, classFilter.getScope(), classFilter, null, null, true) { @Override protected @Nullable PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) { Object userObject = node.getUserObject(); if (userObject instanceof ClassTreeNode treeNode) { return treeNode.getPsiClass(); } KtElement ktElement = null; if (userObject instanceof KtFileTreeNode treeNode) { ktElement = treeNode.getKtFile(); } if (userObject instanceof KtDeclarationTreeNode treeNode) { ktElement = treeNode.getDeclaration(); } if (ktElement != null) { List<PsiNamedElement> elements = LightClassUtilsKt.toLightElements(ktElement); if (!elements.isEmpty()) { PsiNamedElement element = elements.get(0); PsiClass parent = PsiUtilsKt.getParentOfTypes(element, false, PsiClass.class); if (parent != null) { return parent; } } } return null; } }; }