PsiElement (final Project project, final CreateTestDialog d) { return WriteAction.compute(() -> { final PsiClass test = (PsiClass)PostprocessReformattingAspect.getInstance(project).postponeFormattingInside( (Computable<PsiElement>)() -> { try { IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace(); GrTypeDefinition targetClass = CreateClassActionBase.createClassByType( d.getTargetDirectory(), d.getClassName(), PsiManager.getInstance(project), null, GroovyTemplates.GROOVY_CLASS, true); if (targetClass == null) return null; addSuperClass(targetClass, project, d.getSuperClassName()); Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.getContainingFile(), targetClass); addTestMethods(editor, targetClass, d.getSelectedTestFrameworkDescriptor(), d.getSelectedMethods(), d.shouldGeneratedBefore(), d.shouldGeneratedAfter()); return targetClass; } catch (IncorrectOperationException e1) { showErrorLater(project, d.getClassName()); return null; } }); if (test == null) return null; JavaCodeStyleManager.getInstance(test.getProject()).shortenClassReferences(test); CodeStyleManager.getInstance(project).reformat(test); return test; }); }