diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java index 16e2d690a670..eb2b6548fa86 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java @@ -16,8 +16,6 @@ package com.intellij.testFramework.fixtures.impl; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.Result; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -61,12 +59,7 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i } }); assert qName != null; - final PsiFile psiFile = new WriteCommandAction(getProject()) { - @Override - protected void run(Result result) throws Throwable { - result.setResult(addFileToProject(rootPath, qName.replace('.', '/') + ".java", classText)); - } - }.execute().getResultObject(); + final PsiFile psiFile = addFileToProject(rootPath, qName.replace('.', '/') + ".java", classText); return ApplicationManager.getApplication().runReadAction(new Computable() { public PsiClass compute() { return ((PsiJavaFile)psiFile).getClasses()[0]; diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 54e5098eec1a..e0173add5201 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -919,21 +919,26 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return addFileToProject(getTempDirPath(), relativePath, fileText); } - protected PsiFile addFileToProject(String rootPath, String relativePath, String fileText) { - try { - if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) { - final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText); - return PsiManager.getInstance(getProject()).findFile(file); + protected PsiFile addFileToProject(final String rootPath, final String relativePath, final String fileText) { + return new WriteCommandAction(getProject()) { + @Override + protected void run(Result result) throws Throwable { + try { + if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) { + final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText); + result.setResult(PsiManager.getInstance(getProject()).findFile(file)); + } else { + result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText)); + } + } + catch (IOException e) { + throw new RuntimeException(e); + } + finally { + ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter(); + } } - - return ((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText); - } - catch (IOException e) { - throw new RuntimeException(e); - } - finally { - ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter(); - } + }.execute().getResultObject(); } public void registerExtension(final ExtensionsArea area, final ExtensionPointName epName, final T extension) { @@ -1073,36 +1078,56 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public void setUp() throws Exception { super.setUp(); - myProjectFixture.setUp(); - myTempDirFixture.setUp(); - myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject()); - configureInspections(myInspections == null ? LocalInspectionTool.EMPTY_ARRAY : myInspections); + edt(new Runnable() { + @Override + public void run() { + try { + myProjectFixture.setUp(); + myTempDirFixture.setUp(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject()); + configureInspections(myInspections == null ? LocalInspectionTool.EMPTY_ARRAY : myInspections); - DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject()); - daemonCodeAnalyzer.prepareForTest(); + DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject()); + daemonCodeAnalyzer.prepareForTest(); - DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); - ensureIndexesUpToDate(getProject()); - ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities(); + DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); + ensureIndexesUpToDate(getProject()); + ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities(); + } + }); } @Override public void tearDown() throws Exception { - FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); - VirtualFile[] openFiles = editorManager.getOpenFiles(); - for (VirtualFile openFile : openFiles) { - editorManager.closeFile(openFile); - } + edt(new Runnable() { + @Override + public void run() { + FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); + VirtualFile[] openFiles = editorManager.getOpenFiles(); + for (VirtualFile openFile : openFiles) { + editorManager.closeFile(openFile); + } - myEditor = null; - myFile = null; - myPsiManager = null; + myEditor = null; + myFile = null; + myPsiManager = null; - myInspections = null; - myAvailableTools.clear(); + myInspections = null; + myAvailableTools.clear(); - myProjectFixture.tearDown(); - myTempDirFixture.tearDown(); + try { + myProjectFixture.tearDown(); + myTempDirFixture.tearDown(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + }); super.tearDown(); }