void (final PsiMethod sourceMethod) { final List<PsiMethod> generatedMethods = new ArrayList<>(); WriteCommandAction.writeCommandAction(myProject, myTargetClasses.isEmpty() ? myTargetEnumConstants : myTargetClasses).run(() -> { for (PsiEnumConstant enumConstant : myTargetEnumConstants) { PsiClass initializingClass = enumConstant.getOrCreateInitializingClass(); myTargetClasses.add(initializingClass); } for (PsiClass psiClass : myTargetClasses) { final Collection<PsiMethod> methods = OverrideImplementUtil.overrideOrImplementMethod(psiClass, myMethod, true); final Iterator<PsiMethod> iterator = methods.iterator(); if (!iterator.hasNext()) continue; PsiMethod overriddenMethod = iterator.next(); final PsiCodeBlock body = overriddenMethod.getBody(); final PsiCodeBlock sourceBody = sourceMethod.getBody(); assert body != null && sourceBody != null; ChangeContextUtil.encodeContextInfo(sourceBody, true); final PsiElement newBody = body.replace(sourceBody.copy()); ChangeContextUtil.decodeContextInfo(newBody, psiClass, null); final PsiDocComment docComment = overriddenMethod.getDocComment(); if (docComment != null) { try { docComment.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(mySourceClass, psiClass, PsiSubstitutor.EMPTY); PsiElement anchor = OverrideImplementUtil.getDefaultAnchorToOverrideOrImplement(psiClass, sourceMethod, substitutor); try { if (anchor != null) { overriddenMethod = (PsiMethod)anchor.getParent().addBefore(overriddenMethod, anchor); } else { overriddenMethod = (PsiMethod)psiClass.addBefore(overriddenMethod, psiClass.getRBrace()); } generatedMethods.add(overriddenMethod); } catch (IncorrectOperationException e) { LOG.error(e); } } }); if (!generatedMethods.isEmpty()) { PsiMethod target = generatedMethods.get(0); PsiFile psiFile = target.getContainingFile(); FileEditorManager fileEditorManager = FileEditorManager.getInstance(psiFile.getProject()); Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), false); if (editor != null) { GenerateMembersUtil.positionCaret(editor, target, true); editor.getScrollingModel().scrollToCaret(ScrollType.CENTER); } } }