execute tests outside write action by default

This commit is contained in:
Alexey Kudravtsev
2016-02-12 15:18:39 +03:00
parent 9a49afe38d
commit 1d1025401f
26 changed files with 568 additions and 181 deletions
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2016 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.codeInsight;
import com.intellij.JavaTestUtil;
@@ -5,6 +20,8 @@ import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.GenerationInfo;
import com.intellij.codeInsight.generation.PsiGenerationInfo;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NonNls;
@@ -47,7 +64,12 @@ public class GenerateMembersUtilTest extends LightCodeInsightTestCase {
PsiMethod method = factory.createMethod("foo", PsiType.VOID);
int offset = getEditor().getCaretModel().getOffset();
List<GenerationInfo> list = Collections.<GenerationInfo>singletonList(new PsiGenerationInfo<PsiMethod>(method));
List<GenerationInfo> members = GenerateMembersUtil.insertMembersAtOffset(getFile(), offset, list);
List<GenerationInfo> members = ApplicationManager.getApplication().runWriteAction(new Computable<List<GenerationInfo>>() {
@Override
public List<GenerationInfo> compute() {
return GenerateMembersUtil.insertMembersAtOffset(getFile(), offset, list);
}
});
members.get(0).positionCaret(myEditor, true);
checkResultByFile(null, BASE_PATH + getTestName(false) + "_after.java", true);
}
@@ -63,10 +85,16 @@ public class GenerateMembersUtilTest extends LightCodeInsightTestCase {
PsiJavaFile file = (PsiJavaFile)PsiFileFactory.getInstance(getProject())
.createFileFromText(JavaLanguage.INSTANCE, "class A {void foo() {}}\n class B extends A {void foo() {}\n}");
method = file.getClasses()[1].getMethods()[0];
GenerateMembersUtil.setupGeneratedMethod(method);
assertEquals("@Override void foo() {\n" +
" super.foo();\n" +
" }", method.getText());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
PsiMethod newMethod = file.getClasses()[1].getMethods()[0];
GenerateMembersUtil.setupGeneratedMethod(newMethod);
assertEquals("@Override void foo() {\n" +
" super.foo();\n" +
" }", newMethod.getText());
}
});
}
}
@@ -1,7 +1,23 @@
/*
* Copyright 2000-2016 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.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.generation.actions.GenerateSuperMethodCallAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
@@ -43,7 +59,13 @@ public class GenerateSuperMethodCallTest extends LightCodeInsightTestCase {
return super.getHandler();
}
}.getHandler();
handler.invoke(getProject(), getEditor(), getFile());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
handler.invoke(getProject(), getEditor(), getFile());
}
});
checkResultByFile(after);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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,6 +21,7 @@ import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
@@ -163,19 +164,27 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
PsiElement context = getFile().findElementAt(offset);
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
assert psiClass != null;
if (toImplement == null) {
PsiClassType[] implement = psiClass.getImplementsListTypes();
final PsiClass superClass = implement.length == 0 ? psiClass.getSuperClass() : implement[0].resolve();
assert superClass != null;
PsiMethod method = superClass.getMethods()[0];
final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, PsiSubstitutor.EMPTY);
final List<PsiMethodMember> candidates = Collections.singletonList(new PsiMethodMember(method,
OverrideImplementExploreUtil.correctSubstitutor(method, substitutor)));
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(getEditor(), psiClass, candidates, copyJavadoc, true);
}
else {
OverrideImplementUtil.chooseAndOverrideOrImplementMethods(getProject(), getEditor(), psiClass, toImplement);
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (toImplement == null) {
PsiClassType[] implement = psiClass.getImplementsListTypes();
final PsiClass superClass = implement.length == 0 ? psiClass.getSuperClass() : implement[0].resolve();
assert superClass != null;
PsiMethod method = superClass.getMethods()[0];
final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, PsiSubstitutor.EMPTY);
final List<PsiMethodMember> candidates = Collections.singletonList(new PsiMethodMember(method,
OverrideImplementExploreUtil
.correctSubstitutor(method,
substitutor)));
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(getEditor(), psiClass, candidates, copyJavadoc, true);
}
else {
OverrideImplementUtil.chooseAndOverrideOrImplementMethods(getProject(), getEditor(), psiClass, toImplement);
}
}
});
checkResultByFile(BASE_DIR + "after" + name + ".java");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,6 +22,7 @@ import com.intellij.ide.DataManager;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiLiteralExpression;
@@ -61,8 +62,15 @@ public class I18nizeTest extends LightCodeInsightTestCase {
if (afterFileExists) {
PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(getFile(), getEditor());
assertNotNull(handler);
handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1", "i18nizedExpr",
PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1",
"i18nizedExpr",
PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER);
}
});
checkResultByFile(afterFile);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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,6 +25,7 @@ import com.intellij.lang.LanguageSurrounders;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.lang.surroundWith.SurroundDescriptor;
import com.intellij.lang.surroundWith.Surrounder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
@@ -216,14 +217,26 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
assertTrue(surrounder.isApplicable(elements));
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
}
});
checkResultByFile(BASE_PATH + fileName + "_after.java");
}
private void doTestWithTemplateFinish(@NotNull String fileName, Surrounder surrounder, @Nullable String textToType) {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
configureByFile(BASE_PATH + fileName + ".java");
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
}
});
if (textToType != null) {
type(textToType);
}
@@ -1,6 +1,22 @@
/*
* Copyright 2000-2016 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.codeInsight.intention;
import com.intellij.codeInsight.intention.impl.SplitIfAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -61,6 +77,11 @@ public class SplitIfActionTest extends LightCodeInsightTestCase {
private void perform() throws Exception {
SplitIfAction action = new SplitIfAction();
assertTrue(action.isAvailable(getProject(), getEditor(), getFile()));
action.invoke(getProject(), getEditor(), getFile());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
action.invoke(getProject(), getEditor(), getFile());
}
});
}
}
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2016 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: Maxim.Mossienko
@@ -6,6 +22,7 @@
*/
package com.intellij.editor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.impl.LineSet;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -55,46 +72,56 @@ public class LineSetIncrementalUpdateTest extends LightCodeInsightTestCase {
}
private static void doInsert() {
Document document = myEditor.getDocument();
document.insertString(myEditor.getCaretModel().getOffset(), STRING6);
document.insertString(myEditor.getCaretModel().getOffset(), STRING5);
document.insertString(myEditor.getCaretModel().getOffset(), STRING4);
document.insertString(myEditor.getCaretModel().getOffset(), STRING3);
document.insertString(myEditor.getCaretModel().getOffset(), STRING2);
document.insertString(myEditor.getCaretModel().getOffset(), STRING1);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
Document document = myEditor.getDocument();
document.insertString(myEditor.getCaretModel().getOffset(), STRING6);
document.insertString(myEditor.getCaretModel().getOffset(), STRING5);
document.insertString(myEditor.getCaretModel().getOffset(), STRING4);
document.insertString(myEditor.getCaretModel().getOffset(), STRING3);
document.insertString(myEditor.getCaretModel().getOffset(), STRING2);
document.insertString(myEditor.getCaretModel().getOffset(), STRING1);
}
}.execute().throwException();
}
private static void doDelete() {
Document document = myEditor.getDocument();
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
Document document = myEditor.getDocument();
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING1.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING1.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING2.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING2.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING3.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING3.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING4.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING4.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING5.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING5.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING6.length()
);
document.deleteString(
myEditor.getCaretModel().getOffset(),
myEditor.getCaretModel().getOffset() + STRING6.length()
);
}
}.execute().throwException();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -43,9 +43,4 @@ public class FoldingExceptionTest extends LightCodeInsightTestCase {
PsiDocumentManager.getInstance(ourProject).commitAllDocuments();
CodeInsightTestFixtureImpl.instantiateAndRun(myFile, myEditor, new int[]{Pass.UPDATE_ALL, Pass.LOCAL_INSPECTIONS}, false);
}
@Override
protected boolean isRunInWriteAction() {
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.openapi.editor.impl;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.psi.PsiDocumentManager;
@@ -80,11 +81,24 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
"}");
executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS);
checkFoldingState("[FoldRegion +(25:33), placeholder='{...}']");
myEditor.getDocument().insertString(0, "/*");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().insertString(0, "/*");
}
}.execute().throwException();
checkFoldingState("[FoldRegion -(0:37), placeholder='/.../', FoldRegion +(27:35), placeholder='{...}']");
myEditor.getDocument().deleteString(0, 2);
WriteCommandAction.runWriteCommandAction(getProject(),
new Runnable() {
@Override
public void run() {
myEditor.getDocument().deleteString(0, 2);
}
});
checkFoldingState("[FoldRegion +(25:33), placeholder='{...}']");
}
@@ -97,7 +111,13 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS);
checkFoldingState("[FoldRegion +(25:33), placeholder='{...}']");
myEditor.getDocument().insertString(0, "/*");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().insertString(0, "/*");
}
}.execute().throwException();
checkFoldingState("[FoldRegion -(0:37), placeholder='/.../', FoldRegion +(27:35), placeholder='{...}']");
executeAction(IdeActions.ACTION_EXPAND_ALL_REGIONS);
@@ -1,8 +1,25 @@
/*
* Copyright 2000-2016 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.
*/
/*
* @author max
*/
package com.intellij.psi;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -1084,7 +1101,13 @@ public class TreeIsCorrectAfterDiffReparseTest extends LightCodeInsightTestCase
final PsiDocumentManager docManager = PsiDocumentManager.getInstance(ourProject);
final Document doc = docManager.getDocument(myFile);
doc.insertString(part1.length(), "/**");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
doc.insertString(part1.length(), "/**");
}
});
boolean old = DebugUtil.CHECK;
DebugUtil.CHECK = true;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 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.formatter.java;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
@@ -168,7 +169,13 @@ public class JavaFormatterInEditorTest extends LightPlatformCodeInsightTestCase
public void doTest(@NotNull String before, @NotNull String after) throws IOException {
configureFromFileText(getTestName(false) + ".java", before);
CodeStyleManager.getInstance(getProject()).reformatText(getFile(), 0, getEditor().getDocument().getTextLength());
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
CodeStyleManager.getInstance(getProject()).reformatText(getFile(), 0, getEditor().getDocument().getTextLength());
}
});
checkResultByText(after);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -66,7 +66,13 @@ public class ExtendsBoundListTest extends LightCodeInsightTestCase {
final PsiClass cloneableClass = getJavaFacade().findClass("java.lang.Cloneable");
assertNotNull(cloneableClass);
final PsiJavaCodeReferenceElement reference = getJavaFacade().getElementFactory().createClassReferenceElement(cloneableClass);
extendsList.addAfter(reference, extendsList.getReferenceElements()[0]);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
extendsList.addAfter(reference, extendsList.getReferenceElements()[0]);
}
});
check();
}
@@ -76,7 +82,13 @@ public class ExtendsBoundListTest extends LightCodeInsightTestCase {
final PsiClass cloneableClass = getJavaFacade().findClass("java.lang.Cloneable");
assertNotNull(cloneableClass);
final PsiJavaCodeReferenceElement reference = getJavaFacade().getElementFactory().createClassReferenceElement(cloneableClass);
extendsList.addBefore(reference, extendsList.getReferenceElements()[0]);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
extendsList.addBefore(reference, extendsList.getReferenceElements()[0]);
}
});
check();
}
@@ -86,7 +98,13 @@ public class ExtendsBoundListTest extends LightCodeInsightTestCase {
final PsiClass cloneableClass = getJavaFacade().findClass("java.lang.Cloneable");
assertNotNull(cloneableClass);
final PsiJavaCodeReferenceElement reference = getJavaFacade().getElementFactory().createClassReferenceElement(cloneableClass);
extendsList.addBefore(reference, null);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
extendsList.addBefore(reference, null);
}
});
check();
}
@@ -96,7 +114,13 @@ public class ExtendsBoundListTest extends LightCodeInsightTestCase {
final PsiClass cloneableClass = getJavaFacade().findClass(CommonClassNames.JAVA_LANG_RUNNABLE);
assertNotNull(cloneableClass);
final PsiJavaCodeReferenceElement reference = getJavaFacade().getElementFactory().createClassReferenceElement(cloneableClass);
extendsList.add(reference);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
extendsList.add(reference);
}
});
check();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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,6 +18,7 @@ package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -919,7 +920,12 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
for (final Match match : duplicates) {
if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid()) continue;
PsiDocumentManager.getInstance(project).commitAllDocuments();
processor.processMatch(match);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
processor.processMatch(match);
}
});
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -215,8 +215,4 @@ public class InplaceIntroduceParameterTest extends AbstractJavaInplaceIntroduceT
return super.invokeImpl(project, localVariable, editor);
}
}
@Override
protected boolean isRunInWriteAction() {
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 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.testFramework.LightCodeInsightTestCase;
public abstract class LightRefactoringTestCase extends LightCodeInsightTestCase{
@Override
protected boolean isRunInWriteAction() {
return false;
}
}
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2016 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.
*/
/*
* User: anna
* Date: 18-Mar-2008
@@ -8,7 +24,6 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.source.PsiImmediateClassType;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.typeMigration.TypeMigrationLabeler;
import com.intellij.refactoring.typeMigration.TypeMigrationProcessor;
import com.intellij.refactoring.typeMigration.TypeMigrationRules;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -143,9 +158,4 @@ public class ChangeTypeSignatureTest extends LightCodeInsightTestCase {
public void testMethodReturnTypeMigration() throws Exception {
doTest(true, "java.lang.Integer");
}
@Override
protected boolean isRunInWriteAction() {
return false;
}
}
@@ -15,12 +15,16 @@
*/
package com.intellij.ide.bookmarks;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.testFramework.LeakHunter;
import com.intellij.testFramework.TestFileType;
@@ -60,8 +64,14 @@ public class BookmarkManagerTest extends AbstractEditorTest {
addBookmark(2);
List<Bookmark> bookmarksBefore = getManager().getValidBookmarks();
assertEquals(1, bookmarksBefore.size());
myEditor.getDocument().setText(text);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().setText(text);
}
}.execute().throwException();
List<Bookmark> bookmarksAfter = getManager().getValidBookmarks();
assertEquals(1, bookmarksAfter.size());
assertSame(bookmarksBefore.get(0), bookmarksAfter.get(0));
@@ -157,8 +167,14 @@ public class BookmarkManagerTest extends AbstractEditorTest {
"}";
init(text, TestFileType.TEXT);
addBookmark(2);
myEditor.getDocument().setText("111\n222" + text + "333");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().setText("111\n222" + text + "333");
}
}.execute().throwException();
List<Bookmark> bookmarks = getManager().getValidBookmarks();
assertEquals(1, bookmarks.size());
Bookmark bookmark = bookmarks.get(0);
@@ -171,8 +187,19 @@ public class BookmarkManagerTest extends AbstractEditorTest {
"public class Test {\n" +
"}";
myVFile = getSourceRoot().createChildData(null, getTestName(false) + ".txt");
VfsUtil.saveText(myVFile, text);
myVFile = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
@Override
public VirtualFile compute() {
try {
VirtualFile file = getSourceRoot().createChildData(null, getTestName(false) + ".txt");
VfsUtil.saveText(file, text);
return file;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Bookmark bookmark = getManager().addTextBookmark(myVFile, 1, "xxx");
@@ -183,7 +210,13 @@ public class BookmarkManagerTest extends AbstractEditorTest {
assertNotNull(document);
PsiDocumentManager.getInstance(getProject()).getPsiFile(document); // create psi so that PsiChangeHandler won't leak
document.insertString(0, "line 0\n");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.insertString(0, "line 0\n");
}
}.execute().throwException();
assertEquals(2, bookmark.getLine());
myEditor = createEditor(myVFile);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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,12 +15,19 @@
*/
package com.intellij.openapi.editor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
public class EditorModificationUtilTest extends LightPlatformCodeInsightTestCase {
public void testInsertStringAtCaretNotMovingCaret() throws Exception {
configureFromFileText(getTestName(false) + ".txt", "text <caret>");
EditorModificationUtil.insertStringAtCaret(myEditor, " ", false, false);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
EditorModificationUtil.insertStringAtCaret(myEditor, " ", false, false);
}
});
checkResultByText("text <caret> ");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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,8 +19,7 @@ import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Assert;
/**
* @author max
@@ -157,7 +156,7 @@ public class FoldingTest extends AbstractEditorTest {
addCollapsedFoldRegion(10, 12, "???");
FoldRegion[] topLevelRegions = myModel.fetchTopLevel();
assertArrayEquals(new FoldRegion[]{region}, topLevelRegions);
Assert.assertArrayEquals(new FoldRegion[]{region}, topLevelRegions);
}
public void testLastCollapsedRegionBefore() {
@@ -184,8 +183,14 @@ public class FoldingTest extends AbstractEditorTest {
public void testModelRemainsConsistentOnTextRemoval() {
addCollapsedFoldRegion(0, 10, "...");
addCollapsedFoldRegion(1, 9, "...");
myEditor.getDocument().deleteString(0, 1);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().deleteString(0, 1);
}
});
addFoldRegion(20, 21, "..."); // an arbitrary action to rebuild folding caches
assertTrue(myModel.isOffsetCollapsed(5));
@@ -195,8 +200,14 @@ public class FoldingTest extends AbstractEditorTest {
addFoldRegion(0, 5, "...");
addFoldRegion(0, 4, "...");
assertNumberOfValidFoldRegions(2);
myEditor.getDocument().deleteString(4, 5);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().deleteString(4, 5);
}
});
assertNumberOfValidFoldRegions(1);
}
@@ -204,7 +215,13 @@ public class FoldingTest extends AbstractEditorTest {
public void testTopLevelRegionRemainsTopLevelAfterMergingIdenticalRegions() {
addCollapsedFoldRegion(10, 15, "...");
addCollapsedFoldRegion(10, 14, "...");
myEditor.getDocument().deleteString(14, 15);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().deleteString(14, 15);
}
});
FoldRegion region = myModel.getCollapsedRegionAtOffset(10);
assertNotNull(region);
@@ -17,6 +17,7 @@ package com.intellij.openapi.editor.impl;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.LogicalPosition;
@@ -70,11 +71,17 @@ public class EditorImplTest extends AbstractEditorTest {
assertEquals(4, EditorUtil.getTabSize(myEditor));
assertEquals("[FoldRegion +(59:64), placeholder=' { ', FoldRegion +(85:88), placeholder=' }']", myEditor.getFoldingModel().toString());
verifySoftWrapPositions(52, 85);
Document document = myEditor.getDocument();
for (int i = document.getLineCount() - 1; i >= 0; i--) {
document.insertString(document.getLineStartOffset(i), "//");
}
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
Document document = myEditor.getDocument();
for (int i = document.getLineCount() - 1; i >= 0; i--) {
document.insertString(document.getLineStartOffset(i), "//");
}
}
}.execute().throwException();
verifySoftWrapPositions(58, 93);
}
@@ -105,13 +112,19 @@ public class EditorImplTest extends AbstractEditorTest {
public void testNoExceptionDuringBulkModeDocumentUpdate() throws Exception {
initText("something");
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
try {
document.setText("something\telse");
}
finally {
document.setInBulkUpdate(false);
}
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.setInBulkUpdate(true);
try {
document.setText("something\telse");
}
finally {
document.setInBulkUpdate(false);
}
}
}.execute().throwException();
checkResultByText("something\telse");
}
@@ -147,8 +160,14 @@ public class EditorImplTest extends AbstractEditorTest {
public void testNavigationInsideNonNormalizedLineTerminator() throws Exception {
initText("");
((DocumentImpl)myEditor.getDocument()).setAcceptSlashR(true);
myEditor.getDocument().insertString(0, "abc\r\ndef");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().insertString(0, "abc\r\ndef");
}
}.execute().throwException();
myEditor.getCaretModel().moveToOffset(4);
assertEquals(new LogicalPosition(0, 3), myEditor.getCaretModel().getLogicalPosition());
@@ -159,26 +178,38 @@ public class EditorImplTest extends AbstractEditorTest {
initText("long long line<caret>");
configureSoftWraps(12);
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
document.replaceString(4, 5, "-");
document.setInBulkUpdate(false);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.setInBulkUpdate(true);
document.replaceString(4, 5, "-");
document.setInBulkUpdate(false);
}
}.execute().throwException();
assertEquals(new VisualPosition(1, 5), myEditor.getCaretModel().getVisualPosition());
}
public void testSuccessiveBulkModeOperations() throws Exception {
initText("some text");
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
document.replaceString(4, 5, "-");
document.setInBulkUpdate(false);
myEditor.getCaretModel().moveToOffset(9);
document.setInBulkUpdate(true);
document.replaceString(4, 5, "+");
document.setInBulkUpdate(false);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.setInBulkUpdate(true);
document.replaceString(4, 5, "-");
document.setInBulkUpdate(false);
myEditor.getCaretModel().moveToOffset(9);
document.setInBulkUpdate(true);
document.replaceString(4, 5, "+");
document.setInBulkUpdate(false);
}
}.execute().throwException();
checkResultByText("some+text<caret>");
}
@@ -220,10 +251,16 @@ public class EditorImplTest extends AbstractEditorTest {
public void testUpdatingCaretPositionAfterBulkMode() throws Exception {
initText("a<caret>bc");
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
document.insertString(0, "\n "); // we're changing number of visual lines, and invalidating text layout for caret line
document.setInBulkUpdate(false);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
document.insertString(0, "\n "); // we're changing number of visual lines, and invalidating text layout for caret line
document.setInBulkUpdate(false);
}
}.execute().throwException();
checkResultByText("\n a<caret>bc");
}
@@ -255,7 +292,13 @@ public class EditorImplTest extends AbstractEditorTest {
JViewport viewport = ((EditorEx)myEditor).getScrollPane().getViewport();
Dimension normalSize = viewport.getExtentSize();
viewport.setExtentSize(new Dimension(0, 0));
myEditor.getDocument().deleteString(5, 14);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
myEditor.getDocument().deleteString(5, 14);
}
}.execute().throwException();
viewport.setExtentSize(normalSize);
verifySoftWrapPositions();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.openapi.editor.impl;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.EditorEx;
@@ -108,7 +109,12 @@ public class EditorStressTest extends AbstractEditorTest {
public void perform(EditorEx editor, Random random) {
Document document = editor.getDocument();
int offset = random.nextInt(document.getTextLength() + 1);
document.insertString(offset, myText);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.insertString(offset, myText);
}
}.execute().throwException();
}
}
@@ -119,7 +125,12 @@ public class EditorStressTest extends AbstractEditorTest {
int textLength = document.getTextLength();
if (textLength <= 0) return;
int offset = random.nextInt(textLength);
document.deleteString(offset, offset + 1);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
document.deleteString(offset, offset + 1);
}
}.execute().throwException();
}
}
@@ -132,7 +143,12 @@ public class EditorStressTest extends AbstractEditorTest {
int offset = random.nextInt(textLength);
int targetOffset = random.nextInt(textLength + 1);
if (targetOffset < offset || targetOffset > offset + 1) {
((DocumentEx)document).moveText(offset, offset + 1, targetOffset);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
((DocumentEx)document).moveText(offset, offset + 1, targetOffset);
}
}.execute().throwException();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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,6 +23,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.EditorTestUtil;
@@ -175,7 +176,14 @@ public class TrailingSpacesStripperTest extends LightPlatformCodeInsightTestCase
Document document = configureFromFileText("x.txt", "xxx <caret>\nyyy\n\t\t\t");
// make any modification, so that Document and file content differ. Otherwise save won't be, and "on-save" actions won't be called.
document.insertString(0, " ");
WriteCommandAction.runWriteCommandAction(getProject(),
new Runnable() {
@Override
public void run() {
document.insertString(0, " ");
}
});
FileDocumentManager.getInstance().saveAllDocuments();
checkResultByText(" xxx <caret>\nyyy\n\t\t\t\n");
@@ -218,8 +226,19 @@ public class TrailingSpacesStripperTest extends LightPlatformCodeInsightTestCase
@NotNull
private static Editor createHeavyEditor(@NotNull String name, @NotNull String text) throws IOException {
VirtualFile myVFile = getSourceRoot().createChildData(null, name);
VfsUtil.saveText(myVFile, text);
VirtualFile myVFile = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
@Override
public VirtualFile compute() {
try {
VirtualFile file = getSourceRoot().createChildData(null, name);
VfsUtil.saveText(file, text);
return file;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
final FileDocumentManager manager = FileDocumentManager.getInstance();
final Document document = manager.getDocument(myVFile);
manager.reloadFromDisk(document);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.openapi.editor.impl.softwrap.mapping;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
@@ -726,7 +727,13 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
addCollapsedFoldRegion(foldStartOffset, foldEndOffset, "...");
// Simulate addition of the new import that modifies existing fold region.
myEditor.getDocument().insertString(foldEndOffset, "\nimport java.util.Date;\n");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().insertString(foldEndOffset, "\nimport java.util.Date;\n");
}
});
final FoldingModel foldingModel = myEditor.getFoldingModel();
foldingModel.runBatchFoldingOperation(() -> {
FoldRegion oldFoldRegion = getFoldRegion(foldStartOffset);
@@ -757,7 +764,13 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
addCollapsedFoldRegion(foldStartOffset, foldEndOffset, "...");
int modificationOffset = text.indexOf("java.util.Set");
myEditor.getDocument().insertString(modificationOffset, "import java.util.HashSet;\n");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().insertString(modificationOffset, "import java.util.HashSet;\n");
}
});
// Used to get StackOverflowError here, hence, no additional checking is performed.
}
@@ -833,8 +846,14 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
final EditorSettings settings = getEditor().getSettings();
settings.setUseSoftWraps(false);
int startOffset = text.indexOf("\t third") - 1;
getEditor().getDocument().deleteString(startOffset, text.length());
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
getEditor().getDocument().deleteString(startOffset, text.length());
}
});
// Enable soft wraps and ensure that the cache is correctly re-built.
settings.setUseSoftWraps(true);
@@ -1044,7 +1063,13 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
addCollapsedFoldRegion(4, 8, "...");
addCollapsedFoldRegion(13, 15, "...");
myEditor.getDocument().insertString(10, "C");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
myEditor.getDocument().insertString(10, "C");
}
});
// verify that cached layout data is intact after document change and position recalculation is done correctly
assertEquals(new LogicalPosition(0, 0), myEditor.visualToLogicalPosition(new VisualPosition(0, 0)));
@@ -1120,7 +1145,13 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
configureSoftWraps(100);
addCollapsedFoldRegion(0, 4, "...");
((DocumentEx)myEditor.getDocument()).moveText(0, 4, 12);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
((DocumentEx)myEditor.getDocument()).moveText(0, 4, 12);
}
});
assertEquals(new LogicalPosition(2, 0), myEditor.visualToLogicalPosition(new VisualPosition(2, 1)));
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.editor.impl.view;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.DocumentEx;
@@ -91,7 +92,12 @@ public class LogicalPositionCacheStressTest extends AbstractEditorTest {
Document document = editor.getDocument();
int offset = random.nextInt(document.getTextLength() + 1);
CharSequence text = generateText(random);
document.insertString(offset, text);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
document.insertString(offset, text);
}
});
}
}
@@ -103,7 +109,12 @@ public class LogicalPositionCacheStressTest extends AbstractEditorTest {
if (textLength <= 0) return;
int from = random.nextInt(textLength + 1);
int to = random.nextInt(textLength + 1);
document.deleteString(Math.min(from, to), Math.max(from, to));
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
document.deleteString(Math.min(from, to), Math.max(from, to));
}
});
}
}
@@ -116,7 +127,12 @@ public class LogicalPositionCacheStressTest extends AbstractEditorTest {
int from = random.nextInt(textLength + 1);
int to = random.nextInt(textLength + 1);
CharSequence text = generateText(random);
document.replaceString(Math.min(from, to), Math.max(from, to), text);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
document.replaceString(Math.min(from, to), Math.max(from, to), text);
}
});
}
}
@@ -129,12 +145,17 @@ public class LogicalPositionCacheStressTest extends AbstractEditorTest {
int[] offsets = new int[] {random.nextInt(textLength + 1), random.nextInt(textLength + 1), random.nextInt(textLength + 1)};
Arrays.sort(offsets);
if (offsets[0] == offsets[1] || offsets[1] == offsets[2]) return;
if (random.nextBoolean()) {
((DocumentEx)document).moveText(offsets[0], offsets[1], offsets[2]);
}
else {
((DocumentEx)document).moveText(offsets[1], offsets[2], offsets[0]);
}
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
if (random.nextBoolean()) {
((DocumentEx)document).moveText(offsets[0], offsets[1], offsets[2]);
}
else {
((DocumentEx)document).moveText(offsets[1], offsets[2], offsets[0]);
}
}
});
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -79,9 +79,4 @@ public abstract class AbstractInplaceIntroduceTest extends LightPlatformCodeInsi
}
protected abstract AbstractInplaceIntroducer invokeRefactoring();
@Override
protected boolean isRunInWriteAction() {
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -103,7 +103,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
}
protected boolean isRunInWriteAction() {
return true;
return false;
}
/**