ClassBrowser ( Project project, ConfigurationModuleSelector moduleSelector, LabeledComponent<ModuleDescriptionsComboBox> moduleChooser ) { ClassFilter applicationClass = new ClassFilter() { @Override public boolean isAccepted(PsiClass aClass) { return aClass instanceof KtLightClass && ConfigurationUtil.MAIN_CLASS.value(aClass) && findMainMethod(aClass) != null; } private static @Nullable PsiMethod findMainMethod(PsiClass aClass) { return ReadAction.compute(() -> PsiMethodUtil.findMainMethod(aClass)); } }; return new ClassBrowser.MainClassBrowser(project, moduleSelector, ExecutionBundle.message("choose.main.class.dialog.title")) { @Override protected ClassFilter createFilter(Module module) { return applicationClass; } @Override protected void onClassChosen(@NotNull PsiClass psiClass) { Module module = ModuleUtilCore.findModuleForPsiElement(psiClass); if (module != null && moduleSelector.isModuleAccepted(module)) { moduleChooser.getComponent().setSelectedModule(module); } } @Override protected TreeClassChooser createClassChooser(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; } }; } }; }