PsiElement (final Project project, final CreateTestDialog d) { return PostprocessReformattingAspect.getInstance(project).postponeFormattingInside( () -> ApplicationManager.getApplication().runWriteAction(new Computable<PsiElement>() { @Override public PsiElement compute() { try { IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace(); PsiClass targetClass = createTestClass(d); if (targetClass == null) { return null; } final TestFramework frameworkDescriptor = d.getSelectedTestFrameworkDescriptor(); final String defaultSuperClass = frameworkDescriptor.getDefaultSuperClass(); final String superClassName = d.getSuperClassName(); if (!Comparing.strEqual(superClassName, defaultSuperClass)) { addSuperClass(targetClass, project, superClassName); } PsiFile file = targetClass.getContainingFile(); Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, file, targetClass); addTestMethods(editor, targetClass, d.getTargetClass(), frameworkDescriptor, d.getSelectedMethods(), d.shouldGeneratedBefore(), d.shouldGeneratedAfter()); if (file instanceof PsiJavaFile) { PsiImportList list = ((PsiJavaFile)file).getImportList(); if (list != null) { PsiImportStatementBase[] importStatements = list.getAllImportStatements(); if (importStatements.length > 0) { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(list); if (virtualFile != null) { Set<String> imports = new HashSet<>(); for (PsiImportStatementBase base : importStatements) { imports.add(base.getText()); } virtualFile.putCopyableUserData(ImportsHighlightUtil.IMPORTS_FROM_TEMPLATE, imports); } } } } return targetClass; } catch (IncorrectOperationException e) { showErrorLater(project, d.getClassName()); return null; } } })); }