void (final PyClass clazz, @NotNull Collection<PyMemberInfo<PyElement>> selectedMemberInfos, final String superBaseName, final String targetFile) { final Project project = clazz.getProject(); //We will need to change it probably while param may be read-only //noinspection AssignmentToMethodParameter selectedMemberInfos = new ArrayList<>(selectedMemberInfos); final RefactoringEventData beforeData = new RefactoringEventData(); beforeData.addElements(JBIterable.from(selectedMemberInfos).transform( (Function<PyMemberInfo<PyElement>, PsiElement>)info -> info.getMember()).toList()); project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC) .refactoringStarted(getRefactoringId(), beforeData); // PY-12171 final PyMemberInfo<PyElement> objectMember = MembersManager.findMember(selectedMemberInfos, ALLOW_OBJECT); if (LanguageLevel.forElement(clazz).isPy3K() && !isObjectParentDeclaredExplicitly(clazz)) { // Remove object from list if Py3 if (objectMember != null) { selectedMemberInfos.remove(objectMember); } } else { // Always add object if < Py3 if (objectMember == null) { final PyMemberInfo<PyElement> object = MembersManager.findMember(clazz, ALLOW_OBJECT); if (object != null) { selectedMemberInfos.add(object); } } } final String text = "class " + superBaseName + ":\n pass" + "\n"; PyClass newClass = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyClass.class, text); newClass = placeNewClass(project, newClass, clazz, targetFile); MembersManager.moveAllMembers(selectedMemberInfos, clazz, newClass); if (! newClass.getContainingFile().equals(clazz.getContainingFile())) { PyClassRefactoringUtil.optimizeImports(clazz.getContainingFile()); // To remove unneeded imports only if user used different file } PyPsiRefactoringUtil.addSuperclasses(project, clazz, null, newClass); final RefactoringEventData afterData = new RefactoringEventData(); afterData.addElement(newClass); project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC) .refactoringDone(getRefactoringId(), afterData); }