diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 079275f78b83..6c79dcb7d6fd 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -364,10 +364,6 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { }.execute().getResultObject(); } - @Override - protected boolean isRunInWriteAction() { - return false; - } protected static void assertOutput(Module module, TestFileSystemBuilder item) { assertOutput(module, item, false); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java index ba0d3046a3dd..068ecb0ba63a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java @@ -180,13 +180,8 @@ public class JavaExternalDocumentationTest extends PlatformTestCase { finally { EditorFactory.getInstance().releaseEditor(editor); } - } - - @Override - protected boolean isRunInWriteAction() { - return false; } - + private static class MockDocumentationComponent extends DocumentationComponent { private String myText; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessorTest.java index f6dae6ac4074..433a8ddf3d84 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessorTest.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.actions; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -23,6 +24,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiDocumentManager; @@ -263,7 +265,7 @@ public abstract class AbstractLayoutCodeProcessorTest extends PsiTestCase { PsiDirectory dir = createDirectory(getTempRootDirectory().getVirtualFile(), newModuleName); String path = dir.getVirtualFile().getPath() + "/" + newModuleName + ".iml"; - Module module = ModuleManager.getInstance(getProject()).newModule(path, StdModuleTypes.JAVA.getId()); + Module module = ApplicationManager.getApplication().runWriteAction((Computable)() -> ModuleManager.getInstance(getProject()).newModule(path, StdModuleTypes.JAVA.getId())); PsiDirectory src = createDirectory(dir.getVirtualFile(), "src"); PsiTestUtil.addSourceRoot(module, src.getVirtualFile()); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index 558828acda8d..0c47086d1d89 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -107,7 +107,6 @@ import com.intellij.openapi.util.ProperTextRange; import com.intellij.openapi.util.Segment; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; @@ -1420,7 +1419,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { @Override protected void run(@NotNull Result result) throws Throwable { VirtualFile alienFile = alienRoot.createChildData(this, "X.java"); - VfsUtil.saveText(alienFile, "class Alien { }"); + setFileText(alienFile, "class Alien { }"); OpenFileDescriptor alienDescriptor = new OpenFileDescriptor(alienProject, alienFile); result.setResult(alienDescriptor); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java index 783dffd4486f..6ecd882bcd75 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java @@ -388,9 +388,4 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { return html == null ? null : StringUtil.convertLineSeparators(html.trim()).replaceAll("", ""); } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java index bad06c2b089b..0028a2e2c2ac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,11 +89,6 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase { super.tearDown(); } - @Override - protected boolean isRunInWriteAction() { - return false; - } - @Override protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath() + "/inspection/globalContext/"; diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index bf4d6b65f0b9..8a19c58bcbd6 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -44,8 +44,6 @@ import java.io.File; import java.io.IOException; import java.util.*; -import static java.util.Collections.singletonList; - @PlatformTestCase.WrapInCommand public class DirectoryIndexTest extends IdeaTestCase { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.DirectoryIndexTest"); @@ -68,11 +66,6 @@ public class DirectoryIndexTest extends IdeaTestCase { private VirtualFile myExcludedLibSrcDir, myExcludedLibClsDir; private ProjectFileIndex myFileIndex; - @Override - protected boolean isRunInWriteAction() { - return false; - } - @Override protected void setUp() throws Exception { super.setUp(); @@ -149,7 +142,8 @@ public class DirectoryIndexTest extends IdeaTestCase { PsiTestUtil.addSourceRoot(myModule, myTestResDir, JavaResourceRootType.TEST_RESOURCE); ModuleRootModificationUtil.addModuleLibrary(myModule, "lib.js", - singletonList(myFileLibCls.getUrl()), singletonList(myFileLibSrc.getUrl())); + Collections.singletonList(myFileLibCls.getUrl()), Collections + .singletonList(myFileLibSrc.getUrl())); PsiTestUtil.addExcludedRoot(myModule, myExcludedLibClsDir); PsiTestUtil.addExcludedRoot(myModule, myExcludedLibSrcDir); } @@ -163,7 +157,7 @@ public class DirectoryIndexTest extends IdeaTestCase { PsiTestUtil.addSourceRoot(myModule2, mySrcDir2); PsiTestUtil.addExcludedRoot(myModule2, myExcludeDir); ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib", - singletonList(myLibClsDir.getUrl()), singletonList(myLibSrcDir.getUrl()), + Collections.singletonList(myLibClsDir.getUrl()), Collections.singletonList(myLibSrcDir.getUrl()), Arrays.asList(myExcludedLibClsDir.getUrl(), myExcludedLibSrcDir.getUrl()), DependencyScope.COMPILE, true); } @@ -815,7 +809,7 @@ public class DirectoryIndexTest extends IdeaTestCase { public void testFileLibraryInsideFolderLibrary() throws IOException { VirtualFile file = createChildData(myLibSrcDir, "empty.txt"); ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib2", - Collections.emptyList(), singletonList(file.getUrl()), + Collections.emptyList(), Collections.singletonList(file.getUrl()), Collections.emptyList(), DependencyScope.COMPILE, true); // same for the dir and for the file diff --git a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java index e6d23df14478..0fabec350c61 100644 --- a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java +++ b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java @@ -85,9 +85,4 @@ public class LoadProjectTest extends PlatformTestCase { psiFile -> psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem && psiFile.getProject() == getProject()); } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java index e9cd4ecd0f53..89d8b15c9a9a 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -227,9 +227,4 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath(); } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/java-tests/testSrc/com/intellij/psi/AddClassToFileTest.java b/java/java-tests/testSrc/com/intellij/psi/AddClassToFileTest.java index f41efd5de2ff..c4bdd18441aa 100644 --- a/java/java-tests/testSrc/com/intellij/psi/AddClassToFileTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/AddClassToFileTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,11 @@ package com.intellij.psi; import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PsiTestCase; @@ -30,20 +32,36 @@ public class AddClassToFileTest extends PsiTestCase{ VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete); PsiDirectory dir = myPsiManager.findDirectory(root); assertNotNull(dir); - PsiFile file = dir.createFile("AAA.java"); + PsiFile file = ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public PsiFile compute() { + return dir.createFile("AAA.java"); + } + }); PsiClass aClass = myJavaFacade.getElementFactory().createClass("AAA"); - file.add(aClass); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + file.add(aClass); + } + }); + PsiTestUtil.checkFileStructure(file); } public void testFileModified() throws Exception { VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete); - VirtualFile pkg = root.createChildDirectory(this, "foo"); + VirtualFile pkg = createChildDirectory(root, "foo"); PsiDirectory dir = myPsiManager.findDirectory(pkg); assertNotNull(dir); String text = "package foo;\n\nclass A {}"; - PsiElement created = dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText("A.java", JavaFileType.INSTANCE, text)); + PsiElement created = ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public PsiElement compute() { + return dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText("A.java", JavaFileType.INSTANCE, text)); + } + }); VirtualFile virtualFile = created.getContainingFile().getVirtualFile(); assertNotNull(virtualFile); String fileText = LoadTextUtil.loadText(virtualFile).toString(); diff --git a/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java b/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java index dd0611f53175..d9060d7fd40c 100644 --- a/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java @@ -1,14 +1,30 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.psi; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.LightVirtualFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.PsiTestCase; -import com.intellij.psi.search.GlobalSearchScope; @PlatformTestCase.WrapInCommand public class CodeFragmentsTest extends PsiTestCase{ @@ -16,20 +32,32 @@ public class CodeFragmentsTest extends PsiTestCase{ PsiCodeFragment fragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment("AAA.foo()", null, null, false); PsiClass arrayListClass = myJavaFacade.findClass("java.util.ArrayList", GlobalSearchScope.allScope(getProject())); PsiReference ref = fragment.findReferenceAt(0); - ref.bindToElement(arrayListClass); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + ref.bindToElement(arrayListClass); + } + }); + assertEquals("ArrayList.foo()", fragment.getText()); } public void testDontLoseDocument() { PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment("a", null, null, true); - Document document = PsiDocumentManager.getInstance(myProject).getDocument(fragment); - document.insertString(1, "b"); - PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - assertEquals("ab", fragment.getText()); - assertEquals("ab", fragment.getExpression().getText()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + Document document = PsiDocumentManager.getInstance(myProject).getDocument(fragment); + document.insertString(1, "b"); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + assertEquals("ab", fragment.getText()); + assertEquals("ab", fragment.getExpression().getText()); + + //noinspection UnusedAssignment + document = null; + } + }); - //noinspection UnusedAssignment - document = null; PlatformTestUtil.tryGcSoftlyReachableObjects(); assertEquals("ab", PsiDocumentManager.getInstance(myProject).getDocument(fragment).getText()); @@ -40,7 +68,13 @@ public class CodeFragmentsTest extends PsiTestCase{ VirtualFile file = fragment.getViewProvider().getVirtualFile(); assertInstanceOf(file, LightVirtualFile.class); - ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.getInstance(), false, true); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.getInstance(), false, true); + } + }); + assertSame(fragment, PsiManager.getInstance(myProject).findFile(file)); assertTrue(fragment.isValid()); diff --git a/java/java-tests/testSrc/com/intellij/psi/CoreJavaFileManagerTest.java b/java/java-tests/testSrc/com/intellij/psi/CoreJavaFileManagerTest.java index c5ddcde7cc69..5328e9594e8c 100644 --- a/java/java-tests/testSrc/com/intellij/psi/CoreJavaFileManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/CoreJavaFileManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.psi; import com.intellij.core.CoreJavaFileManager; import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.PlatformTestCase; @@ -186,10 +187,16 @@ public class CoreJavaFileManagerTest extends PsiTestCase { @NotNull private CoreJavaFileManager configureManager(@Language("JAVA") @NotNull String text, @NotNull String className) throws Exception { VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete); - VirtualFile pkg = root.createChildDirectory(this, "foo"); + VirtualFile pkg = createChildDirectory(root, "foo"); PsiDirectory dir = myPsiManager.findDirectory(pkg); assertNotNull(dir); - dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText(className + ".java", JavaFileType.INSTANCE, text)); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText(className + ".java", JavaFileType.INSTANCE, text)); + } + }); + CoreJavaFileManager manager = new CoreJavaFileManager(myPsiManager); manager.addToClasspath(root); return manager; diff --git a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java index 7b9d54b665ae..be74702c925b 100644 --- a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java @@ -1,6 +1,22 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.psi; import com.intellij.JavaTestUtil; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PsiTestCase; @@ -27,10 +43,22 @@ public class NormalizeDeclarationTest extends PsiTestCase{ assertTrue(element instanceof PsiIdentifier); assertTrue(element.getParent() instanceof PsiVariable); - ((PsiVariable)element.getParent()).normalizeDeclaration(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + ((PsiVariable)element.getParent()).normalizeDeclaration(); + } + }); + String textAfter = loadFile(getTestName(false) + "_after.java"); - PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); + } + }); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); String fileText = myFile.getText(); diff --git a/java/java-tests/testSrc/com/intellij/psi/OverlappingSourceRootsTest.java b/java/java-tests/testSrc/com/intellij/psi/OverlappingSourceRootsTest.java index 1a91661a2187..0fdf0bff6107 100644 --- a/java/java-tests/testSrc/com/intellij/psi/OverlappingSourceRootsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/OverlappingSourceRootsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.psi; import com.intellij.openapi.application.ApplicationManager; @@ -39,10 +54,10 @@ public class OverlappingSourceRootsTest extends PsiTestCase { myProjectRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getPath().replace(File.separatorChar, '/')); - mySourceRoot1 = myProjectRoot.createChildDirectory(null, "root1"); - mySourceRoot2 = myProjectRoot.createChildDirectory(null, "root2"); - mySourceRoot11 = mySourceRoot1.createChildDirectory(null, "root11"); - mySourceRoot21 = mySourceRoot2.createChildDirectory(null, "root21"); + mySourceRoot1 = createChildDirectory(myProjectRoot, "root1"); + mySourceRoot2 = createChildDirectory(myProjectRoot, "root2"); + mySourceRoot11 = createChildDirectory(mySourceRoot1, "root11"); + mySourceRoot21 = createChildDirectory(mySourceRoot2, "root21"); PsiTestUtil.addContentRoot(myModule, myProjectRoot); PsiTestUtil.addSourceRoot(myModule, mySourceRoot21); @@ -50,10 +65,10 @@ public class OverlappingSourceRootsTest extends PsiTestCase { PsiTestUtil.addSourceRoot(myModule, mySourceRoot2); PsiTestUtil.addSourceRoot(myModule, mySourceRoot11); - myFile1 = mySourceRoot1.createChildData(null, "File1.java"); - myFile2 = mySourceRoot2.createChildData(null, "File2.java"); - myFile11 = mySourceRoot11.createChildData(null, "File11.java"); - myFile21 = mySourceRoot21.createChildData(null, "File21.java"); + myFile1 = createChildData(mySourceRoot1, "File1.java"); + myFile2 = createChildData(mySourceRoot2, "File2.java"); + myFile11 = createChildData(mySourceRoot11, "File11.java"); + myFile21 = createChildData(mySourceRoot21, "File21.java"); } catch (IOException e) { LOG.error(e); } diff --git a/java/java-tests/testSrc/com/intellij/psi/SrcRepositoryUseTest.java b/java/java-tests/testSrc/com/intellij/psi/SrcRepositoryUseTest.java index bbf4056c70d8..98740f83d35e 100644 --- a/java/java-tests/testSrc/com/intellij/psi/SrcRepositoryUseTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/SrcRepositoryUseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -628,7 +628,13 @@ public class SrcRepositoryUseTest extends PsiTestCase{ PsiClass aClass = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject)); assertNotNull(aClass); - aClass.getNameIdentifier().replace(myJavaFacade.getElementFactory().createIdentifier("NewName")); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + aClass.getNameIdentifier().replace(myJavaFacade.getElementFactory().createIdentifier("NewName")); + } + }); + assertEquals("pack.NewName", aClass.getQualifiedName()); } @@ -637,13 +643,25 @@ public class SrcRepositoryUseTest extends PsiTestCase{ assertNotNull(aClass); PsiField field = aClass.getFields()[0]; - aClass.getNameIdentifier().replace(myJavaFacade.getElementFactory().createIdentifier("NewName")); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + aClass.getNameIdentifier().replace(myJavaFacade.getElementFactory().createIdentifier("NewName")); + } + }); + assertTrue(field.isValid()); } public void testModification2() throws Exception { PsiClass aClass = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject)); - PsiUtil.setModifierProperty(aClass, PsiModifier.FINAL, true); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PsiUtil.setModifierProperty(aClass, PsiModifier.FINAL, true); + } + }); + PsiClass aClass2 = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject)); assertEquals(aClass, aClass2); @@ -656,9 +674,21 @@ public class SrcRepositoryUseTest extends PsiTestCase{ BlockSupport blockSupport = ServiceManager.getService(myProject, BlockSupport.class); final PsiFile psiFile = aClass.getContainingFile(); - blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getEndOffset(), ""); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getEndOffset(), ""); + } + }); + LOG.assertTrue(!aClass.isValid()); - blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getStartOffset(), text); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getStartOffset(), text); + } + }); + aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject)); PsiElement[] children = aClass.getChildren(); @@ -751,7 +781,12 @@ public class SrcRepositoryUseTest extends PsiTestCase{ PsiMethod[] methods = nonAnonClass.getMethods(); assertEquals(1, methods.length); PsiTypeElement newType = myJavaFacade.getElementFactory().createTypeElement(PsiType.FLOAT); - methods[0].getReturnTypeElement().replace(newType); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + methods[0].getReturnTypeElement().replace(newType); + } + }); } public void testParentIdAssertOnExternalChange() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java index c3825da78195..d292d339346f 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,12 +64,12 @@ public class FindClassTest extends PsiTestCase { VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(root.getAbsolutePath().replace(File.separatorChar, '/')); - myPrjDir1 = rootVFile.createChildDirectory(null, "prj1"); - mySrcDir1 = myPrjDir1.createChildDirectory(null, "src1"); + myPrjDir1 = createChildDirectory(rootVFile, "prj1"); + mySrcDir1 = createChildDirectory(myPrjDir1, "src1"); - myPackDir = mySrcDir1.createChildDirectory(null, "p"); - VirtualFile file1 = myPackDir.createChildData(null, "A.java"); - VfsUtil.saveText(file1, "package p; public class A{ public void foo(); }"); + myPackDir = createChildDirectory(mySrcDir1, "p"); + VirtualFile file1 = createChildData(myPackDir, "A.java"); + setFileText(file1, "package p; public class A{ public void foo(); }"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiTestUtil.addContentRoot(myModule, myPrjDir1); diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/IdCacheTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/IdCacheTest.java index a1c4fbba4a23..e4c0891f709f 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/IdCacheTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/IdCacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.intellij.ide.todo.TodoConfiguration; import com.intellij.ide.todo.TodoIndexPatternProvider; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -70,14 +69,14 @@ public class IdCacheTest extends CodeInsightTestCase{ } public void testUpdateCache1() throws Exception { - myRootDir.createChildData(null, "4.java"); + createChildData(myRootDir, "4.java"); Thread.sleep(1000); checkCache(CacheManager.SERVICE.getInstance(myProject), TodoCacheManager.SERVICE.getInstance(myProject)); } public void testUpdateCache2() throws Exception { VirtualFile child = myRootDir.findChild("1.java"); - VfsUtil.saveText(child, "xxx"); + setFileText(child, "xxx"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); FileDocumentManager.getInstance().saveAllDocuments(); @@ -100,7 +99,7 @@ public class IdCacheTest extends CodeInsightTestCase{ public void testUpdateCache3() throws Exception { VirtualFile child = myRootDir.findChild("1.java"); - child.delete(null); + delete(child); final CacheManager cache2 = CacheManager.SERVICE.getInstance(myProject); final TodoCacheManager todocache2 = TodoCacheManager.SERVICE.getInstance(myProject); @@ -118,7 +117,7 @@ public class IdCacheTest extends CodeInsightTestCase{ } public void testUpdateCacheNoTodo() throws Exception { - myRootDir.createChildData(null, "4.java"); + createChildData(myRootDir, "4.java"); final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject); final CacheManager cache = CacheManager.SERVICE.getInstance(myProject); checkResult(new String[]{"1.java", "2.java"}, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false))); @@ -150,7 +149,8 @@ public class IdCacheTest extends CodeInsightTestCase{ checkCache(cache, todocache); - VfsUtil.saveText(child, "xxx"); + setFileText(child, "xxx"); + setFileText(child, "xxx"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject); @@ -173,7 +173,7 @@ public class IdCacheTest extends CodeInsightTestCase{ checkCache(cache, todocache); VirtualFile child = myRootDir.findChild("1.java"); - child.delete(null); + delete(child); final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject); checkResult(new String[]{}, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false))); @@ -193,8 +193,8 @@ public class IdCacheTest extends CodeInsightTestCase{ final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject); checkCache(cache, todocache); - VirtualFile child = myRootDir.createChildData(null, "4.java"); - VfsUtil.saveText(child, "xxx //todo"); + VirtualFile child = createChildData(myRootDir, "4.java"); + setFileText(child, "xxx //todo"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject); diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java index dbe19a31a5a0..c8e701bc68c2 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; @@ -47,14 +46,15 @@ public class SameSourceRootInTwoModulesTest extends PsiTestCase { @Override public void run() { try { - VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(root.getAbsolutePath().replace(File.separatorChar, '/')); + VirtualFile rootVFile = + LocalFileSystem.getInstance().refreshAndFindFileByPath(root.getAbsolutePath().replace(File.separatorChar, '/')); - myPrjDir1 = rootVFile.createChildDirectory(null, "prj1"); - mySrcDir1 = myPrjDir1.createChildDirectory(null, "src1"); + myPrjDir1 = createChildDirectory(rootVFile, "prj1"); + mySrcDir1 = createChildDirectory(myPrjDir1, "src1"); - myPackDir = mySrcDir1.createChildDirectory(null, "p"); - VirtualFile file1 = myPackDir.createChildData(null, "A.java"); - VfsUtil.saveText(file1, "package p; public class A{ public void foo(); }"); + myPackDir = createChildDirectory(mySrcDir1, "p"); + VirtualFile file1 = createChildData(myPackDir, "A.java"); + setFileText(file1, "package p; public class A{ public void foo(); }"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiTestUtil.addContentRoot(myModule, myPrjDir1); diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java index 17babf5920ee..9182b959e31a 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,8 @@ */ package com.intellij.psi.impl.cache.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -40,21 +38,11 @@ public class SourceRootAddedAsLibraryRootTest extends PsiTestCase { super.setUp(); final File root = createTempDirectory(); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - try { - VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(root.getAbsolutePath().replace(File.separatorChar, '/')); + VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(root.getAbsolutePath().replace(File.separatorChar, '/')); - myDir = rootVFile.createChildDirectory(null, "contentAndLibrary"); + myDir = createChildDirectory(rootVFile, "contentAndLibrary"); - PsiTestUtil.addSourceRoot(myModule, myDir); - } - catch (IOException e) { - LOG.error(e); - } - } - }); + PsiTestUtil.addSourceRoot(myModule, myDir); } private void changeRoots() { @@ -69,8 +57,8 @@ public class SourceRootAddedAsLibraryRootTest extends PsiTestCase { } private void touchFileSync() throws IOException { - myVFile = myDir.createChildData(null, "A.java"); - VfsUtil.saveText(myVFile, "package p; public class A{ public void foo(); }"); + myVFile = createChildData(myDir, "A.java"); + setFileText(myVFile, "package p; public class A{ public void foo(); }"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); } } diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java index c9f8d7e76001..1203b848c452 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java @@ -21,9 +21,9 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx; import com.intellij.openapi.roots.ModuleRootModificationUtil; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.PsiTreeChangeEventImpl; @@ -62,30 +62,26 @@ public class PsiEventsTest extends PsiTestCase { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - try { - VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); + VirtualFile rootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); - myPrjDir1 = rootVFile.createChildDirectory(null, "prj1"); - mySrcDir1 = myPrjDir1.createChildDirectory(null, "src1"); - mySrcDir2 = myPrjDir1.createChildDirectory(null, "src2"); + myPrjDir1 = createChildDirectory(rootVFile, "prj1"); + mySrcDir1 = createChildDirectory(myPrjDir1, "src1"); + mySrcDir2 = createChildDirectory(myPrjDir1, "src2"); - myPrjDir2 = rootVFile.createChildDirectory(null, "prj2"); - mySrcDir3 = myPrjDir2; + myPrjDir2 = createChildDirectory(rootVFile, "prj2"); + mySrcDir3 = myPrjDir2; - myClsDir1 = myPrjDir1.createChildDirectory(null, "cls1"); + myClsDir1 = createChildDirectory(myPrjDir1, "cls1"); - myIgnoredDir = mySrcDir1.createChildDirectory(null, "CVS"); + myIgnoredDir = createChildDirectory(mySrcDir1, "CVS"); - PsiTestUtil.addContentRoot(myModule, myPrjDir1); - PsiTestUtil.addSourceRoot(myModule, mySrcDir1); - PsiTestUtil.addSourceRoot(myModule, mySrcDir2); - PsiTestUtil.addContentRoot(myModule, myPrjDir2); - ModuleRootModificationUtil.addModuleLibrary(myModule, myClsDir1.getUrl()); - PsiTestUtil.addSourceRoot(myModule, mySrcDir3); - } catch (IOException e) { - LOG.error(e); - } + PsiTestUtil.addContentRoot(myModule, myPrjDir1); + PsiTestUtil.addSourceRoot(myModule, mySrcDir1); + PsiTestUtil.addSourceRoot(myModule, mySrcDir2); + PsiTestUtil.addContentRoot(myModule, myPrjDir2); + ModuleRootModificationUtil.addModuleLibrary(myModule, myClsDir1.getUrl()); + PsiTestUtil.addSourceRoot(myModule, mySrcDir3); } }); } @@ -96,7 +92,7 @@ public class PsiEventsTest extends PsiTestCase { myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); PsiDirectory psiDir = fileManager.findDirectory(myPrjDir1); - myPrjDir1.createChildData(null, "a.txt"); + createChildData(myPrjDir1, "a.txt"); String string = listener.getEventsString(); String expected = @@ -111,7 +107,7 @@ public class PsiEventsTest extends PsiTestCase { myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); PsiDirectory psiDir = fileManager.findDirectory(myPrjDir1); - myPrjDir1.createChildDirectory(null, "aaa"); + createChildDirectory(myPrjDir1, "aaa"); String string = listener.getEventsString(); String expected = @@ -121,7 +117,7 @@ public class PsiEventsTest extends PsiTestCase { } public void testDeleteFile() throws Exception { - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); FileManager fileManager = myPsiManager.getFileManager(); PsiFile psiFile = fileManager.findFile(file);//it's important to hold the reference @@ -129,7 +125,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.delete(null); + delete(file); String string = listener.getEventsString(); String expected = @@ -139,7 +135,7 @@ public class PsiEventsTest extends PsiTestCase { } public void testDeleteDirectory() throws Exception { - VirtualFile file = myPrjDir1.createChildDirectory(null, "aaa"); + VirtualFile file = createChildDirectory(myPrjDir1, "aaa"); FileManager fileManager = myPsiManager.getFileManager(); PsiDirectory psiDirectory = fileManager.findDirectory(file); @@ -147,7 +143,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.delete(null); + delete(file); String string = listener.getEventsString(); String expected = @@ -158,7 +154,7 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameFile() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); PsiDirectory directory = fileManager.findDirectory(myPrjDir1); @@ -167,7 +163,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "b.txt"); + rename(file, "b.txt"); String string = listener.getEventsString(); String expected = @@ -178,7 +174,7 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameFileWithoutDir() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); PlatformTestUtil.tryGcSoftlyReachableObjects(); @@ -206,7 +202,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "b.txt"); + rename(file, "b.txt"); String string = listener.getEventsString(); String expected = @@ -217,13 +213,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameFileChangingExtension() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "b.xml"); + rename(file, "b.xml"); String string = listener.getEventsString(); String expected = @@ -234,13 +230,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameFileToIgnored() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "CVS"); + rename(file, "CVS"); String string = listener.getEventsString(); String expected = @@ -252,13 +248,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameFileFromIgnored() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "CVS"); + VirtualFile file = createChildData(myPrjDir1, "CVS"); PsiDirectory psiDirectory = fileManager.findDirectory(file.getParent()); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "aaa.txt"); + rename(file, "aaa.txt"); String string = listener.getEventsString(); String expected = @@ -269,13 +265,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameDirectory_WithPsiDir() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "dir1"); + VirtualFile file = createChildDirectory(myPrjDir1, "dir1"); PsiDirectory psiDirectory = fileManager.findDirectory(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "dir2"); + rename(file, "dir2"); String string = listener.getEventsString(); String expected = @@ -286,7 +282,7 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameDirectory_WithoutPsiDir() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "dir1"); + VirtualFile file = createChildDirectory(myPrjDir1, "dir1"); PlatformTestUtil.tryGcSoftlyReachableObjects(); @@ -295,7 +291,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "dir2"); + rename(file, "dir2"); String string = listener.getEventsString(); String expected = @@ -306,13 +302,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameDirectoryToIgnored() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "dir1"); + VirtualFile file = createChildDirectory(myPrjDir1, "dir1"); PsiDirectory psiDirectory = fileManager.findDirectory(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "CVS"); + rename(file, "CVS"); String string = listener.getEventsString(); String expected = @@ -324,13 +320,13 @@ public class PsiEventsTest extends PsiTestCase { public void testRenameDirectoryFromIgnored() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "CVS"); + VirtualFile file = createChildDirectory(myPrjDir1, "CVS"); PsiDirectory psiDirectory = fileManager.findDirectory(file.getParent()); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.rename(null, "dir"); + rename(file, "dir"); String string = listener.getEventsString(); String expected = @@ -341,13 +337,20 @@ public class PsiEventsTest extends PsiTestCase { public void testMakeFileReadOnly() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); final EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); + return null; + } + }); + final String expected = "beforePropertyChange writable\n" + @@ -360,18 +363,24 @@ public class PsiEventsTest extends PsiTestCase { } }.assertCompleted(listener.getEventsString()); - ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); + return null; + } + }); } public void testMoveFile() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myPrjDir1.getParent()); + move(file, myPrjDir1.getParent()); String string = listener.getEventsString(); String expected = @@ -382,13 +391,13 @@ public class PsiEventsTest extends PsiTestCase { public void testMoveFileToIgnoredDir() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); PsiFile psiFile = fileManager.findFile(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myIgnoredDir); + move(file, myIgnoredDir); String string = listener.getEventsString(); String expected = @@ -399,12 +408,12 @@ public class PsiEventsTest extends PsiTestCase { } public void testMoveFileFromIgnoredDir() throws Exception { - VirtualFile file = myIgnoredDir.createChildData(null, "a.txt"); + VirtualFile file = createChildData(myIgnoredDir, "a.txt"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myPrjDir1); + move(file, myPrjDir1); String string = listener.getEventsString(); String expected = @@ -414,13 +423,13 @@ public class PsiEventsTest extends PsiTestCase { } public void testMoveFileInsideIgnoredDir() throws Exception { - VirtualFile file = myIgnoredDir.createChildData(null, "a.txt"); - VirtualFile subdir = myIgnoredDir.createChildDirectory(null, "subdir"); + VirtualFile file = createChildData(myIgnoredDir, "a.txt"); + VirtualFile subdir = createChildDirectory(myIgnoredDir, "subdir"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, subdir); + move(file, subdir); String string = listener.getEventsString(); String expected = ""; @@ -429,13 +438,13 @@ public class PsiEventsTest extends PsiTestCase { public void testMoveDirectory() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "dir"); + VirtualFile file = createChildDirectory(myPrjDir1, "dir"); PsiDirectory psiDirectory = fileManager.findDirectory(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myPrjDir1.getParent()); + move(file, myPrjDir1.getParent()); String string = listener.getEventsString(); String expected = @@ -446,13 +455,13 @@ public class PsiEventsTest extends PsiTestCase { public void testMoveDirectoryToIgnored() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildDirectory(null, "dir"); + VirtualFile file = createChildDirectory(myPrjDir1, "dir"); PsiDirectory psiDirectory = fileManager.findDirectory(file); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myIgnoredDir); + move(file, myIgnoredDir); String string = listener.getEventsString(); String expected = @@ -463,12 +472,12 @@ public class PsiEventsTest extends PsiTestCase { } public void testMoveDirectoryFromIgnored() throws Exception { - VirtualFile file = myIgnoredDir.createChildDirectory(null, "dir"); + VirtualFile file = createChildDirectory(myIgnoredDir, "dir"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, myPrjDir1); + move(file, myPrjDir1); String string = listener.getEventsString(); String expected = @@ -478,13 +487,13 @@ public class PsiEventsTest extends PsiTestCase { } public void testMoveDirectoryInsideIgnored() throws Exception { - VirtualFile file = myIgnoredDir.createChildDirectory(null, "dir"); - VirtualFile subdir = myIgnoredDir.createChildDirectory(null, "subdir"); + VirtualFile file = createChildDirectory(myIgnoredDir, "dir"); + VirtualFile subdir = createChildDirectory(myIgnoredDir, "subdir"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - file.move(null, subdir); + move(file, subdir); String string = listener.getEventsString(); String expected = ""; @@ -493,8 +502,8 @@ public class PsiEventsTest extends PsiTestCase { public void testChangeFile() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); - VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); - VfsUtil.saveText(file, "aaa"); + VirtualFile file = createChildData(myPrjDir1, "a.txt"); + setFileText(file, "aaa"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiFile psiFile = fileManager.findFile(file); psiFile.getText(); @@ -502,7 +511,7 @@ public class PsiEventsTest extends PsiTestCase { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); - VfsUtil.saveText(file, "bbb"); + setFileText(file, "bbb"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); /* @@ -520,7 +529,7 @@ public class PsiEventsTest extends PsiTestCase { } public void testAddExcludeRoot() throws IOException { - final VirtualFile dir = myPrjDir1.createChildDirectory(null, "aaa"); + final VirtualFile dir = createChildDirectory(myPrjDir1, "aaa"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); @@ -536,7 +545,7 @@ public class PsiEventsTest extends PsiTestCase { } public void testAddSourceRoot() throws IOException { - final VirtualFile dir = myPrjDir1.createChildDirectory(null, "aaa"); + final VirtualFile dir = createChildDirectory(myPrjDir1, "aaa"); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); @@ -579,7 +588,7 @@ public class PsiEventsTest extends PsiTestCase { } }; getPsiManager().addPsiTreeChangeListener(listener,getTestRootDisposable()); - virtualFile.rename(this, "b.xml"); + rename(virtualFile, "b.xml"); } String newText; @@ -698,10 +707,22 @@ public class PsiEventsTest extends PsiTestCase { this.newText = newText; original = getFile().getText(); Document document = PsiDocumentManager.getInstance(getProject()).getDocument(getFile()); - document.setText(newText); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.setText(newText); + } + }); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - document.setText(original); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.setText(original); + } + }); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); } finally { @@ -783,7 +804,13 @@ public class PsiEventsTest extends PsiTestCase { Document document = documentManager.getDocument(getFile()); assertTrue(documentManager.isCommitted(document)); - document.setText(""); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.setText(""); + } + }); + documentManager.commitAllDocuments(); assertTrue(documentManager.isCommitted(document)); } diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java index d6c65b5dd2cb..77fdb909684b 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java @@ -21,6 +21,7 @@ import com.intellij.ide.highlighter.HtmlFileType; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.ide.highlighter.XmlFileType; import com.intellij.lang.FileASTNode; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.EditorFactory; @@ -35,7 +36,6 @@ import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.util.Segment; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.source.PostprocessReformattingAspect; @@ -58,7 +58,10 @@ import org.junit.Assert; import java.io.IOException; import java.lang.ref.SoftReference; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.Set; import java.util.stream.Collectors; @PlatformTestCase.WrapInCommand @@ -83,7 +86,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); int offset = aClass.getTextOffset(); - document.insertString(offset, "/**/"); + insertString(document, offset, "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = pointer.getElement(); @@ -92,6 +95,15 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertTrue(element.isValid()); } + private static void insertString(Document document, int offset, String s) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.insertString(offset, s); + } + }); + } + // This test is unfair. If pointer would be asked for getElement() between commits it'll never restore again anyway. // public void testChangeInDocumentTwice() { @@ -102,9 +114,9 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); int offset = aClass.getTextOffset(); - document.insertString(offset, "/*"); + insertString(document, offset, "/*"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - document.insertString(offset + 2, "*/"); + insertString(document, offset + 2, "*/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = pointer.getElement(); @@ -121,10 +133,10 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); int offset = aClass.getTextOffset(); - document.insertString(offset, "/**/"); + insertString(document, offset, "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - document.insertString(offset, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + insertString(document, offset, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); PsiElement element = pointer.getElement(); assertNotNull(element); @@ -140,11 +152,11 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); int offset = aClass.getTextOffset(); - document.insertString(offset, "/******/"); + insertString(document, offset, "/******/"); pointer.getElement(); - document.insertString(offset, "/**/"); + insertString(document, offset, "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = pointer.getElement(); @@ -154,28 +166,33 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { } public void testRetrieveOnUncommittedDocument() { - PsiClass aClass = myJavaFacade.findClass("AClass",GlobalSearchScope.allScope(getProject())); - assertNotNull(aClass); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject())); + assertNotNull(aClass); - Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); - document.insertString(0, "/******/"); + Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); + document.insertString(0, "/******/"); - SmartPointerEx pointer = (SmartPointerEx)createPointer(aClass.getNameIdentifier()); + SmartPointerEx pointer = (SmartPointerEx)createPointer(aClass.getNameIdentifier()); - //noinspection UnusedAssignment - aClass = null; - PlatformTestUtil.tryGcSoftlyReachableObjects(); - assertNull(pointer.getCachedElement()); + //noinspection UnusedAssignment + aClass = null; + PlatformTestUtil.tryGcSoftlyReachableObjects(); + assertNull(pointer.getCachedElement()); - assertNotNull(pointer.getElement()); + assertNotNull(pointer.getElement()); - document.insertString(0, "/**/"); - PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + document.insertString(0, "/**/"); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - PsiElement element = pointer.getElement(); - assertNotNull(element); - assertTrue(element.getParent() instanceof PsiClass); - assertTrue(element.isValid()); + PsiElement element = pointer.getElement(); + assertNotNull(element); + assertTrue(element.getParent() instanceof PsiClass); + assertTrue(element.isValid()); + } + }); } public void testNoAstLoadingWithoutDocumentChanges() { @@ -206,7 +223,13 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertEquals(myFile.getFirstChild(), pointer.getElement()); Document document = myFile.getViewProvider().getDocument(); - document.deleteString(0, document.getTextLength()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.deleteString(0, document.getTextLength()); + } + }); + PlatformTestUtil.tryGcSoftlyReachableObjects(); assertEquals(myFile.getFirstChild(), pointer.getElement()); @@ -224,7 +247,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile()); int offset = aClass.getTextOffset(); - document.insertString(offset, "/**/"); + insertString(document, offset, "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = pointer.getElement(); @@ -241,7 +264,13 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { createPointer(aClass.getNameIdentifier()); final PsiComment javadoc = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createCommentFromText("/** javadoc */", aClass); - aClass.getParent().addBefore(javadoc, aClass); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + aClass.getParent().addBefore(javadoc, aClass); + } + }); + final PsiIdentifier elt = pointer.getElement(); assertNotNull(elt); @@ -259,8 +288,8 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Document testDocument = PsiDocumentManager.getInstance(myProject).getDocument(typeElement.getContainingFile()); assertNotSame(aClassDocument, testDocument); - aClassDocument.insertString(aClass.getTextOffset(), "/**/"); - testDocument.insertString(typeElement.getTextOffset(), "/**/"); + insertString(aClassDocument, aClass.getTextOffset(), "/**/"); + insertString(testDocument, typeElement.getTextOffset(), "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = typePointer.getElement(); @@ -291,7 +320,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster(); multicaster.addDocumentListener(listener); try { - document.insertString(offset, "/******/"); + insertString(document, offset, "/******/"); } finally { multicaster.removeDocumentListener(listener); @@ -299,7 +328,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { pointer[0].getElement(); - document.insertString(0, "/**/"); + insertString(document, 0, "/**/"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiElement element = pointer[0].getElement(); @@ -328,12 +357,12 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertNull(psiFile); */ - document.insertString(0, "class Foo{}\n"); + insertString(document, 0, "class Foo{}\n"); PsiElement element = pointer.getElement(); assertEquals(aClass, element); - document.insertString(0, "/**/"); + insertString(document, 0, "/**/"); psiDocumentManager.commitAllDocuments(); if (aClass.isValid()) { @@ -351,8 +380,8 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { } public void testReplaceFile() throws IOException { - VirtualFile vfile = myRoot.createChildData(this, "X.java"); - VfsUtil.saveText(vfile, "public class X { public int X; }"); + VirtualFile vfile = createChildData(myRoot, "X.java"); + setFileText(vfile, "public class X { public int X; }"); PsiClass aClass = myJavaFacade.findClass("X", GlobalSearchScope.allScope(getProject())); assertNotNull(aClass); @@ -379,8 +408,8 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { } public void testCreatePointerDoesNotLoadPsiTree() throws IOException { - VirtualFile vfile = myRoot.createChildData(this, "X.java"); - VfsUtil.saveText(vfile, "public class X { public int X; }"); + VirtualFile vfile = createChildData(myRoot, "X.java"); + setFileText(vfile, "public class X { public int X; }"); PsiClass aClass = myJavaFacade.findClass("X", GlobalSearchScope.allScope(getProject())); assertNotNull(aClass); @@ -401,7 +430,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); Document document = documentManager.getDocument(file); - document.insertString(0, "/** asdasd */"); + insertString(document, 0, "/** asdasd */"); documentManager.commitAllDocuments(); // loaded tree @@ -515,10 +544,10 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { } public void testSmartPointersSurvivePsiFileUnload() throws IOException { - final VirtualFile vfile = myRoot.createChildData(this, "X.txt"); + final VirtualFile vfile = createChildData(myRoot, "X.txt"); String xxx = "xxx"; String text = xxx + " " + xxx + " " + xxx; - VfsUtil.saveText(vfile, text); + setFileText(vfile, text); PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vfile); assertTrue(String.valueOf(psiFile), psiFile instanceof PsiPlainTextFile); SmartPointerManagerImpl manager = getPointerManager(); @@ -538,7 +567,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() { @Override public void run() { - FileDocumentManager.getInstance().getDocument(vfile).insertString(0, " "); + insertString(FileDocumentManager.getInstance().getDocument(vfile), 0, " "); } }); assertEquals(range1.shiftRight(1), pointer1.getRange()); @@ -568,7 +597,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { final SmartPsiElementPointer selectPointer = createPointer(select); WriteCommandAction.runWriteCommandAction(getProject(), () -> { - getEditor().getDocument().insertString(getEditor().getCaretModel().getOffset(), ""); + insertString(getEditor().getDocument(), getEditor().getCaretModel().getOffset(), ""); }); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); @@ -601,8 +630,8 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { WriteCommandAction.runWriteCommandAction(getProject(), () -> { int offset = getEditor().getCaretModel().getOffset(); - getEditor().getDocument().insertString(offset, "
    \n" + - "
\n"); + insertString(getEditor().getDocument(), offset, "
    \n" + + "
\n"); }); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); @@ -623,7 +652,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() { @Override public void run() { - getEditor().getDocument().insertString(0, "import java.util.Map;\n"); + insertString(getEditor().getDocument(), 0, "import java.util.Map;\n"); } }); @@ -677,13 +706,18 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { final Document document = file.getViewProvider().getDocument(); assertNotNull(document); - PlatformTestUtil.startPerformanceTest("smart pointer range update", 10000, () -> { - for (int i = 0; i < 10000; i++) { - document.insertString(i * 20 + 100, "x\n"); - assertFalse(PsiDocumentManager.getInstance(myProject).isCommitted(document)); - assertEquals(range, pointer.getRange()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PlatformTestUtil.startPerformanceTest("smart pointer range update", 10000, () -> { + for (int i = 0; i < 10000; i++) { + document.insertString(i * 20 + 100, "x\n"); + assertFalse(PsiDocumentManager.getInstance(myProject).isCommitted(document)); + assertEquals(range, pointer.getRange()); + } + }).cpuBound().useLegacyScaling().assertTiming(); } - }).cpuBound().useLegacyScaling().assertTiming(); + }); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals(range, pointer.getRange()); @@ -697,8 +731,14 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { SmartPsiFileRange range1 = getPointerManager().createSmartPsiFileRangePointer(myFile, TextRange.create(0, 2)); SmartPsiFileRange range2 = getPointerManager().createSmartPsiFileRangePointer(myFile, TextRange.create(1, 3)); - document.deleteString(0, 1); - document.deleteString(1, 2); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.deleteString(0, 1); + document.deleteString(1, 2); + } + }); + assertEquals(TextRange.create(0, 1), range1.getRange()); assertEquals(TextRange.create(0, 1), range2.getRange()); @@ -706,7 +746,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertEquals(TextRange.create(0, 1), range1.getRange()); assertEquals(TextRange.create(0, 1), range2.getRange()); - document.insertString(0, "a"); + insertString(document, 0, "a"); assertEquals(TextRange.create(1, 2), range1.getRange()); assertEquals(TextRange.create(1, 2), range2.getRange()); @@ -731,10 +771,12 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertNull(((SmartPointerEx) pointer2).getCachedElement()); TextRange range = file.getClasses()[1].getTextRange(); - document.moveText(range.getStartOffset(), range.getEndOffset(), 0); - - System.out.println(pointer1.getRange()); - System.out.println(pointer2.getRange()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.moveText(range.getStartOffset(), range.getEndOffset(), 0); + } + }); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); @@ -746,7 +788,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { PsiJavaFile file = (PsiJavaFile)myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject())).getContainingFile().copy(); SmartPsiFileRange pointer = getPointerManager().createSmartPsiFileRangePointer(file, TextRange.create(1, 2)); - file.getViewProvider().getDocument().insertString(0, " "); + insertString(file.getViewProvider().getDocument(), 0, " "); assertEquals(TextRange.create(2, 3), pointer.getRange()); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); @@ -762,8 +804,14 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { TextRange originalRange = method.getTextRange(); SmartPsiElementPointer pointer = createPointer(method); - EditorModificationUtil.insertStringAtCaret(myEditor, " void m() {\n" + - " }\n"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + EditorModificationUtil.insertStringAtCaret(myEditor, " void m() {\n" + + " }\n"); + } + }); + PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); PsiElement element = pointer.getElement(); assertNotNull(element); @@ -779,7 +827,13 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(((SmartPointerEx) pointer).getCachedElement()); - file.getClasses()[1].delete(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + file.getClasses()[1].delete(); + } + }); + assertNotNull(pointer.getElement()); } @@ -825,7 +879,14 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { assertNull(pointer.getCachedElement()); ref = PsiTreeUtil.findElementOfClassAtOffset(file, file.getText().indexOf("Bar"), PsiJavaCodeReferenceElement.class, false); - ref.handleElementRename("BarImpl"); + final PsiJavaCodeReferenceElement finalRef = ref; + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + finalRef.handleElementRename("BarImpl"); + } + }); + assertNotNull(pointer.getElement()); } @@ -843,7 +904,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(((SmartPointerEx) pointer).getCachedElement()); - file.getViewProvider().getDocument().insertString(0, " "); + insertString(file.getViewProvider().getDocument(), 0, " "); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertNotNull(pointer.getElement()); @@ -855,19 +916,24 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { List tags = ContainerUtil.newArrayList(PsiTreeUtil.findChildrenOfType(file.getDocument(), XmlTag.class)); List pointers = tags.stream().map(this::createPointer).collect(Collectors.toList()); Random random = new Random(); - PlatformTestUtil.startPerformanceTest("smart pointer range update after PSI change", 21000, () -> { - for (int i = 0; i < tags.size(); i++) { - XmlTag tag = tags.get(i); - SmartPsiElementPointer pointer = pointers.get(i); - assertEquals(tag.getName().length(), TextRange.create(pointer.getRange()).getLength()); - assertEquals(tag.getName().length(), TextRange.create(pointer.getPsiRange()).getLength()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PlatformTestUtil.startPerformanceTest("smart pointer range update after PSI change", 21000, () -> { + for (int i = 0; i < tags.size(); i++) { + XmlTag tag = tags.get(i); + SmartPsiElementPointer pointer = pointers.get(i); + assertEquals(tag.getName().length(), TextRange.create(pointer.getRange()).getLength()); + assertEquals(tag.getName().length(), TextRange.create(pointer.getPsiRange()).getLength()); - tag.setName("bar" + random.nextInt(20)); - assertEquals(tag.getName().length(), TextRange.create(pointer.getRange()).getLength()); - assertEquals(tag.getName().length(), TextRange.create(pointer.getPsiRange()).getLength()); + tag.setName("bar" + random.nextInt(20)); + assertEquals(tag.getName().length(), TextRange.create(pointer.getRange()).getLength()); + assertEquals(tag.getName().length(), TextRange.create(pointer.getPsiRange()).getLength()); + } + PostprocessReformattingAspect.getInstance(myProject).doPostponedFormatting(); + }).cpuBound().useLegacyScaling().assertTiming(); } - PostprocessReformattingAspect.getInstance(myProject).doPostponedFormatting(); - }).cpuBound().useLegacyScaling().assertTiming(); + }); } @NotNull diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/BindToElementTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/BindToElementTest.java index c926afd5af8c..73e0e9828ae2 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/BindToElementTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/BindToElementTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.psi.impl.source.tree.java; import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.util.Computable; @@ -60,12 +61,17 @@ public class BindToElementTest extends CodeInsightTestCase { final PsiJavaCodeReferenceElement referenceElement = PsiTreeUtil.getParentOfType(element, PsiJavaCodeReferenceElement.class); final PsiClass aClassA = JavaPsiFacade.getInstance(myProject).findClass("p2.A", GlobalSearchScope.moduleScope(myModule)); assertNotNull(aClassA); - try { - referenceElement.bindToElement(aClassA); - } - catch (IncorrectOperationException e) { - LOG.error(e); - } + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + try { + referenceElement.bindToElement(aClassA); + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + }); } }); } @@ -80,12 +86,17 @@ public class BindToElementTest extends CodeInsightTestCase { assertNotNull(aClassA); final PsiElementFactory factory = myJavaFacade.getElementFactory(); final PsiClassType type = factory.createType(aClassA); - try { - typeElement.replace(factory.createTypeElement(type)); - } - catch (IncorrectOperationException e) { - LOG.error(e); - } + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + try { + typeElement.replace(factory.createTypeElement(type)); + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + }); } }); } diff --git a/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java b/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java index 4c24cef46b6a..48c397e7075c 100644 --- a/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import com.intellij.JavaTestUtil; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.ide.impl.ProjectUtil; import com.intellij.ide.todo.TodoConfiguration; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -29,7 +31,6 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.JavaPsiFacadeEx; @@ -88,7 +89,14 @@ public class UpdateCacheTest extends PsiTestCase { PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0]; PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("New.java", JavaFileType.INSTANCE, "class A{ Object o;}"); - file = (PsiFile)root.add(file); + final PsiFile finalFile = file; + file = new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + PsiFile res = (PsiFile)root.add(finalFile); + result.setResult(res); + } + }.execute().throwException().getResultObject(); assertNotNull(file); PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject())); @@ -115,7 +123,7 @@ public class UpdateCacheTest extends PsiTestCase { VirtualFile file = root.findChild("1.java"); assertNotNull(file); - file.delete(null); + delete(file); PsiClass stringClass = myJavaFacade.findClass("java.lang.String", GlobalSearchScope.allScope(getProject())); assertNotNull(stringClass); @@ -127,7 +135,7 @@ public class UpdateCacheTest extends PsiTestCase { VirtualFile file = root.findChild("1.java"); assertNotNull(file); - VfsUtil.saveText(file, "class A{ Object o;}"); + setFileText(file, "class A{ Object o;}"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject())); @@ -135,11 +143,6 @@ public class UpdateCacheTest extends PsiTestCase { checkUsages(objectClass, new String[]{"1.java"}); } - @Override - protected boolean isRunInWriteAction() { - return !getTestName(false).equals("ExternalFileModificationWhileProjectClosed"); - } - public void testExternalFileModificationWhileProjectClosed() throws Exception { VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0]; @@ -207,7 +210,7 @@ public class UpdateCacheTest extends PsiTestCase { VirtualFile file = root.findChild("aDir"); assertNotNull(file); - file.delete(null); + delete(file); PsiClass threadClass = myJavaFacade.findClass("java.lang.Thread", GlobalSearchScope.allScope(getProject())); assertNotNull(threadClass); @@ -242,8 +245,8 @@ public class UpdateCacheTest extends PsiTestCase { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { - VirtualFile newFile = dir.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(dir, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); @@ -270,8 +273,8 @@ public class UpdateCacheTest extends PsiTestCase { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { - VirtualFile newFile = dir.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(dir, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); @@ -297,8 +300,8 @@ public class UpdateCacheTest extends PsiTestCase { protected void run() throws Throwable { PsiTestUtil.addContentRoot(myModule, root); - VirtualFile newFile = root.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(root, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); @@ -322,8 +325,8 @@ public class UpdateCacheTest extends PsiTestCase { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { - VirtualFile newFile = root.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(root, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); @@ -354,8 +357,8 @@ public class UpdateCacheTest extends PsiTestCase { protected void run() throws Throwable { PsiTestUtil.addSourceRoot(myModule, root); - VirtualFile newFile = root.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(root, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); @@ -389,8 +392,8 @@ public class UpdateCacheTest extends PsiTestCase { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { - VirtualFile newFile = root.createChildData(null, "New.java"); - VfsUtil.saveText(newFile, "class A{ Exception e;} //todo"); + VirtualFile newFile = createChildData(root, "New.java"); + setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java index 3e8fc36b0139..04237cfa2843 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.refactoring; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.Computable; @@ -114,11 +115,23 @@ public class CopyClassTest extends CodeInsightTestCase { } final VirtualFile targetVDir = rootDir.findChild("p2"); - CopyClassesHandler.doCopyClasses(map, null, myPsiManager.findDirectory(targetVDir), myProject); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + CopyClassesHandler.doCopyClasses(map, null, myPsiManager.findDirectory(targetVDir), myProject); + } + }); + String rootAfter = root + "/after"; VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/')); - myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); + } + }); + PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RefactoringTestCase.java b/java/java-tests/testSrc/com/intellij/refactoring/RefactoringTestCase.java index 62e902792dc3..3d9e41d92ca4 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RefactoringTestCase.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RefactoringTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,4 @@ package com.intellij.refactoring; import com.intellij.codeInsight.CodeInsightTestCase; public abstract class RefactoringTestCase extends CodeInsightTestCase { - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootFoldersTest.java b/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootFoldersTest.java index 6f73584181c8..85f092a85041 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootFoldersTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootFoldersTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.roots; import com.intellij.openapi.application.ApplicationManager; @@ -10,6 +25,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -56,39 +72,39 @@ public class ManagingContentRootFoldersTest extends IdeaTestCase { } public void testCreationOfSourceFolderWithFile() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); ContentFolder f = entry.addSourceFolder(dir, false); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); - dir.delete(null); + delete(dir); assertNull(f.getFile()); assertEquals(url, f.getUrl()); - dir = root.createChildDirectory(null, "src"); + dir = createSrc(); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); } public void testCreationOfSourceFolderWithUrl() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); - dir.delete(null); + delete(dir); ContentFolder f = entry.addSourceFolder(url, false); assertNull(f.getFile()); assertEquals(url, f.getUrl()); - dir = root.createChildDirectory(null, "src"); + dir = createSrc(); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); } public void testCreationOfSourceFolderWithUrlWhenFileExists() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); ContentFolder f = entry.addSourceFolder(url, false); @@ -97,38 +113,43 @@ public class ManagingContentRootFoldersTest extends IdeaTestCase { } public void testCreationOfExcludedFolderWithFile() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); ContentFolder f = entry.addExcludeFolder(dir); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); - dir.delete(null); + delete(dir); assertNull(f.getFile()); assertEquals(url, f.getUrl()); - dir = root.createChildDirectory(null, "src"); + dir = createSrc(); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); } + @NotNull + private VirtualFile createSrc() throws IOException { + return createChildDirectory(root, "src"); + } + public void testCreationOfExcludedFolderWithUrl() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); - dir.delete(null); + delete(dir); ContentFolder f = entry.addExcludeFolder(url); assertNull(f.getFile()); assertEquals(url, f.getUrl()); - dir = root.createChildDirectory(null, "src"); + dir = createSrc(); assertEquals(dir, f.getFile()); assertEquals(url, f.getUrl()); } public void testCreationOfExcludedFolderWithUrlWhenFileExists() throws IOException { - VirtualFile dir = root.createChildDirectory(null, "src"); + VirtualFile dir = createSrc(); String url = dir.getUrl(); ContentFolder f = entry.addExcludeFolder(url); diff --git a/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootsTest.java b/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootsTest.java index 83ebb21e4d5a..55eb753c07b2 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootsTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ManagingContentRootsTest.java @@ -43,7 +43,7 @@ public class ManagingContentRootsTest extends IdeaTestCase { } public void testCreationOfContentRootWithFile() throws IOException { - VirtualFile root = dir.createChildDirectory(null, "root"); + VirtualFile root = createChildDirectory(dir, "root"); String url = root.getUrl(); PsiTestUtil.addContentRoot(myModule, root); @@ -51,29 +51,29 @@ public class ManagingContentRootsTest extends IdeaTestCase { assertEquals(root, findContentEntry(url).getFile()); - root.delete(null); + delete(root); assertNotNull(findContentEntry(url)); - root = dir.createChildDirectory(null, "root"); + root = createChildDirectory(dir, "root"); assertEquals(root, findContentEntry(url).getFile()); } public void testCreationOfContentRootWithUrl() throws IOException { - VirtualFile root = dir.createChildDirectory(null, "root"); + VirtualFile root = createChildDirectory(dir, "root"); String url = root.getUrl(); String path = root.getPath(); - root.delete(null); + delete(root); addContentRoot(path); assertNotNull(findContentEntry(url)); - root = dir.createChildDirectory(null, "root"); + root = createChildDirectory(dir, "root"); assertEquals(root, findContentEntry(url).getFile()); } public void testCreationOfContentRootWithUrlWhenFileExists() throws IOException { - VirtualFile root = dir.createChildDirectory(null, "root"); + VirtualFile root = createChildDirectory(dir, "root"); addContentRoot(root.getPath()); assertEquals(root, findContentEntry(root.getUrl()).getFile()); } diff --git a/java/java-tests/testSrc/com/intellij/roots/ModuleRootManagerTestCase.java b/java/java-tests/testSrc/com/intellij/roots/ModuleRootManagerTestCase.java index a9473a4393bf..adfa0b344187 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ModuleRootManagerTestCase.java +++ b/java/java-tests/testSrc/com/intellij/roots/ModuleRootManagerTestCase.java @@ -1,5 +1,21 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.roots; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; @@ -7,6 +23,7 @@ import com.intellij.openapi.projectRoots.SdkModificator; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.IdeaTestUtil; @@ -96,16 +113,21 @@ public abstract class ModuleRootManagerTestCase extends ModuleTestCase { } protected Library createLibrary(final String name, final @Nullable VirtualFile classesRoot, final @Nullable VirtualFile sourceRoot) { - final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).createLibrary(name); - final Library.ModifiableModel model = library.getModifiableModel(); - if (classesRoot != null) { - model.addRoot(classesRoot, OrderRootType.CLASSES); - } - if (sourceRoot != null) { - model.addRoot(sourceRoot, OrderRootType.SOURCES); - } - model.commit(); - return library; + return ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public Library compute() { + final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).createLibrary(name); + final Library.ModifiableModel model = library.getModifiableModel(); + if (classesRoot != null) { + model.addRoot(classesRoot, OrderRootType.CLASSES); + } + if (sourceRoot != null) { + model.addRoot(sourceRoot, OrderRootType.SOURCES); + } + model.commit(); + return library; + } + }); } protected Library createJDomLibrary() { diff --git a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java index 6b0c06f3b6a1..ba5715407ecf 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.module.impl.ModuleEx; import com.intellij.openapi.module.impl.scopes.LibraryScope; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.DependencyScope; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.ModuleRootModificationUtil; +import com.intellij.openapi.roots.OrderEnumerator; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; @@ -139,7 +142,7 @@ public class ModuleScopesTest extends ModuleTestCase { VirtualFile root = myFixture.findOrCreateDir("c"); PsiTestUtil.addSourceContentToRoots(c, root); - VirtualFile file = root.createChildData(this, "x.txt"); + VirtualFile file = createChildData(root, "x.txt"); GlobalSearchScope deps = m.getModuleWithDependentsScope(); assertTrue(deps.contains(file)); @@ -164,7 +167,7 @@ public class ModuleScopesTest extends ModuleTestCase { PsiTestUtil.addSourceContentToRoots(b, bRoot); VirtualFile cRoot = myFixture.findOrCreateDir("c"); PsiTestUtil.addSourceContentToRoots(c, cRoot); - VirtualFile file = cRoot.createChildData(this, "x.txt"); + VirtualFile file = createChildData(cRoot, "x.txt"); GlobalSearchScope deps = c.getModuleContentWithDependenciesScope(); assertTrue(deps.contains(file)); @@ -278,7 +281,7 @@ public class ModuleScopesTest extends ModuleTestCase { VirtualFile lib = myFixture.findOrCreateDir("lib"); PsiTestUtil.addContentRoot(myModule, lib); - VirtualFile file = lib.createChildData(this, "a.txt"); + VirtualFile file = createChildData(lib, "a.txt"); addLibrary(myModule, DependencyScope.COMPILE); assertTrue(myModule.getModuleWithDependenciesAndLibrariesScope(false).contains(file)); } diff --git a/java/java-tests/testSrc/com/intellij/roots/MultiModuleEditingTest.java b/java/java-tests/testSrc/com/intellij/roots/MultiModuleEditingTest.java index b8ebc68165c4..6d7205e93613 100644 --- a/java/java-tests/testSrc/com/intellij/roots/MultiModuleEditingTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/MultiModuleEditingTest.java @@ -170,7 +170,12 @@ public class MultiModuleEditingTest extends ModuleTestCase { assertSame(moduleA, moduleManager.findModuleByName("a")); assertEquals("c", moduleModel.getNewName(moduleA)); assertSame(moduleA, moduleModel.getModuleToBeRenamed("c")); - moduleModel.commit(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + moduleModel.commit(); + } + }); } assertEquals(1, rootManagerB.getDependencies().length); diff --git a/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java b/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java index 813f0ae57b85..28de3f097ae1 100644 --- a/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java @@ -54,11 +54,6 @@ public class RootsChangedTest extends ModuleTestCase { connection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener); } - @Override - protected boolean isRunInWriteAction() { - return false; - } - public void testEventsAfterFileModifications() throws Exception { File root = new File(FileUtil.getTempDirectory()); diff --git a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java index acb9fd900ff2..a201aa06bbc2 100644 --- a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java @@ -1,14 +1,33 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.roots.libraries; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.NativeLibraryOrderRootType; +import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.roots.ModuleRootManagerTestCase; @@ -27,7 +46,12 @@ import java.util.Collections; public class LibraryTest extends ModuleRootManagerTestCase { public void testModification() throws Exception { final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(); - final Library library = libraryTable.createLibrary("NewLibrary"); + final Library library = ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public Library compute() { + return libraryTable.createLibrary("NewLibrary"); + } + }); final boolean[] listenerNotifiedOnChange = new boolean[1]; library.getRootProvider().addRootSetChangedListener(wrapper -> listenerNotifiedOnChange[0] = true); final Library.ModifiableModel model1 = library.getModifiableModel(); @@ -83,10 +107,19 @@ public class LibraryTest extends ModuleRootManagerTestCase { assertNull(model.getLibraryByName("a")); assertSame(a, table.getLibraryByName("b")); assertSame(a, model.getLibraryByName("b")); - model.commit(); + commit(model); assertSame(a, table.getLibraryByName("b")); } + private static void commit(LibraryTable.ModifiableModel model) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + model.commit(); + } + }); + } + public void testFindLibraryByNameAfterChainedRename() { Library a = createLibrary("a", null, null); Library b = createLibrary("b", null, null); @@ -140,7 +173,13 @@ public class LibraryTest extends ModuleRootManagerTestCase { public void testNativePathSerialization() { LibraryTable table = getLibraryTable(); - Library library = table.createLibrary("native"); + Library library = new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + Library res = table.createLibrary("native"); + result.setResult(res); + } + }.execute().throwException().getResultObject(); Library.ModifiableModel model = library.getModifiableModel(); model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance()); commit(model); @@ -160,7 +199,12 @@ public class LibraryTest extends ModuleRootManagerTestCase { public void testJarDirectoriesSerialization() { LibraryTable table = getLibraryTable(); - Library library = table.createLibrary("jarDirs"); + Library library = ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public Library compute() { + return table.createLibrary("jarDirs"); + } + }); Library.ModifiableModel model = library.getModifiableModel(); model.addJarDirectory("file://jar-dir", false, OrderRootType.CLASSES); model.addJarDirectory("file://jar-dir-src", false, OrderRootType.SOURCES); diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index 3c8218430e49..e7132dac9283 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -95,11 +95,6 @@ import java.util.List; public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { private VirtualFileFilter myVirtualFileFilter = new FileTreeAccessFilter(); - @Override - protected boolean isRunInWriteAction() { - return false; - } - @Override protected void setUp() throws Exception { super.setUp(); diff --git a/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java b/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java index fc43f57f4c4b..07337ad327aa 100644 --- a/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java +++ b/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,8 +183,14 @@ public abstract class ProjectWizardTestCase ext }); } - protected void addSdk(Sdk sdk) { - ProjectJdkTable.getInstance().addJdk(sdk); + protected void addSdk(final Sdk sdk) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + ProjectJdkTable.getInstance().addJdk(sdk); + } + }); + mySdks.add(sdk); } diff --git a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java index 7df52e431252..5a8ac4917ef4 100644 --- a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java +++ b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,8 +108,4 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { return PathManagerEx.getTestDataPath(getClass()); } - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java b/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java index 7f2716e8179e..dbefed374e42 100644 --- a/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java +++ b/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,9 +88,4 @@ public abstract class MultiFileTestCase extends CodeInsightTestCase { protected interface PerformAction { void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception; } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java index 633fac53c170..581b96838ac2 100644 --- a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java @@ -247,9 +247,4 @@ public abstract class InspectionTestCase extends PsiTestCase { protected String getTestDataPath() { return PathManagerEx.getTestDataPath() + "/inspection/"; } - - @Override - protected final boolean isRunInWriteAction() { - return false; - } } diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java index 476f584e86f0..ca5b57bf7b7d 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java @@ -62,15 +62,11 @@ public abstract class PsiTestCase extends ModuleTestCase { @Override protected void tearDown() throws Exception { - try { - myPsiManager = null; - myFile = null; - myTestDataBefore = null; - myTestDataAfter = null; - } - finally { - super.tearDown(); - } + myPsiManager = null; + myFile = null; + myTestDataBefore = null; + myTestDataAfter = null; + super.tearDown(); } @NotNull diff --git a/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java b/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java index 941b34cf29ea..fda285d09b8c 100644 --- a/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.testFramework; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -69,7 +70,14 @@ public abstract class ResolveTestCase extends PsiTestCase { if (existing != null) { myDocument = FileDocumentManager.getInstance().getDocument(existing); assertNotNull(myDocument); - myDocument.setText(fileText); + final String finalFileText = fileText; + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + myDocument.setText(finalFileText); + } + }); + myFile = PsiManager.getInstance(getProject()).findFile(existing); assertNotNull(myFile); assertEquals(fileText, myFile.getText()); diff --git a/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java b/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java index 339d070f4762..75e15173fe26 100644 --- a/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java @@ -40,17 +40,6 @@ import java.util.concurrent.atomic.AtomicReference; public class JobUtilTest extends PlatformTestCase { private static final AtomicInteger COUNT = new AtomicInteger(); - //@Override - //protected void setUp() throws Exception { - // super.setUp(); - // ((ApplicationImpl)ApplicationManager.getApplication()).stopMeasuringWriteActionPauses(myTestRootDisposable); - //} - // - @Override - protected boolean isRunInWriteAction() { - return false; - } - public void testUnbalancedTaskJobUtilPerformance() { List things = new ArrayList(Collections.nCopies(10000, null)); int sum = 0; diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java index 5ed58dc18ced..63fd088de00f 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,9 @@ package com.intellij.history.integration; import com.intellij.history.LocalHistory; import com.intellij.history.core.revisions.Revision; import com.intellij.history.utils.RunnableAdapter; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -36,20 +38,26 @@ public class BasicsTest extends IntegrationTestCase { public void testProcessingCommands() throws Exception { final VirtualFile[] f = new VirtualFile[1]; - CommandProcessor.getInstance().executeCommand(myProject, new RunnableAdapter() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override - public void doRun() throws IOException { - f[0] = myRoot.createChildData(null, "f1.txt"); - f[0].setBinaryContent(new byte[]{1}); - f[0].setBinaryContent(new byte[]{2}); + public void run() { + CommandProcessor.getInstance().executeCommand(myProject, new RunnableAdapter() { + @Override + public void doRun() throws IOException { + f[0] = createChildData(myRoot, "f1.txt"); + f[0].setBinaryContent(new byte[]{1}); + f[0].setBinaryContent(new byte[]{2}); + } + }, "name", null); } - }, "name", null); + }); + assertEquals(2, getRevisionsFor(f[0]).size()); } public void testPuttingUserLabel() throws Exception { - VirtualFile f = myRoot.createChildData(null, "f.txt"); + VirtualFile f = createChildData(myRoot, "f.txt"); LocalHistory.getInstance().putUserLabel(myProject, "global"); @@ -67,7 +75,7 @@ public class BasicsTest extends IntegrationTestCase { } public void testPuttingSystemLabel() throws IOException { - VirtualFile f = myRoot.createChildData(null, "file.txt"); + VirtualFile f = createChildData(myRoot, "file.txt"); assertEquals(2, getRevisionsFor(f).size()); assertEquals(2, getRevisionsFor(myRoot).size()); @@ -84,7 +92,7 @@ public class BasicsTest extends IntegrationTestCase { } public void testPuttingLabelWithUnsavedDocuments() throws Exception { - VirtualFile f = myRoot.createChildData(null, "f.txt"); + VirtualFile f = createChildData(myRoot, "f.txt"); setContent(f, "1"); setDocumentTextFor(f, "2"); @@ -109,7 +117,7 @@ public class BasicsTest extends IntegrationTestCase { } public void testDoNotRegisterSameUnsavedDocumentContentTwice() throws Exception { - VirtualFile f = myRoot.createChildData(null, "f.txt"); + VirtualFile f = createChildData(myRoot, "f.txt"); setContent(f, "1"); setDocumentTextFor(f, "2"); @@ -126,8 +134,8 @@ public class BasicsTest extends IntegrationTestCase { } public void testIsUnderControl() throws Exception { - VirtualFile f1 = myRoot.createChildData(null, "file.txt"); - VirtualFile f2 = myRoot.createChildData(null, "file.hprof"); + VirtualFile f1 = createChildData(myRoot, "file.txt"); + VirtualFile f2 = createChildData(myRoot, "file.hprof"); assertTrue(LocalHistory.getInstance().isUnderControl(f1)); assertFalse(LocalHistory.getInstance().isUnderControl(f2)); @@ -135,12 +143,18 @@ public class BasicsTest extends IntegrationTestCase { public void testDoNotRegisterChangesNotInLocalFS() throws Exception { File f = new File(myRoot.getPath(), "f.jar"); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { JarOutputStream jar = new JarOutputStream(new FileOutputStream(f)); jar.putNextEntry(new JarEntry("file.txt")); jar.write(1); jar.closeEntry(); jar.close(); + return null; + } + }); VirtualFile vfile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f); assertNotNull(vfile); @@ -150,15 +164,22 @@ public class BasicsTest extends IntegrationTestCase { assertEquals(2, getRevisionsFor(myRoot).size()); - jar = new JarOutputStream(new FileOutputStream(f)); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + JarOutputStream jar = new JarOutputStream(new FileOutputStream(f)); + + JarEntry e = new JarEntry("file.txt"); + e.setTime(f.lastModified() + 10000); + jar.putNextEntry(e); + jar.write(2); + jar.closeEntry(); + jar.close(); + f.setLastModified(f.lastModified() + 10000); + return null; + } + }); - JarEntry e = new JarEntry("file.txt"); - e.setTime(f.lastModified() + 10000); - jar.putNextEntry(e); - jar.write(2); - jar.closeEntry(); - jar.close(); - f.setLastModified(f.lastModified() + 10000); LocalFileSystem.getInstance().refreshWithoutFileWatcher(false); JarFileSystem.getInstance().refreshWithoutFileWatcher(false); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java index 0ec801c52a9c..006ef34a0660 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java @@ -147,7 +147,7 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase { public void testDeletionOfFilteredDirectoryExternallyDoesNotThrowExceptionDuringRefresh() throws Exception { int before = getRevisionsFor(myRoot).size(); - myRoot.createChildDirectory(this, FILTERED_DIR_NAME); + createChildDirectory(myRoot, FILTERED_DIR_NAME); String path = Paths.appended(myRoot.getPath(), FILTERED_DIR_NAME); FileUtil.delete(new File(path)); @@ -171,7 +171,7 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase { addExcludedDir(classesPath); final VirtualFile classesDir = LocalFileSystem.getInstance().findFileByPath(classesPath); assertNotNull(classesDir); - classesDir.getParent().delete(this); + delete(classesDir.getParent()); FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target")); VirtualFileManager.getInstance().syncRefresh(); // shouldn't throw diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java index 4af406c46352..28b99bf02678 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,9 @@ import com.intellij.history.core.changes.StructuralChange; import com.intellij.history.core.revisions.Revision; import com.intellij.history.core.tree.Entry; import com.intellij.history.utils.RunnableAdapter; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; @@ -119,10 +121,10 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile("file.txt"); assertEquals(2, getRevisionsFor(f).size()); - f.setBinaryContent(new byte[]{1}); + setBinaryContent(f,new byte[]{1}); assertEquals(3, getRevisionsFor(f).size()); - f.setBinaryContent(new byte[]{2}); + setBinaryContent(f,new byte[]{2}); assertEquals(4, getRevisionsFor(f).size()); } @@ -130,7 +132,7 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile("file.txt"); assertEquals(2, getRevisionsFor(f).size()); - f.rename(this, "file2.txt"); + rename(f, "file2.txt"); assertEquals(3, getRevisionsFor(f).size()); } @@ -155,7 +157,7 @@ public class FileListeningTest extends IntegrationTestCase { addFileListenerDuring(l, new RunnableAdapter() { @Override public void doRun() throws IOException { - f.rename(this, "new.txt"); + rename(f, "new.txt"); } }); @@ -169,7 +171,7 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile("file.hprof"); assertEquals(before, getRevisionsFor(myRoot).size()); - f.rename(this, "file.txt"); + rename(f, "file.txt"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); assertEquals(2, getRevisionsFor(f).size()); @@ -181,7 +183,7 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile("file.txt"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); - f.rename(this, "file.hprof"); + rename(f, "file.hprof"); assertEquals(before + 2, getRevisionsFor(myRoot).size()); } @@ -191,7 +193,7 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile(FILTERED_DIR_NAME); assertEquals(before, getRevisionsFor(myRoot).size()); - f.rename(this, "not_filtered"); + rename(f, "not_filtered"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); assertEquals(2, getRevisionsFor(f).size()); @@ -203,7 +205,7 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createDirectory("not_filtered"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); - f.rename(this, FILTERED_DIR_NAME); + rename(f, FILTERED_DIR_NAME); assertEquals(before + 2, getRevisionsFor(myRoot).size()); } @@ -211,10 +213,10 @@ public class FileListeningTest extends IntegrationTestCase { VirtualFile f = createFile("f.txt"); assertEquals(2, getRevisionsFor(f).size()); - ReadOnlyAttributeUtil.setReadOnlyAttribute(f, true); + setReadOnlyAttribute(f, true); assertEquals(3, getRevisionsFor(f).size()); - ReadOnlyAttributeUtil.setReadOnlyAttribute(f, false); + setReadOnlyAttribute(f, false); assertEquals(4, getRevisionsFor(f).size()); } @@ -222,17 +224,27 @@ public class FileListeningTest extends IntegrationTestCase { int before = getRevisionsFor(myRoot).size(); VirtualFile f = createFile("f.hprof"); - ReadOnlyAttributeUtil.setReadOnlyAttribute(f, true); // shouldn't throw + setReadOnlyAttribute(f, true); assertEquals(before, getRevisionsFor(myRoot).size()); } + private void setReadOnlyAttribute(VirtualFile f, boolean status) throws IOException { + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + ReadOnlyAttributeUtil.setReadOnlyAttribute(f, status); // shouldn't throw + return null; + } + }); + } + public void testDeletion() throws Exception { VirtualFile f = createDirectory("f.txt"); int before = getRevisionsFor(myRoot).size(); - f.delete(this); + delete(f); assertEquals(before + 1, getRevisionsFor(myRoot).size()); } @@ -240,7 +252,7 @@ public class FileListeningTest extends IntegrationTestCase { int before = getRevisionsFor(myRoot).size(); VirtualFile f = createDirectory(FILTERED_DIR_NAME); - f.delete(this); + delete(f); assertEquals(before, getRevisionsFor(myRoot).size()); } @@ -259,7 +271,7 @@ public class FileListeningTest extends IntegrationTestCase { final VirtualFile vDir1 = LocalFileSystem.getInstance().findFileByPath(dir1); assertNotNull(dir1, vDir1); - vDir1.delete(this); + delete(vDir1); List changes = getVcs().getChangeListInTests().getChangesInTests().get(0).getChanges(); assertEquals(1, changes.size()); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/GettingContentAtDateTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/GettingContentAtDateTest.java index 8ba94f744223..c4846103aad6 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/GettingContentAtDateTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/GettingContentAtDateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ public class GettingContentAtDateTest extends IntegrationTestCase { @Override protected void setUpInWriteAction() throws Exception { super.setUpInWriteAction(); - f = myRoot.createChildData(null, "f.txt"); + f = createChildData(myRoot, "f.txt"); } public void testContentAtDate() throws Exception { @@ -45,7 +45,7 @@ public class GettingContentAtDateTest extends IntegrationTestCase { } public void testContentAtDateForFilteredFilesIsNull() throws Exception { - VirtualFile f = myRoot.createChildData(null, "f.class"); + VirtualFile f = createChildData(myRoot, "f.class"); setContent(f, "1", 1111); assertContentAt(1111, null); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/IdeaGatewayTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/IdeaGatewayTest.java index bdded1c21007..d5b5f78a019a 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/IdeaGatewayTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/IdeaGatewayTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,13 @@ package com.intellij.history.integration; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.IOException; public class IdeaGatewayTest extends IntegrationTestCase { public void testFindingFile() throws Exception { @@ -27,14 +31,25 @@ public class IdeaGatewayTest extends IntegrationTestCase { } public void testGettingDirectory() throws Exception { - assertEquals(myRoot, myGateway.findOrCreateFileSafely(myRoot.getPath(), true)); + assertEquals(myRoot, findOrCreateFileSafely(myRoot.getPath())); + } + + @NotNull + private VirtualFile findOrCreateFileSafely(String path) throws IOException { + return ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public VirtualFile compute() throws IOException { + return myGateway.findOrCreateFileSafely(path, true); + } + }) + ; } public void testCreatingDirectory() throws Exception { String subSubDirPath = myRoot.getPath() + "/subDir/subSubDir"; assertFalse(new File(subSubDirPath).exists()); - VirtualFile subDir = myGateway.findOrCreateFileSafely(subSubDirPath, true); + VirtualFile subDir = findOrCreateFileSafely(subSubDirPath); assertNotNull(subDir); assertEquals(subSubDirPath, subDir.getPath()); @@ -46,9 +61,9 @@ public class IdeaGatewayTest extends IntegrationTestCase { String subSubDirPath = myRoot.getPath() + "/subDir/subSubDir"; assertFalse(new File(subSubDirPath).exists()); - myRoot.createChildData(this, "subDir"); + createChildData(myRoot, "subDir"); - VirtualFile subDir = myGateway.findOrCreateFileSafely(subSubDirPath, true); + VirtualFile subDir = findOrCreateFileSafely(subSubDirPath); assertNotNull(subDir); assertEquals(subSubDirPath, subDir.getPath()); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java b/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java index c13fc9ed5eb1..47009cf110f8 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java @@ -114,7 +114,7 @@ public abstract class IntegrationTestCase extends PlatformTestCase { } protected void setContent(VirtualFile f, String content, long timestamp) throws IOException { - f.setBinaryContent(content.getBytes(CharsetToolkit.UTF8_CHARSET), -1, timestamp); + setBinaryContent(f, content.getBytes(CharsetToolkit.UTF8_CHARSET), -1, timestamp,this); } protected String createFileExternally(String name) throws IOException { @@ -144,7 +144,12 @@ public abstract class IntegrationTestCase extends PlatformTestCase { protected void setDocumentTextFor(VirtualFile f, String text) { Document document = FileDocumentManager.getInstance().getDocument(f); assertNotNull(f.getPath(), document); - document.setText(text); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.setText(text); + } + }); } protected LocalHistoryFacade getVcs() { diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/PatchingTestCase.java b/platform/platform-tests/testSrc/com/intellij/history/integration/PatchingTestCase.java index 2f5e3b24039a..5c7ecdea6a1a 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/PatchingTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/PatchingTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public abstract class PatchingTestCase extends IntegrationTestCase { protected void clearRoot() throws IOException { for (VirtualFile f : myRoot.getChildren()) { - f.delete(null); + delete(f); } } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java index 53905cbe3aa7..158b45ea4b5d 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -162,7 +162,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testRevisionsForFileCreatedWithSameNameAsDeletedOne() throws IOException { VirtualFile f = createFile("file.txt", "old"); loadContent(f); - f.delete(this); + delete(f); f = createFile("file.txt", "new"); loadContent(f); @@ -184,7 +184,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testRevisionForDirectoryWithTheSameNameAsDeletedOne() throws IOException { VirtualFile dir = createDirectory("dir"); - dir.delete(this); + delete(dir); dir = createDirectory("dir"); List rr = getRevisionsFor(dir); @@ -194,7 +194,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testRevisionForRestoredDirectoryWithRestoreChildren() throws IOException { VirtualFile dir = createDirectory("dir"); createFile("dir/f.txt"); - dir.delete(this); + delete(dir); getVcs().beginChangeSet(); dir = createDirectory("dir"); @@ -215,11 +215,11 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { getVcs().beginChangeSet(); VirtualFile f = createFile("f.txt"); getVcs().endChangeSet("1"); - f.delete(this); + delete(f); getVcs().beginChangeSet(); f = createFile("f.txt"); - f.delete(this); + delete(f); getVcs().endChangeSet("2"); getVcs().beginChangeSet(); @@ -227,7 +227,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { getVcs().endChangeSet("3"); getVcs().beginChangeSet(); - f.delete(this); + delete(f); f = createFile("f.txt"); getVcs().endChangeSet("4"); @@ -243,7 +243,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testRevisionsForFileCreatedInPlaceOfRenamedOne() throws IOException { VirtualFile f = createFile("file1.txt", "content1"); loadContent(f); - f.rename("file1", "file2.txt"); + rename(f, "file2.txt"); VirtualFile ff = createFile("file1.txt", "content2"); loadContent(ff); @@ -270,7 +270,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { VirtualFile dir = createDirectory("dir"); VirtualFile f = createFile("dir/f.txt"); getVcs().beginChangeSet(); - f.delete(this); + delete(f); List rr = getRevisionsFor(dir); assertEquals(4, rr.size()); @@ -279,7 +279,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testGettingEntryFromRevisionInRenamedDir() throws IOException { VirtualFile dir = createDirectory("dir"); VirtualFile f = createFile("dir/file.txt"); - dir.rename("dir", "newDir"); + rename(dir, "newDir"); setContent(f, "xxx"); List rr = getRevisionsFor(f); @@ -329,7 +329,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testNoDifferenceForDirectoryWithEqualContents() throws IOException { VirtualFile dir = createDirectory("dir"); VirtualFile f = createFile("dir/file.txt"); - f.delete(this); + delete(f); List rr = getRevisionsFor(dir); @@ -383,7 +383,7 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { public void testDoNotIncludeLabelsWhenFileDidNotExist() throws Exception { VirtualFile f = createFile("foo.txt"); LocalHistory.getInstance().putSystemLabel(myProject, "1", -1); - f.delete(this); + delete(f); LocalHistory.getInstance().putSystemLabel(myProject, "2", -1); f = createFile("foo.txt"); LocalHistory.getInstance().putSystemLabel(myProject, "3", -1); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java index 41460bed03fa..97d17f3e4ef0 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ public class VisitingTest extends IntegrationTestCase { VirtualFile dir = createFile("dir"); getVcs().endChangeSet(null); getVcs().beginChangeSet(); - dir.rename(this, "newDir"); + rename(dir, "newDir"); assertVisitorLog("begin rename end begin create end begin create end finished "); } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/patches/PatchCreatorTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/patches/PatchCreatorTest.java index 15cb0b149988..31face320d81 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/patches/PatchCreatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/patches/PatchCreatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import java.util.List; public class PatchCreatorTest extends PatchingTestCase { public void testCreationPatch() throws Exception { - myRoot.createChildData(null, "f.txt"); + createChildData(myRoot, "f.txt"); createPatchBetweenRevisions(1, 0); clearRoot(); @@ -37,9 +37,9 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testPatchBetweenTwoOldRevisions() throws Exception { - myRoot.createChildData(null, "f1.txt"); - myRoot.createChildData(null, "f2.txt"); - myRoot.createChildData(null, "f3.txt"); + createChildData(myRoot, "f1.txt"); + createChildData(myRoot, "f2.txt"); + createChildData(myRoot, "f3.txt"); createPatchBetweenRevisions(3, 1); clearRoot(); @@ -51,13 +51,13 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testRename() throws Exception { - VirtualFile f = myRoot.createChildData(null, "f.txt"); - f.setBinaryContent(new byte[]{'x'}); + VirtualFile f = createChildData(myRoot, "f.txt"); + setBinaryContent(f,new byte[]{'x'}); - f.rename(null, "ff.txt"); + rename(f, "ff.txt"); createPatchBetweenRevisions(1, 0); - f.rename(null, "f.txt"); + rename(f, "f.txt"); applyPatch(); VirtualFile patched = myRoot.findChild("ff.txt"); @@ -67,7 +67,7 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testReversePatch() throws Exception { - myRoot.createChildData(null, "f.txt"); + createChildData(myRoot, "f.txt"); createPatchBetweenRevisions(1, 0, true); applyPatch(); @@ -76,8 +76,8 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testDirectoryCreationWithFiles() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(null, "dir"); - dir.createChildData(null, "f.txt"); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + createChildData(dir, "f.txt"); createPatchBetweenRevisions(2, 0, false); clearRoot(); @@ -89,16 +89,16 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testDirectoryDeletionWithFiles() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(null, "dir"); - dir.createChildData(null, "f1.txt"); - dir.createChildData(null, "f2.txt"); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + createChildData(dir, "f1.txt"); + createChildData(dir, "f2.txt"); - dir.delete(null); + delete(dir); createPatchBetweenRevisions(1, 0, false); - dir = myRoot.createChildDirectory(null, "dir"); - dir.createChildData(null, "f1.txt"); - dir.createChildData(null, "f2.txt"); + dir = createChildDirectory(myRoot, "dir"); + createChildData(dir, "f1.txt"); + createChildData(dir, "f2.txt"); applyPatch(); @@ -108,14 +108,14 @@ public class PatchCreatorTest extends PatchingTestCase { } public void testDirectoryRename() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(null, "dir1"); - dir.createChildData(null, "f.txt"); + VirtualFile dir = createChildDirectory(myRoot, "dir1"); + createChildData(dir, "f.txt"); - dir.rename(null, "dir2"); + rename(dir, "dir2"); createPatchBetweenRevisions(1, 0); - dir.rename(null, "dir1"); + rename(dir, "dir1"); applyPatch(); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/DifferenceReverterTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/DifferenceReverterTest.java index ee1b7c4fc4c7..8e8d7f5dfe69 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/DifferenceReverterTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/DifferenceReverterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import java.util.List; public class DifferenceReverterTest extends IntegrationTestCase { public void testFileCreation() throws Exception { - myRoot.createChildData(this, "foo.txt"); + createChildData(myRoot, "foo.txt"); revertLastChange(); @@ -35,9 +35,9 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testFileDeletion() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); - f.delete(this); + VirtualFile f = createChildData(myRoot, "foo.txt"); + setBinaryContent(f, new byte[]{123}, -1, 4000, this); + delete(f); revertLastChange(); @@ -48,12 +48,13 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testDirDeletion() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(this, "dir"); - VirtualFile subdir = dir.createChildDirectory(this, "subdir"); - VirtualFile f = subdir.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + VirtualFile subdir = createChildDirectory(dir, "subdir"); + VirtualFile f = createChildData(subdir, "foo.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{123}, modificationStamp, 4000, this); - dir.delete(this); + delete(dir); revertLastChange(); @@ -66,11 +67,11 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testDeletionOfFileAndCreationOfDirAtTheSameTime() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); + VirtualFile f = createChildData(myRoot, "foo.txt"); getVcs().beginChangeSet(); - f.delete(this); - myRoot.createChildDirectory(this, "foo.txt"); + delete(f); + createChildDirectory(myRoot, "foo.txt"); getVcs().endChangeSet(null); revertLastChange(); @@ -81,11 +82,11 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testDeletionOfDirAndCreationOfFileAtTheSameTime() throws Exception { - VirtualFile f = myRoot.createChildDirectory(this, "foo.txt"); + VirtualFile f = createChildDirectory(myRoot, "foo.txt"); getVcs().beginChangeSet(); - f.delete(this); - myRoot.createChildData(this, "foo.txt"); + delete(f); + createChildData(myRoot, "foo.txt"); getVcs().endChangeSet(null); revertLastChange(); @@ -96,9 +97,10 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRename() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); - f.rename(this, "bar.txt"); + VirtualFile f = createChildData(myRoot, "foo.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{123}, modificationStamp, 4000, this); + rename(f, "bar.txt"); revertLastChange(); @@ -110,13 +112,14 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testMovement() throws Exception { - VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1"); - VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2"); + VirtualFile dir1 = createChildDirectory(myRoot, "dir1"); + VirtualFile dir2 = createChildDirectory(myRoot, "dir2"); - VirtualFile f = dir1.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); + VirtualFile f = createChildData(dir1, "foo.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{123}, modificationStamp, 4000, this); - f.move(this, dir2); + move(f, dir2); revertLastChange(); @@ -128,11 +131,12 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testParentRename() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(this, "dir"); - VirtualFile f = dir.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + VirtualFile f = createChildData(dir, "foo.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{123}, modificationStamp, 4000, this); - dir.rename(this, "dir2"); + rename(dir, "dir2"); revertLastChange(); @@ -145,13 +149,14 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testParentAndChildRename() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(this, "dir"); - VirtualFile f = dir.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{123}, -1, 4000); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + VirtualFile f = createChildData(dir, "foo.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{123}, modificationStamp, 4000, this); getVcs().beginChangeSet(); - dir.rename(this, "dir2"); - f.rename(this, "bar.txt"); + rename(dir, "dir2"); + rename(f, "bar.txt"); getVcs().endChangeSet(null); revertLastChange(); @@ -167,9 +172,11 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertContentChange() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{1}, -1, 1000); - f.setBinaryContent(new byte[]{2}, -1, 2000); + VirtualFile f = createChildData(myRoot, "foo.txt"); + int modificationStamp1 = -1; + setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{2}, modificationStamp, 2000, this); revertLastChange(); @@ -180,15 +187,17 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testContentChangeWhenDirectoryExists() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.setBinaryContent(new byte[]{1}, -1, 1000); + VirtualFile f = createChildData(myRoot, "foo.txt"); + int modificationStamp1 = -1; + setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); getVcs().beginChangeSet(); - f.rename(this, "bar.txt"); - f.setBinaryContent(new byte[]{2}, -1, 2000); + rename(f, "bar.txt"); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{2}, modificationStamp, 2000, this); getVcs().endChangeSet(null); - myRoot.createChildDirectory(this, "foo.txt"); + createChildDirectory(myRoot, "foo.txt"); revertChange(1, 0, 1); @@ -201,8 +210,8 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertingFromOldRevisionsWhenFileAlreadyDeleted() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.delete(this); + VirtualFile f = createChildData(myRoot, "foo.txt"); + delete(f); revertChange(1); @@ -210,9 +219,9 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertingFromOldRevisionsWhenFileAlreadyExists() throws Exception { - VirtualFile f = myRoot.createChildData(this, "foo.txt"); - f.delete(this); - f = myRoot.createChildData(this, "foo.txt"); + VirtualFile f = createChildData(myRoot, "foo.txt"); + delete(f); + f = createChildData(myRoot, "foo.txt"); revertChange(1); @@ -220,12 +229,12 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertingRenameFromOldRevisionsWhenDirDoesNotExists() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(this, "dir"); - VirtualFile f = dir.createChildData(this, "foo.txt"); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + VirtualFile f = createChildData(dir, "foo.txt"); - f.rename(this, "bar.txt"); + rename(f, "bar.txt"); - dir.delete(this); + delete(dir); revertChange(1); @@ -236,14 +245,14 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertingMoveFromOldRevisionsWhenDirDoesNotExists() throws Exception { - VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1"); - VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2"); - VirtualFile f = dir1.createChildData(this, "foo.txt"); + VirtualFile dir1 = createChildDirectory(myRoot, "dir1"); + VirtualFile dir2 = createChildDirectory(myRoot, "dir2"); + VirtualFile f = createChildData(dir1, "foo.txt"); - f.move(this, dir2); + move(f, dir2); - dir1.delete(this); - dir2.delete(this); + delete(dir1); + delete(dir2); revertChange(2); @@ -254,13 +263,15 @@ public class DifferenceReverterTest extends IntegrationTestCase { } public void testRevertingContentChangeFromOldRevisionsWhenDirDoesNotExists() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(this, "dir"); - VirtualFile f = dir.createChildData(this, "foo.txt"); + VirtualFile dir = createChildDirectory(myRoot, "dir"); + VirtualFile f = createChildData(dir, "foo.txt"); - f.setBinaryContent(new byte[]{1}, -1, 1000); - f.setBinaryContent(new byte[]{2}, -1, 2000); + int modificationStamp1 = -1; + setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); + int modificationStamp = -1; + setBinaryContent(f, new byte[]{2}, modificationStamp, 2000, this); - dir.delete(this); + delete(dir); revertChange(1); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/SelectionReverterTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/SelectionReverterTest.java index 7cff8dfa5e49..a1e56cafe7ae 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/SelectionReverterTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/SelectionReverterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class SelectionReverterTest extends IntegrationTestCase { @Override protected void setUpInWriteAction() throws Exception { super.setUpInWriteAction(); - f = myRoot.createChildData(null, "f.txt"); + f = createChildData(myRoot, "f.txt"); } public void testBasics() throws IOException { @@ -54,8 +54,8 @@ public class SelectionReverterTest extends IntegrationTestCase { " public abstract bar();\n" + "}\n"; - f.setBinaryContent(before.getBytes()); - f.setBinaryContent(after.getBytes()); + setBinaryContent(f, before.getBytes()); + setBinaryContent(f, after.getBytes()); revertToPreviousRevision(2, 2); @@ -72,8 +72,8 @@ public class SelectionReverterTest extends IntegrationTestCase { long time = new Date(2001, 1, 11, 12, 30).getTime(); Clock.setTime(time); - f.setBinaryContent("one".getBytes()); - f.setBinaryContent("two".getBytes()); + setBinaryContent(f, "one".getBytes()); + setBinaryContent(f, "two".getBytes()); revertToPreviousRevision(0, 0); @@ -83,11 +83,11 @@ public class SelectionReverterTest extends IntegrationTestCase { } public void testAskingForReadOnlyStatusClearingOnlyForTheSpecifiedFile() throws Exception { - myRoot.createChildData(null, "foo1.txt"); - f.setBinaryContent("one".getBytes()); - myRoot.createChildData(null, "foo2.txt"); - f.setBinaryContent("two".getBytes()); - myRoot.createChildData(null, "foo3.txt"); + createChildData(myRoot, "foo1.txt"); + setBinaryContent(f, "one".getBytes()); + createChildData(myRoot, "foo2.txt"); + setBinaryContent(f, "two".getBytes()); + createChildData(myRoot, "foo3.txt"); final List files = new ArrayList(); myGateway = new IdeaGateway() { diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryChangeModelTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryChangeModelTest.java index 3423e48a6522..e01a009b6549 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryChangeModelTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryChangeModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import java.util.List; public class DirectoryChangeModelTest extends IntegrationTestCase { public void testNames() throws IOException { VirtualFile f = createDirectory("foo"); - f.rename(this, "bar"); + rename(f, "bar"); List revs = getRevisionsFor(f); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java index fb804506065c..f8758ee6f4b4 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ import com.intellij.history.integration.ui.models.DirectoryHistoryDialogModel; public class DirectoryHistoryDialogPatchCreationTest extends PatchingTestCase { public void testPatchCreation() throws Exception { - myRoot.createChildData(null, "f1.txt"); - myRoot.createChildData(null, "f2.txt"); - myRoot.createChildData(null, "f3.txt"); + createChildData(myRoot, "f1.txt"); + createChildData(myRoot, "f2.txt"); + createChildData(myRoot, "f3.txt"); DirectoryHistoryDialogModel m = new DirectoryHistoryDialogModel(myProject, myGateway, getVcs(), myRoot); assertSize(3, m.getRevisions()); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogTest.java index 130061b51b58..b8286c01f3e1 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ public class DirectoryHistoryDialogTest extends LocalHistoryUITestCase { } public void testRevertion() throws Exception { - myRoot.createChildData(null, "f.txt"); + createChildData(myRoot, "f.txt"); HistoryDialogModel m = createModelAndSelectRevision(0); m.createReverter().revert(); @@ -41,8 +41,8 @@ public class DirectoryHistoryDialogTest extends LocalHistoryUITestCase { } public void testSelectionRevertion() throws Exception { - myRoot.createChildData(null, "f1.txt"); - myRoot.createChildData(null, "f2.txt"); + createChildData(myRoot, "f1.txt"); + createChildData(myRoot, "f2.txt"); DirectoryHistoryDialogModel m = createModelAndSelectRevision(1); DirectoryChange c = (DirectoryChange)m.getChanges().get(0); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/FileHistoryDialogTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/FileHistoryDialogTest.java index 19680575a3b6..a3fe37d5b97e 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/FileHistoryDialogTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/FileHistoryDialogTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import java.util.Date; public class FileHistoryDialogTest extends LocalHistoryUITestCase { public void testDialogWorks() throws IOException { - VirtualFile file = myRoot.createChildData(null, "f.txt"); + VirtualFile file = createChildData(myRoot, "f.txt"); FileHistoryDialog d = new FileHistoryDialog(myProject, myGateway, file); Disposer.dispose(d); @@ -43,13 +43,14 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase { long leftTime = new Date(2001 - 1900, 1, 3, 12, 0).getTime(); long rightTime = new Date(2002 - 1900, 2, 4, 14, 0).getTime(); - VirtualFile f = myRoot.createChildData(null, "old.txt"); - f.setBinaryContent("old".getBytes(), -1, leftTime); + VirtualFile f = createChildData(myRoot, "old.txt"); + setBinaryContent(f, "old".getBytes(), -1, leftTime, this); - f.rename(null, "new.txt"); - f.setBinaryContent("new".getBytes(), -1, rightTime); + rename(f, "new.txt"); + setBinaryContent(f, "new".getBytes(), -1, rightTime, this); - f.setBinaryContent(new byte[0]); // to create current content to skip. + byte[] content = new byte[0]; + setBinaryContent(f, content); FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 2); assertEquals(FileUtil.toSystemDependentName(f.getPath()), m.getDifferenceModel().getTitle()); @@ -61,10 +62,10 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase { } public void testContent() throws IOException { - VirtualFile f = myRoot.createChildData(null, "f.txt"); - f.setBinaryContent("old".getBytes()); - f.setBinaryContent("new".getBytes()); - f.setBinaryContent("current".getBytes()); + VirtualFile f = createChildData(myRoot, "f.txt"); + setBinaryContent(f, "old".getBytes()); + setBinaryContent(f, "new".getBytes()); + setBinaryContent(f, "current".getBytes()); FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 1); @@ -72,9 +73,9 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase { } public void testContentWhenOnlyOneRevisionSelected() throws IOException { - VirtualFile f = myRoot.createChildData(null, "f.txt"); - f.setBinaryContent("old".getBytes()); - f.setBinaryContent("new".getBytes()); + VirtualFile f = createChildData(myRoot, "f.txt"); + setBinaryContent(f, "old".getBytes()); + setBinaryContent(f, "new".getBytes()); FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 0); @@ -82,9 +83,9 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase { } public void testContentForCurrentRevision() throws IOException { - VirtualFile f = myRoot.createChildData(null, "f.txt"); - f.setBinaryContent("old".getBytes()); - f.setBinaryContent("current".getBytes()); + VirtualFile f = createChildData(myRoot, "f.txt"); + setBinaryContent(f, "old".getBytes()); + setBinaryContent(f, "current".getBytes()); FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 0); @@ -93,10 +94,10 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase { } public void testRevertion() throws Exception { - VirtualFile dir = myRoot.createChildDirectory(null, "oldDir"); - VirtualFile f = dir.createChildData(null, "old.txt"); - f.rename(null, "new.txt"); - dir.rename(null, "newDir"); + VirtualFile dir = createChildDirectory(myRoot, "oldDir"); + VirtualFile f = createChildData(dir, "old.txt"); + rename(f, "new.txt"); + rename(dir, "newDir"); FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 1, 1); m.createReverter().revert(); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/LocalHistoryActionsTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/LocalHistoryActionsTest.java index 0e12b7ac2499..f3429f08bd0a 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/LocalHistoryActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/LocalHistoryActionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public class LocalHistoryActionsTest extends LocalHistoryUITestCase { @Override protected void setUpInWriteAction() throws Exception { super.setUpInWriteAction(); - f = myRoot.createChildData(null, "f.txt"); + f = createChildData(myRoot, "f.txt"); document = FileDocumentManager.getInstance().getDocument(f); document.setText("foo"); @@ -70,8 +70,8 @@ public class LocalHistoryActionsTest extends LocalHistoryUITestCase { assertStatus(a, f, true); assertStatus(a, null, false); - assertStatus(a, myRoot.createChildData(null, "f.hprof"), false); - assertStatus(a, myRoot.createChildData(null, "f.xxx"), false); + assertStatus(a, createChildData(myRoot, "f.hprof"), false); + assertStatus(a, createChildData(myRoot, "f.xxx"), false); } public void testLocalHistoryActionDisabledWithoutProject() throws IOException { diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/RecentChangeDialogTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/RecentChangeDialogTest.java index 0f4c9b55b681..e1bee21de8db 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/RecentChangeDialogTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/RecentChangeDialogTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import java.io.IOException; public class RecentChangeDialogTest extends LocalHistoryUITestCase { public void testDialogWork() throws IOException { getVcs().beginChangeSet(); - myRoot.createChildData(null, "f.txt"); + createChildData(myRoot, "f.txt"); getVcs().endChangeSet("change"); RecentChange c = getVcs().getRecentChanges(getRootEntry()).get(0); @@ -45,11 +45,11 @@ public class RecentChangeDialogTest extends LocalHistoryUITestCase { public void testRevertChange() throws IOException { getVcs().beginChangeSet(); - myRoot.createChildData(null, "f1.txt"); + createChildData(myRoot, "f1.txt"); getVcs().endChangeSet("change"); getVcs().beginChangeSet(); - myRoot.createChildData(null, "f2.txt"); + createChildData(myRoot, "f2.txt"); getVcs().endChangeSet("another change"); RecentChange c = getVcs().getRecentChanges(getRootEntry()).get(1); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/SelectionHistoryDialogTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/SelectionHistoryDialogTest.java index b97af0ef8787..40da69dc8ff3 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/SelectionHistoryDialogTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/SelectionHistoryDialogTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,10 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase { protected void setUpInWriteAction() throws Exception { super.setUpInWriteAction(); - f = myRoot.createChildData(null, "f.txt"); - f.setBinaryContent("a\nb\nc\n".getBytes(), -1, 123); - f.setBinaryContent("a\nbc\nd\n".getBytes(), -1, 456); - f.setBinaryContent("a\nbcd\ne\n".getBytes(), -1, 789); + f = createChildData(myRoot, "f.txt"); + setBinaryContent(f,"a\nb\nc\n".getBytes(), -1, 123,this); + setBinaryContent(f,"a\nbc\nd\n".getBytes(), -1, 456,this); + setBinaryContent(f,"a\nbcd\ne\n".getBytes(), -1, 789,this); } public void testDialogWorks() throws IOException { @@ -53,8 +53,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase { } public void testTitles() throws IOException { - f.rename(null, "ff.txt"); - f.setBinaryContent(new byte[0]); + rename(f, "ff.txt"); + setBinaryContent(f,new byte[0]); initModelOnSecondLineAndSelectRevisions(0, 1); @@ -107,7 +107,7 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase { public void testDiffForDeletedAndRecreatedFile() throws Exception { byte[] bytes = f.contentsToByteArray(); - f.delete(this); + delete(f); f = createFile(f.getName(), new String(bytes)); loadContent(f); diff --git a/platform/platform-tests/testSrc/com/intellij/module/ModulePointerTest.java b/platform/platform-tests/testSrc/com/intellij/module/ModulePointerTest.java index 3c6d090f0d8f..ca128cbaea0c 100644 --- a/platform/platform-tests/testSrc/com/intellij/module/ModulePointerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/module/ModulePointerTest.java @@ -16,6 +16,7 @@ package com.intellij.module; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.module.*; @@ -78,7 +79,13 @@ public class ModulePointerTest extends PlatformTestCase { assertSame(module, pointer.getModule()); assertEquals("xxx", pointer.getModuleName()); - modifiableModel.dispose(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + modifiableModel.dispose(); + } + }); + assertNull(pointer.getModule()); assertEquals("xxx", pointer.getModuleName()); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileDocumentManagerImplTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileDocumentManagerImplTest.java index dfb55e42b474..f8ddecb1c543 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileDocumentManagerImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileDocumentManagerImplTest.java @@ -90,7 +90,14 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { public void testGetDocument_CreateNew_ReadOnly() throws Exception { final VirtualFile file = createFile(); - file.setWritable(false); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + file.setWritable(false); + return null; + } + }); + final Document document = myDocumentManager.getDocument(file); assertNotNull(document); assertEquals("test", document.getText()); @@ -221,7 +228,12 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { assertEquals("test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET)); } finally { - myDocumentManager.dropAllUnsavedDocuments(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + myDocumentManager.dropAllUnsavedDocuments(); + } + }); } } @@ -347,27 +359,24 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { public void testContentChanged_noDocument() throws Exception { final VirtualFile file = createFile(); - setContent(file, "xxx"); + setFileText(file, "xxx"); assertNull(myDocumentManager.getCachedDocument(file)); } - VirtualFile createFile(String name, String content) throws IOException { + private VirtualFile createFile(String name, String content) throws IOException { File file = createTempFile(name, content); VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file); assertNotNull(virtualFile); return virtualFile; } - VirtualFile createFile() throws IOException { + private VirtualFile createFile() throws IOException { return createFile("test.txt", "test"); } - void setContent(VirtualFile file, String content) throws IOException { - file.setBinaryContent(content.getBytes(CharsetToolkit.UTF8_CHARSET)); - } public void testContentChanged_documentPresent() throws Exception { VirtualFile file = createFile(); Document document = myDocumentManager.getDocument(file); - setContent(file, "xxx"); + setFileText(file, "xxx"); assertNotNull(file.toString(), document); assertEquals("xxx", document.getText()); assertEquals(file.getModificationStamp(), document.getModificationStamp()); @@ -376,7 +385,8 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { public void testContentChanged_ignoreEventsFromSelf() throws Exception { final VirtualFile file = createFile("test.txt", "test\rtest"); Document document = myDocumentManager.getDocument(file); - file.setBinaryContent("xxx".getBytes(CharsetToolkit.UTF8_CHARSET), -1,-1,myDocumentManager); + setBinaryContent(file, "xxx".getBytes(CharsetToolkit.UTF8_CHARSET), -1, -1, myDocumentManager); + assertNotNull(file.toString(), document); assertEquals("test\ntest", document.getText()); } @@ -427,7 +437,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { myReloadFromDisk = Boolean.TRUE; - setContent(file, "xxx"); + setFileText(file, "xxx"); assertEquals("xxx", document.getText()); assertEquals(file.getModificationStamp(), document.getModificationStamp()); @@ -448,7 +458,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase { myReloadFromDisk = Boolean.FALSE; long oldDocumentStamp = document.getModificationStamp(); - file.setBinaryContent("xxx".getBytes(CharsetToolkit.UTF8_CHARSET)); + setBinaryContent(file, "xxx".getBytes(CharsetToolkit.UTF8_CHARSET)); assertEquals("old test", document.getText()); assertEquals(oldDocumentStamp, document.getModificationStamp()); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java index 33217625a15e..92fbef4851a5 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java @@ -615,9 +615,4 @@ public class FileTypesTest extends PlatformTestCase { myFileTypeManager.toLog = false; } } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java index 7ecb5b89446f..1f6002226629 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java @@ -80,11 +80,6 @@ public class VirtualFilePointerTest extends PlatformTestCase { } } - @Override - protected boolean isRunInWriteAction() { - return false; - } - private static class LoggingListener implements VirtualFilePointerListener { private final ArrayList myLog = new ArrayList<>(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index 1ab833558823..aa77d48665f7 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileAttributes; import com.intellij.openapi.util.io.FileSystemUtil; import com.intellij.openapi.util.io.FileUtil; @@ -160,11 +161,11 @@ public class LocalFileSystemTest extends PlatformTestCase { VirtualFile toVDir = myFS.findFileByPath(toDir.getPath().replace(File.separatorChar, '/')); assertNotNull(fromVDir); assertNotNull(toVDir); - final VirtualFile fileToCopy = fromVDir.createChildData(this, "temp_file"); + final VirtualFile fileToCopy = createChildData(fromVDir, "temp_file"); final byte[] byteContent = {0, 1, 2, 3}; - fileToCopy.setBinaryContent(byteContent); + setBinaryContent(fileToCopy,byteContent); final String newName = "new_temp_file"; - final VirtualFile copy = fileToCopy.copy(this, toVDir, newName); + final VirtualFile copy = copy(fileToCopy, toVDir, newName); assertEquals(newName, copy.getName()); assertTrue(Arrays.equals(byteContent, copy.contentsToByteArray())); } @@ -177,11 +178,11 @@ public class LocalFileSystemTest extends PlatformTestCase { VirtualFile toVDir = myFS.findFileByPath(toDir.getPath().replace(File.separatorChar, '/')); assertNotNull(fromVDir); assertNotNull(toVDir); - final VirtualFile dirToCopy = fromVDir.createChildDirectory(this, "dir"); - final VirtualFile file = dirToCopy.createChildData(this, "temp_file"); - file.setBinaryContent(new byte[]{0, 1, 2, 3}); + final VirtualFile dirToCopy = createChildDirectory(fromVDir, "dir"); + final VirtualFile file = createChildData(dirToCopy, "temp_file"); + setBinaryContent(file,new byte[]{0, 1, 2, 3}); final String newName = "dir"; - final VirtualFile dirCopy = dirToCopy.copy(this, toVDir, newName); + final VirtualFile dirCopy = copy(dirToCopy, toVDir, newName); assertEquals(newName, dirCopy.getName()); PlatformTestUtil.assertDirectoriesEqual(toVDir, fromVDir); } @@ -291,7 +292,7 @@ public class LocalFileSystemTest extends PlatformTestCase { final VirtualFile file = myFS.refreshAndFindFileByIoFile(targetFile); assertNotNull(file); - file.setBinaryContent("hello".getBytes(CharsetToolkit.UTF8_CHARSET), 0, 0, requestor); + setBinaryContent(file,"hello".getBytes(CharsetToolkit.UTF8_CHARSET), 0, 0, requestor); assertTrue(file.getLength() > 0); final VirtualFile check = myFS.refreshAndFindFileByIoFile(hardLinkFile); @@ -698,12 +699,25 @@ public class LocalFileSystemTest extends PlatformTestCase { assertNotNull(vFile); assertWritable(file, vFile, true); - vFile.setWritable(false); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + vFile.setWritable(false); + return null; + } + }); + assertWritable(file, vFile, false); vFile.refresh(false, false); assertWritable(file, vFile, false); - vFile.setWritable(true); + ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { + @Override + public Object compute() throws IOException { + vFile.setWritable(true); + return null; + } + }); assertWritable(file, vFile, true); vFile.refresh(false, false); assertWritable(file, vFile, true); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java index e83f5ee1f9ee..d971758b1493 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java @@ -59,7 +59,7 @@ public class PersistentFsTest extends PlatformTestCase { int id = ((VirtualFileWithId)vFile).getId(); assertEquals(vFile, myFs.findFileById(id)); - vFile.delete(this); + delete(vFile); assertNull(myFs.findFileById(id)); } diff --git a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java index e03c3f6c45e1..bf45e594dc4a 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java @@ -36,7 +36,6 @@ import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -101,11 +100,6 @@ public class PsiDocumentManagerImplTest extends PlatformTestCase { assertSame(document, FileDocumentManager.getInstance().getDocument(vFile)); } - @Override - protected boolean isRunInWriteAction() { - return false; - } - private static LightVirtualFile createFile() { return new LightVirtualFile("foo.txt"); } @@ -436,7 +430,7 @@ public class PsiDocumentManagerImplTest extends PlatformTestCase { private void makeFileTooLarge(final VirtualFile vFile) throws Exception { WriteCommandAction.runWriteCommandAction(myProject, (ThrowableComputable)() -> { - VfsUtil.saveText(vFile, StringUtil.repeat("a", FileUtilRt.LARGE_FOR_CONTENT_LOADING + 1)); + setFileText(vFile, StringUtil.repeat("a", FileUtilRt.LARGE_FOR_CONTENT_LOADING + 1)); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); return null; }); diff --git a/platform/platform-tests/testSrc/com/intellij/psi/search/GlobalSearchScopeTest.java b/platform/platform-tests/testSrc/com/intellij/psi/search/GlobalSearchScopeTest.java index 60286fa560a1..3f41c48f3af9 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/search/GlobalSearchScopeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/search/GlobalSearchScopeTest.java @@ -24,7 +24,7 @@ public class GlobalSearchScopeTest extends PlatformTestCase { public void testUniteDirectorySearchScopeDoesNotSOE() throws Exception { VirtualFile genRoot = getVirtualFile(createTempDir("genSrcRoot")); VirtualFile srcRoot = getVirtualFile(createTempDir("srcRoot")); - VirtualFile child = srcRoot.createChildDirectory(this, "child"); + VirtualFile child = createChildDirectory(srcRoot, "child"); GlobalSearchScope childScope = GlobalSearchScopesCore.directoryScope(getProject(), child, true); GlobalSearchScope directoryScope = GlobalSearchScopesCore.directoryScope(getProject(), srcRoot, true); @@ -40,7 +40,7 @@ public class GlobalSearchScopeTest extends PlatformTestCase { int N = 1000; VirtualFile[] d = new VirtualFile[N]; for (int i=0; i< N;i++) { - d[i] = srcRoot.createChildDirectory(this, "d"+i); + d[i] = createChildDirectory(srcRoot, "d"+i); GlobalSearchScope united = s.uniteWith(GlobalSearchScopesCore.directoryScope(getProject(), d[i], true)); assertNotSame(s, united); s = united; diff --git a/platform/platform-tests/testSrc/com/intellij/ui/IconUtilTest.java b/platform/platform-tests/testSrc/com/intellij/ui/IconUtilTest.java index 075a3b0ee465..f168f7a19f2b 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/IconUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/IconUtilTest.java @@ -325,9 +325,4 @@ public class IconUtilTest extends PlatformTestCase { } return Collections.singletonList(icon); } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/platform/platform-tests/testSrc/com/intellij/util/StringBuilderSpinAllocatorTest.java b/platform/platform-tests/testSrc/com/intellij/util/StringBuilderSpinAllocatorTest.java index 183abe63b7fb..2d7f613e455d 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/StringBuilderSpinAllocatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/StringBuilderSpinAllocatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,9 +104,4 @@ public class StringBuilderSpinAllocatorTest extends PlatformTestCase { randomField++; return spinTime; } - - @Override - protected boolean isRunInWriteAction() { - return false; - } } diff --git a/platform/testFramework/src/com/intellij/testFramework/IdeResourcesTestCase.java b/platform/testFramework/src/com/intellij/testFramework/IdeResourcesTestCase.java index 7e6896842f2b..fab99c8e14b4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/IdeResourcesTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/IdeResourcesTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,11 +34,6 @@ import java.util.Set; */ public abstract class IdeResourcesTestCase extends PlatformTestCase { - @Override - protected boolean isRunInWriteAction() { - return false; - } - public void testFeatureTipsRegistered() { ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance(); Set ids = registry.getFeatureIds(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index a9e62ab38e19..9625c1231400 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -716,7 +716,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } protected boolean isRunInWriteAction() { - return true; + return false; } @Override @@ -938,7 +938,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro }.execute().throwException(); } - public static void setBinaryContent(final VirtualFile file, final byte[] content) { + public static void setBinaryContent(@NotNull final VirtualFile file, @NotNull final byte[] content) { new WriteAction() { @Override protected void run(@NotNull Result result) throws Throwable { @@ -946,4 +946,12 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } }.execute().throwException(); } + public static void setBinaryContent(@NotNull final VirtualFile file, @NotNull final byte[] content, final long newModificationStamp, final long newTimeStamp, final Object requestor) { + new WriteAction() { + @Override + protected void run(@NotNull Result result) throws Throwable { + file.setBinaryContent(content,newModificationStamp, newTimeStamp,requestor); + } + }.execute().throwException(); + } } diff --git a/platform/testFramework/src/com/intellij/testFramework/TempFiles.java b/platform/testFramework/src/com/intellij/testFramework/TempFiles.java index e819c59160c3..dc27670903c9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TempFiles.java +++ b/platform/testFramework/src/com/intellij/testFramework/TempFiles.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.intellij.testFramework; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; @@ -106,14 +108,19 @@ public class TempFiles { } } - public VirtualFile createVFile(@NotNull VirtualFile parentDir, @NotNull String name, @NotNull String text) { - try { - final VirtualFile virtualFile = parentDir.createChildData(this, name); - VfsUtil.saveText(virtualFile, text + "\n"); - return virtualFile; - } - catch (IOException e) { - throw new RuntimeException(e); - } + public VirtualFile createVFile(@NotNull final VirtualFile parentDir, @NotNull final String name, @NotNull final String text) { + return ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public VirtualFile compute() { + try { + final VirtualFile virtualFile = parentDir.createChildData(this, name); + VfsUtil.saveText(virtualFile, text + "\n"); + return virtualFile; + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + }); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java index eb2b96dc74f4..31a5a69fa30d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java @@ -16,6 +16,7 @@ package com.intellij.testFramework; import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; @@ -99,14 +100,18 @@ public class VfsTestUtil { UtilKt.deleteFile(file); } - public static void clearContent(VirtualFile file) { - Assert.assertNotNull(file); - try { - VfsUtil.saveText(file, ""); - } - catch (IOException e) { - throw new RuntimeException(e); - } + public static void clearContent(@NotNull final VirtualFile file) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + try { + VfsUtil.saveText(file, ""); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + }); } @SuppressWarnings("UnusedDeclaration") diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java index 972a80e3c196..ff1155baa609 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.intellij.xdebugger; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -30,7 +32,7 @@ public class UpdateBreakpointsAfterRenameTest extends XBreakpointsTestCase { public void testRenameFile() throws Exception { final VirtualFile file = createFile("file.txt"); XLineBreakpoint b = putBreakpoint(file); - file.rename(this, "file2.txt"); + rename(file, "file2.txt"); assertTrue(b.getFileUrl().endsWith("file2.txt")); assertSame(b, getBreakpointManager().findBreakpointAtLine(XDebuggerTestCase.MY_LINE_BREAKPOINT_TYPE, file, 0)); } @@ -39,19 +41,24 @@ public class UpdateBreakpointsAfterRenameTest extends XBreakpointsTestCase { final VirtualFile file = createFile("dir/a.txt"); final VirtualFile targetDir = createFile("dir2/b.txt").getParent(); final XLineBreakpoint b = putBreakpoint(file); - file.move(this, targetDir); + move(file, targetDir); assertTrue(b.getFileUrl().endsWith("dir2/a.txt")); } public void testRenameParentDir() throws Exception { final VirtualFile file = createFile("dir/x.txt"); final XLineBreakpoint b = putBreakpoint(file); - file.getParent().rename(this, "dir2"); + rename(file.getParent(), "dir2"); assertTrue(b.getFileUrl().endsWith("dir2/x.txt")); } private XLineBreakpoint putBreakpoint(final VirtualFile file) { - return getBreakpointManager().addLineBreakpoint(XDebuggerTestCase.MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null, false); + return ApplicationManager.getApplication().runWriteAction(new Computable>() { + @Override + public XLineBreakpoint compute() { + return getBreakpointManager().addLineBreakpoint(XDebuggerTestCase.MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null, false); + } + }); } private VirtualFile createFile(String path) { diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java index 4246c892a6f1..c08c77ac653f 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import org.jdom.Document; import org.jdom.Element; import org.jetbrains.annotations.NotNull; -import java.io.IOException; import java.util.List; /** @@ -38,32 +37,32 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { assertSameElements(getAllBreakpoints(), defaultBreakpoint); XLineBreakpoint lineBreakpoint = - myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "url", 239, new MyBreakpointProperties("123")); + addLineBreakpoint(myBreakpointManager, "url", 239, new MyBreakpointProperties("123")); - XBreakpoint breakpoint = myBreakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, new MyBreakpointProperties("abc")); + XBreakpoint breakpoint = addBreakpoint(myBreakpointManager, new MyBreakpointProperties("abc")); assertSameElements(getAllBreakpoints(), breakpoint, lineBreakpoint, defaultBreakpoint); assertSame(lineBreakpoint, assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE))); assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), breakpoint, defaultBreakpoint); - myBreakpointManager.removeBreakpoint(lineBreakpoint); + removeBreakPoint(myBreakpointManager, lineBreakpoint); assertSameElements(getAllBreakpoints(), breakpoint, defaultBreakpoint); assertTrue(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE).isEmpty()); assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), breakpoint, defaultBreakpoint); - myBreakpointManager.removeBreakpoint(breakpoint); + removeBreakPoint(myBreakpointManager, breakpoint); assertSameElements(getAllBreakpoints(), defaultBreakpoint); assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), defaultBreakpoint); } public void testSerialize() { XLineBreakpoint breakpoint = - myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "myurl", 239, new MyBreakpointProperties("z1")); + addLineBreakpoint(myBreakpointManager, "myurl", 239, new MyBreakpointProperties("z1")); breakpoint.setCondition("cond"); breakpoint.setLogExpression("log"); breakpoint.setSuspendPolicy(SuspendPolicy.NONE); breakpoint.setLogMessage(true); - myBreakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, new MyBreakpointProperties("z2")); + addBreakpoint(myBreakpointManager, new MyBreakpointProperties("z2")); reload(); List> breakpoints = getAllBreakpoints(); @@ -134,27 +133,22 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { }; myBreakpointManager.addBreakpointListener(MY_LINE_BREAKPOINT_TYPE, listener); - XBreakpoint breakpoint = myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "url", 239, new MyBreakpointProperties("abc")); - myBreakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, new MyBreakpointProperties("321")); - myBreakpointManager.removeBreakpoint(breakpoint); + XBreakpoint breakpoint = addLineBreakpoint(myBreakpointManager, "url", 239, new MyBreakpointProperties("abc")); + addBreakpoint(myBreakpointManager, new MyBreakpointProperties("321")); + removeBreakPoint(myBreakpointManager, breakpoint); assertEquals("added[abc];removed[abc];", out.toString()); myBreakpointManager.removeBreakpointListener(MY_LINE_BREAKPOINT_TYPE, listener); out.setLength(0); - myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "url", 239, new MyBreakpointProperties("a")); + addLineBreakpoint(myBreakpointManager, "url", 239, new MyBreakpointProperties("a")); assertEquals("", out.toString()); } public void testRemoveFile() { final VirtualFile file = myTempFiles.createVFile("breakpoint", ".txt"); - myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null); + addLineBreakpoint(myBreakpointManager, file.getUrl(), 0, null); assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE)); - try { - file.delete(this); - } - catch (IOException e) { - throw new RuntimeException(e); - } + delete(file); assertEmpty(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE)); } diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java index 132cf71c59ac..57a84d3bcc4a 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ */ package com.intellij.xdebugger; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.util.xmlb.annotations.Attribute; -import com.intellij.xdebugger.breakpoints.XBreakpoint; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -import com.intellij.xdebugger.breakpoints.XBreakpointType; -import com.intellij.xdebugger.breakpoints.XLineBreakpointType; +import com.intellij.xdebugger.breakpoints.*; +import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import org.jetbrains.annotations.NotNull; /** @@ -34,6 +34,39 @@ public abstract class XDebuggerTestCase extends PlatformTestCase { public static final MyLineBreakpointType MY_LINE_BREAKPOINT_TYPE = new MyLineBreakpointType(); protected static final MySimpleBreakpointType MY_SIMPLE_BREAKPOINT_TYPE = new MySimpleBreakpointType(); + @NotNull + static XBreakpoint addBreakpoint(final XBreakpointManagerImpl breakpointManager, + final MyBreakpointProperties abc) { + return ApplicationManager.getApplication().runWriteAction(new Computable>() { + @Override + public XBreakpoint compute() { + return breakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, abc); + } + }); + } + + @NotNull + static XLineBreakpoint addLineBreakpoint(final XBreakpointManagerImpl breakpointManager, final String url, + final int line, + final MyBreakpointProperties properties) { + return ApplicationManager.getApplication().runWriteAction(new Computable>() { + @Override + public XLineBreakpoint compute() { + return breakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, url, line, properties); + } + }); + } + + static void removeBreakPoint(final XBreakpointManagerImpl breakpointManager, + final XBreakpoint breakpoint) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + breakpointManager.removeBreakpoint(breakpoint); + } + }); + } + @Override protected void initApplication() throws Exception { super.initApplication(); diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDependentBreakpointsTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDependentBreakpointsTest.java index b24cbca61c97..89c3dce9cc9d 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDependentBreakpointsTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDependentBreakpointsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public class XDependentBreakpointsTest extends XBreakpointsTestCase { assertSame(slave, assertOneElement(myDependentBreakpointManager.getSlaveBreakpoints(master))); assertSame(slave, assertOneElement(myDependentBreakpointManager.getAllSlaveBreakpoints())); - myBreakpointManager.removeBreakpoint(master); + removeBreakPoint(myBreakpointManager, master); assertNull(myDependentBreakpointManager.getMasterBreakpoint(slave)); assertEmpty(myDependentBreakpointManager.getAllSlaveBreakpoints()); } @@ -71,10 +71,10 @@ public class XDependentBreakpointsTest extends XBreakpointsTestCase { } private XLineBreakpoint createSlave() { - return myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "file://slave", 2, new MyBreakpointProperties("z-slave")); + return addLineBreakpoint(myBreakpointManager, "file://slave", 2, new MyBreakpointProperties("z-slave")); } private XLineBreakpoint createMaster() { - return myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "file://master", 1, new MyBreakpointProperties("z-master")); + return addLineBreakpoint(myBreakpointManager, "file://master", 1, new MyBreakpointProperties("z-master")); } } diff --git a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java index 0f4fc1b5bce7..5a4737ec6c91 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java +++ b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,13 @@ package git4idea.push; import com.intellij.notification.NotificationType; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.EdtTestUtil; import com.intellij.util.containers.ContainerUtil; -import git4idea.GitBranch; import git4idea.GitLocalBranch; import git4idea.GitRemoteBranch; import git4idea.GitStandardRemoteBranch; @@ -36,7 +33,6 @@ import git4idea.test.MockGitRepository; import git4idea.update.GitUpdateResult; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -239,17 +235,7 @@ public class GitPushResultNotificationTest extends GitPlatformTest { EdtTestUtil.runInEdtAndWait(new Runnable() { @Override public void run() { - root.set(ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public VirtualFile compute() { - try { - return ourProject.getBaseDir().createChildData(null, name); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - })); + root.set(createChildData(ourProject.getBaseDir(), name)); } }); return new MockGitRepository(ourProject, root.get()); diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java index 0d212f65565e..98bf25a3aa7b 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package com.intellij.uiDesigner.make; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -94,7 +93,12 @@ public class FormSourceCodeGeneratorTest extends PsiTestCase { @Override public void run() { try { - myGenerator.generate(form); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + myGenerator.generate(form); + } + }); } catch (Exception e) { fail(e.getMessage()); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomFileDescriptionTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomFileDescriptionTest.java index 1e14863e394b..9fcb8818ed04 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomFileDescriptionTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomFileDescriptionTest.java @@ -16,6 +16,7 @@ package com.intellij.util.xml; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; @@ -125,7 +126,13 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase { final XmlFile file = (XmlFile)createFile("a.xml", "42"); getDomManager().registerFileDescription(new MockDomFileDescription(MyElement.class, "b", file), myDisposable); - file.setName("b.xml"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + file.setName("b.xml"); + } + }); + assertTrue(getDomManager().isDomFile(file)); final XmlFile copy = (XmlFile)file.copy(); assertTrue(getDomManager().isDomFile(copy)); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomPerformanceTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomPerformanceTest.java index f65d32b3b6ef..9fd830f4dc79 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomPerformanceTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomPerformanceTest.java @@ -15,6 +15,7 @@ */ package com.intellij.util.xml; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.module.Module; @@ -56,9 +57,14 @@ public class DomPerformanceTest extends DomHardCoreTestCase{ PlatformTestUtil.startPerformanceTest(getTestName(false), 80000, new ThrowableRunnable() { @Override public void run() throws Exception { - for (int i = 0; i < 239; i++) { - element.addChildElement().copyFrom(child); - } + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + for (int i = 0; i < 239; i++) { + element.addChildElement().copyFrom(child); + } + } + }); } }).cpuBound().attempts(1).useLegacyScaling().assertTiming(); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomVirtualFileEventsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomVirtualFileEventsTest.java index e1ed1542a0cd..de842adf169e 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomVirtualFileEventsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomVirtualFileEventsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,9 @@ package com.intellij.util.xml; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.module.Module; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.xml.XmlFile; -import com.intellij.testFramework.PsiTestUtil; import com.intellij.util.xml.events.DomEvent; import com.intellij.util.xml.impl.DomFileElementImpl; import org.jetbrains.annotations.NotNull; @@ -48,14 +46,14 @@ public class DomVirtualFileEventsTest extends DomHardCoreTestCase{ @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); - PsiTestUtil.addSourceContentToRoots(getModule(), dir); + addSourceContentToRoots(getModule(), dir); final VirtualFile childData = dir.createChildData(this, "abc.xml"); System.gc(); System.gc(); System.gc(); System.gc(); assertResultsAndClear(); - VfsUtil.saveText(childData, ""); + setFileText(childData, ""); assertEventCount(0); assertResultsAndClear(); } @@ -67,10 +65,10 @@ public class DomVirtualFileEventsTest extends DomHardCoreTestCase{ @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); - PsiTestUtil.addSourceContentToRoots(getModule(), dir); + addSourceContentToRoots(getModule(), dir); final VirtualFile childData = dir.createChildData(this, "abc.xml"); assertResultsAndClear(); - VfsUtil.saveText(childData, ""); + setFileText(childData, ""); final DomFileElementImpl fileElement = getFileElement(childData); assertResultsAndClear(); @@ -88,9 +86,9 @@ public class DomVirtualFileEventsTest extends DomHardCoreTestCase{ @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); - PsiTestUtil.addSourceContentToRoots(getModule(), dir); + addSourceContentToRoots(getModule(), dir); final VirtualFile data = dir.createChildData(this, "abc.xml"); - VfsUtil.saveText(data, ""); + setFileText(data, ""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); final DomFileElementImpl fileElement = getFileElement(data); assertEventCount(0); diff --git a/xml/tests/src/com/intellij/codeInsight/XmlReparseTest.java b/xml/tests/src/com/intellij/codeInsight/XmlReparseTest.java index 08107e7a2a0b..4ea26221b6c3 100644 --- a/xml/tests/src/com/intellij/codeInsight/XmlReparseTest.java +++ b/xml/tests/src/com/intellij/codeInsight/XmlReparseTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Created by IntelliJ IDEA. * User: mike @@ -8,6 +24,7 @@ */ package com.intellij.codeInsight; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.psi.AbstractReparseTestCase; @@ -154,7 +171,13 @@ public class XmlReparseTest extends AbstractReparseTestCase { private static void removeGarbage(Document document) { int i = document.getText().indexOf(marker); if (i==-1) return; - document.replaceString(i,i+marker.length(),""); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + document.replaceString(i, i + marker.length(), ""); + } + }); + removeGarbage(document); }