PsiClass (final GrTypeDefinition psiClass, final PsiDirectory targetDirectory, final String className) { final Project project = psiClass.getProject(); final Ref<GrTypeDefinition> targetClass = new Ref<>(); WriteCommandAction.writeCommandAction(project).withName(getTitle(psiClass)).withGroupId(getTitle(psiClass)).run(() -> { IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace(); final GrTypeParameterList oldTypeParameterList = psiClass.getTypeParameterList(); try { targetClass.set(CreateClassActionBase.createClassByType(targetDirectory, className, PsiManager.getInstance(project), psiClass, GroovyTemplates.GROOVY_CLASS, true)); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater( () -> Messages.showErrorDialog(project, JavaBundle.message("intention.error.cannot.create.class.message", className) + "\n" + e.getLocalizedMessage(), JavaBundle.message("intention.error.cannot.create.class.title"))); return; } startTemplate(oldTypeParameterList, project, psiClass, targetClass.get(), false); }); if (targetClass.get() == null) return null; if (!ApplicationManager.getApplication().isUnitTestMode() && !psiClass.hasTypeParameters()) { final Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.get().getContainingFile(), targetClass.get()); if (editor == null) return targetClass.get(); chooseAndImplement(psiClass, project, targetClass.get(), editor); } return targetClass.get(); }