Runnable (final Editor editor, final PsiFile file, final Project project) { return () -> { TemplateManager.getInstance(project).finishTemplate(editor); if (DumbService.getInstance(project).isDumb()) return; int offset = editor.getCaretModel().getOffset(); RangeMarker marker = editor.getDocument().createRangeMarker(offset, offset); record OverrideContext(@NotNull PsiAnonymousClass aClass, @NotNull Collection<CandidateInfo> candidatesToImplement, @Nullable JavaOverrideImplementMemberChooser.JavaOverrideImplementMemberChooserContainer container) {} ReadAction.nonBlocking(() -> { PsiAnonymousClass anonymousClass = PsiTreeUtil.findElementOfClassAtOffset(file, marker.getStartOffset(), PsiAnonymousClass.class, false); if (anonymousClass == null) return null; final Collection<CandidateInfo> candidatesToImplement = OverrideImplementExploreUtil.getMethodsToOverrideImplement(anonymousClass, true); candidatesToImplement.removeIf( candidate -> candidate.getElement() instanceof PsiMethod method && method.hasModifierProperty(PsiModifier.DEFAULT)); JavaOverrideImplementMemberChooser.JavaOverrideImplementMemberChooserContainer container = null; if (candidatesToImplement.isEmpty()) { container = OverrideImplementUtil.prepareChooser(anonymousClass, false); } return new OverrideContext(anonymousClass, candidatesToImplement, container); }).withDocumentsCommitted(project) .finishOnUiThread(ModalityState.nonModal(), context -> { marker.dispose(); if (context == null) return; CommandProcessor.getInstance().executeCommand(project, () -> { PsiAnonymousClass anonymousClass = context.aClass; boolean invokeOverride = context.candidatesToImplement.isEmpty(); if (invokeOverride) { OverrideImplementUtil.showAndPerform(project, editor, anonymousClass, false, context.container); } else { ApplicationManagerEx.getApplicationEx() .runWriteActionWithCancellableProgressInDispatchThread(getCommandName(), project, editor.getComponent(), indicator -> { try { List<PsiMethod> methods = OverrideImplementUtil.overrideOrImplementMethodCandidates( anonymousClass, context.candidatesToImplement, false); List<PsiGenerationInfo<PsiMethod>> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods); List<PsiGenerationInfo<PsiMethod>> resultMembers = GenerateMembersUtil.insertMembersBeforeAnchor(anonymousClass, null, prototypes); resultMembers.get(0).positionCaret(editor, true); } catch (IncorrectOperationException ioe) { LOG.error(ioe); } }); } }, getCommandName(), getCommandName(), UndoConfirmationPolicy.DEFAULT, editor.getDocument()); }).submit(AppExecutorUtil.getAppExecutorService()); }; }