void (@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { myProject = project; PsiElement parent = PsiTreeUtil.findCommonParent(elements); mySubclass = parent instanceof PsiClass aClass ? aClass : PsiTreeUtil.getParentOfType(parent, PsiClass.class, false); if (mySubclass == null) { String message = RefactoringBundle.message("error.select.class.to.be.refactored"); CommonRefactoringUtil.showErrorHint(project, null, message, getRefactoringName(), HelpID.EXTRACT_SUPERCLASS); return; } if (mySubclass instanceof PsiUnnamedClass) { String message = RefactoringBundle.message("error.superclass.cannot.be.extracted.from.unnamed.class"); CommonRefactoringUtil.showErrorHint(project, null, message, getRefactoringName(), HelpID.EXTRACT_SUPERCLASS); return; } if (!CommonRefactoringUtil.checkReadOnlyStatus(project, mySubclass)) return; Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null; if (mySubclass.isInterface()) { String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("superclass.cannot.be.extracted.from.an.interface")); CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.EXTRACT_SUPERCLASS); return; } if (mySubclass.isEnum()) { String message = RefactoringBundle.getCannotRefactorMessage(JavaRefactoringBundle.message("superclass.cannot.be.extracted.from.an.enum")); CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.EXTRACT_SUPERCLASS); return; } if (mySubclass.isRecord()) { String message = RefactoringBundle.getCannotRefactorMessage(JavaRefactoringBundle.message("superclass.cannot.be.extracted.from.a.record")); CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.EXTRACT_SUPERCLASS); return; } List<MemberInfo> memberInfos = MemberInfo.extractClassMembers(mySubclass, new MemberInfo.Filter<>() { @Override public boolean includeMember(PsiMember element) { return true; } }, false); final Set<PsiElement> selectedMembers = new HashSet<>(); Collections.addAll(selectedMembers, elements); for (MemberInfo info : memberInfos) { if (selectedMembers.contains(info.getMember())) { info.setChecked(true); } } if (mySubclass instanceof PsiAnonymousClass) { memberInfos = ContainerUtil.filter(memberInfos, memberInfo -> !(memberInfo.getMember() instanceof PsiClass && memberInfo.getOverrides() != null)); } final ExtractSuperclassDialog dialog = new ExtractSuperclassDialog(project, mySubclass, memberInfos, this); if (!dialog.showAndGet() || !dialog.isExtractSuperclass()) { return; } PsiClass superClass = WriteCommandAction .writeCommandAction(project) .withName(getRefactoringName()) .compute(() -> doRefactoring(project, mySubclass, dialog)); ExtractClassUtil.askAndTurnRefsToSuper(mySubclass, superClass); }